Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit test covering all v2.0.1 datatypes and enums #684

Closed
wants to merge 8 commits into from
21 changes: 21 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
### Changes included in this PR

*(Bug fix, feature, docs update, ...)*

### Current behavior

*Link to an open issue here...*

### New behavior

*If this is a feature change, describe the new behavior*

### Impact

*Describe breaking changes, including changes a users might need to make due to this PR*

### Checklist

1. [ ] Does your submission pass the existing tests?
2. [ ] Are there new tests that cover these additions/changes?
3. [ ] Have you linted your code locally before submission?
74 changes: 74 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level of experience,
education, socio-economic status, nationality, personal appearance, race,
religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at {{ email }}. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html

[homepage]: https://www.contributor-covenant.org

41 changes: 41 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
## Contributing

[fork]: /fork
[pr]: /compare
[style]: https://standardjs.com/
[code-of-conduct]: CODE_OF_CONDUCT.md

Hi there! We're thrilled that you'd like to contribute to this project. Your help is essential for keeping it great.

Please note that this project is released with a [Contributor Code of Conduct][code-of-conduct]. By participating in this project you agree to abide by its terms.

## Issues and PRs

If you have suggestions for how this project could be improved, or want to report a bug, open an issue! We'd love all and any contributions. If you have questions, too, we'd love to hear them.

We'd also love PRs. If you're thinking of a large PR, we advise opening up an issue first to talk about it, though! Look at the links below if you're not sure how to open a PR.

Work in Progress pull requests are also welcome to get feedback early on, or if there is something blocked you.

## Submitting a pull request

1. [Fork][fork] and clone the repository.
1. Create a new branch: `git checkout -b my-branch-name`.
1. Configure and install the dependencies: `poetry install`.
1. Make sure the tests pass on your machine: `make install & make tests`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A migration to task should be considered. make is not really a build tool the python community use.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would agree... sort of. make is so ubiquitous; I've seen many (legitimate) uses of make and python.

for the time being with this PR, was trying to document current process : )

if you think it's important, i could get behind it. could you create an issue ticket so that the community can have the discussion about it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apologies for the confusion, i removed these files as they are really part of #681

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jerome-benoit which task library were you referring to? there's pytask. but also snakemake, scons, invoke, bitbake all of which are python friendly, although probably way more functionality than is needed here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

taskpy. The Makefile is only used here to run ordered shell command(s), so is pointless. taskpy can do the same without requiring another external tool.

1. Make your change, add tests, and make sure the tests still pass.
1. Push to your fork and [submit a pull request][pr] and complete the information in the pull request template.

## Linting requirements
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A migration to ruff should be considered.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm not as familiar with ruff as black, isort and flake8. could you open an issue and give some justification? i'd be happy to switch over if there's enough support from the community.

apologies for the confusion, i removed these files as they are really part of #681. could you add addition comments there?


using `make install & make tests` will also run the following linters:

- [Black: The uncompromising Python code formatter](https://black.readthedocs.io/en/stable/)
- [isort your imports, so you don't have to](https://pycqa.github.io/isort/)
- [flake8: Your Tool For Style Guide Enforcement](https://flake8.pycqa.org/en/latest/)

## Resources

- [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/)
- [Using Pull Requests](https://help.github.com/articles/about-pull-requests/)
- [GitHub Help](https://help.github.com)
33 changes: 33 additions & 0 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Security Policy

This document outlines security procedures and general policies for this OCPP project.

## Supported Versions

The currently supported versions of this OCPP project are:

| Version | Supported |
|----------| ------------------ |
| 2.0.0 | :white_check_mark: |
| 0.26.0 | :white_check_mark: |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No version 1.x.x has been released?

Copy link
Contributor Author

@ajmirsky ajmirsky Nov 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not quite yet : (

there's a release candidate pending since february: https://github.com/mobilityhouse/ocpp/releases

probably should remove 2.0.0 from this list too, until we have a release candidate for that one too

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apologies for the confusion, i removed these files as they are really part of #681

| < 0.26.0 | :x: |

## Reporting a Vulnerability

Please include the requested information listed below (as much as you can provide) to help
us better understand the nature and scope of the possible issue:

- Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
- Full paths of source file(s) related to the manifestation of the issue
- The location of the affected source code (tag/branch/commit or direct URL)
- Any special configuration required to reproduce the issue
- Step-by-step instructions to reproduce the issue
- Proof-of-concept or exploit code (if possible)
- Impact of the issue, including how an attacker might exploit the issue

This information will help us triage your report more quickly.

## Comments on this Policy

If you have suggestions on how this process could be improved please submit a
pull request. Thanks!
34 changes: 34 additions & 0 deletions SUPPORT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Support

This article explains where to get help with this OCPP project.
Please read through the following guidelines.

> 👉 **Note**: before participating in our community, please read our
> [code of conduct][coc].
> By interacting with this repository, organization, or community you agree to
> abide by its terms.

## Asking quality questions

Questions can go to [GitHub discussions][chat].

Help us help you!
Spend time framing questions and add links and resources.
Spending the extra time up front can help save everyone time in the long run.
Here are some tips:

* Search to find out if a similar question has been asked or a similar issue has been reported
* Check to see if a PR is already in progress for the issue you want to raise
* Try to define what you need help with:
* Is there something in particular you want to do?
* What problem are you encountering and what steps have you taken to try
and fix it?
* Is there a concept you don’t understand?
* Provide sample code, such as a [CodeSandbox][cs] or video, if possible
* Screenshots can help, but if there’s important text such as code or error
messages in them, please also provide those as text
* The more time you put into asking your question, the better we can help you

## Contributions

See [`contributing.md`][contributing] on how to contribute.
2 changes: 1 addition & 1 deletion ocpp/v201/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ class IdTokenType:
"""

id_token: str
type: enums.IdTokenType
type: enums.IdTokenEnumType
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what's the value add of renaming enums

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compliance with the OCPP specs

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cross Checked this. This makes me question the whether the rest of the enums and datatypes are compliant or not. Will take a look at this soon.

Copy link
Contributor Author

@ajmirsky ajmirsky Dec 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a double check when I came across this one and all of the others seemed compliant. But another set of eyes is always appreciated!

additional_info: Optional[List[AdditionalInfoType]] = None


Expand Down
32 changes: 30 additions & 2 deletions ocpp/v201/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,26 @@ class StrEnum(str, Enum): # pragma: no cover
pass # pragma: no cover


class DeprecatedEnumWrapper:
"""
Since enums can't be subclassed in order to add a deprecation warning,
this class is included to help warn users of deprecated enums.
"""

def __init__(self, enum_class, alias_name):
self.enum_class = enum_class
self.alias_name = alias_name

def __getattr__(self, name):
warn(
(
f"Enum '{self.alias_name}' is deprecated, "
+ "instead use '{self.enum_class.__name__}'"
)
)
return getattr(self.enum_class, name)


class Action(StrEnum):
"""An Action is a required part of a Call message."""

Expand Down Expand Up @@ -721,7 +741,7 @@ class HashAlgorithmType(StrEnum):
sha512 = "SHA512"


class IdTokenType(StrEnum):
class IdTokenEnumType(StrEnum):
"""
Allowable values of the IdTokenType field.
"""
Expand All @@ -736,6 +756,9 @@ class IdTokenType(StrEnum):
no_authorization = "NoAuthorization"


IdTokenType = DeprecatedEnumWrapper(IdTokenEnumType, "IdTokenType")


class InstallCertificateStatusType(StrEnum):
"""
InstallCertificateStatusEnumType is used by
Expand Down Expand Up @@ -1321,7 +1344,7 @@ class VPNType(StrEnum):
# DataTypes


class UnitOfMeasureType(StrEnum):
class StandardizedUnitsOfMeasureType(StrEnum):
"""
Allowable values of the optional "unit" field of a Value element, as used
in MeterValues.req and StopTransaction.req messages. Default value of
Expand Down Expand Up @@ -1364,6 +1387,11 @@ class UnitOfMeasureType(StrEnum):
k = "K"


UnitOfMeasureType = DeprecatedEnumWrapper(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure it worth the effort. Have these enums been part of any stable release.
Considering rc versions as API stable is unusual.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm mixed on this one.

correct, there has been no official stable release.

But... since 0.26.0 has been in the wild for the past year, there are definitely people who are using/depending on the library

I leaned towards usability for the community in this case but I could be convinced otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jerome-benoit actually, given that these OCPP 2.0 files are included in this library's 1.0 release (on pypi), I think it's better to be safe. I don't think the project has made it clear if the library's release version is tied to the OCPP version or not?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The library version is totally independent from the OCPP version supported.

StandardizedUnitsOfMeasureType, "UnitOfMeasureType"
)


class StatusInfoReasonType(StrEnum):
"""
Standardized reason codes for StatusInfo defined in Appendix 5. v1.3
Expand Down
Loading