-
Notifications
You must be signed in to change notification settings - Fork 19
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
Code Style Guidelines #50
Comments
|
@bcoca conditional imports aren't affected by E402 Can we create our own rules (E402 is better than at the bottom of the file, but understand the preference to after docstrings) |
I like all the E300s, they make it a lot easier to visually see distinct methods (although 3 blank lines rather than 2 is not so major) W391 is just a bit careless. Also getting rid of them is probably the smallest effect on git blame you can have compared to most pep8 checks. |
Ignoring any of the PEP8 recommendations makes the code readability worse. Therefore full PEP8 compliance should be recommended for any new code (e.g. modules). |
Regarding the E402, "treat those similarly to module level docstrings" is irrelevant statement as the blocks are still variables from the Python perspective. If you want to treat them like docstrings, then turn them in real docstrings. Until then the statement "This allows us to keep all code and imports together instead of split from each other." is irrelevant as well because those are variables which makes them code as well. |
Needs documentation update. |
It's very annoying that flake8 and validate-modules are now incompatible. There should be a setup.cfg that sets up flake8/pep8 for the project appropriately |
@willthames on E402, when the import is conditional to the code flow
|
@bcoca E402 does not fire for that case:
Note that E402 fires for the non-conditional import but not the conditional import |
Documentation updates are in process. Also we are utilizing We aren't currently using flake8, but very well may in the future. As for flags for flake8 it should be `--ignore E402 --max-line-length 160" which are the same flags for pep8 |
Nice, @willthames! So we can make the wrong placement of imports pass the PEP8 test by putting it into
|
@sivel is there a distinction between legacy and non-legacy pep8 requirements? tox.ini currently has 10 ignores, and I can add E402 there, but just wondered if there was a core set |
@jtyr, that's horrible :) I think adding E402 to tox.ini will have to do. |
@willthames see: https://github.com/ansible/ansible/tree/devel/test/sanity/pep8 And I'm not at a computer right now, so just pointing in the right direction to help get you that info |
We don't use |
@mattclay, it's irrelevant whether people use tox or not - if you run flake8 in a project that has a tox.ini, it picks up flake8 rules from that tox.ini. |
@willthames Could you submit a PR with your recommended changes to |
tox.ini is used for flake8 configuration in addition to tox configuration. Update the flake8 configuration to match the latest standards as documented in ansible/proposals#50
tox.ini is used for flake8 configuration in addition to tox configuration. Update the flake8 configuration to match the latest standards as documented in ansible/proposals#50
To summerize
I think this can be marked as complete |
Not sure if it's applicable here, but there's a tool, which makes easier to consolidate linters: https://pre-commit.com |
We're still waiting for Powershell style validation to be included;-) |
Powershell linting has been started already https://github.com/ansible/ansible/tree/devel/test/sanity/pslint |
Proposal: Code Style Guidelines
Author: Matt Martz <@sivel>
Date: 2017/01/26
pep8
toansible-test
. ansible#20745This proposal was unanimously approved in the Jan 26, 2017 Testing meeting.
Motivation
Standardizing on coding guidelines are crucial to the longterm maintainability, and to our ability to act faster and more comfortably with pull requests from the community.
Problems
What problems exist that this proposal will solve?
Solution proposal
The errors returned from the pep8 utility were analyzed to come to a conclusion of what the current ansible code style is. This was done by counting the number of times each error was encountered, and removing those that occurred relatively few times, or were obvious anti patterns.
Existing Files
We have come to an agreement of 30 ignores for pep8, and a standard max line length of 160 characters for current files in the repository.
This will require a change to around 3390 lines over 571 files at the time of writing this. Changes will be targeted to begin once the 2.3 release is branched to stable-2.3 and devel becomes the base for the 2.4 release.
The following is the list of pep8 ignores:
Invocation will look like:
After the initial modification to adhere to the 30 ignore ruleset, the goal with pre existing files will be to convert them to adhere to the more strict standard that new files will follow, as outlined below. The approach will be to start with the easiest modifications, by inverting
--ignore
to--select
, totaling the number of times we see an error, and resolving those that occur the fewest times.New Files
All new python files within the repository will adhere to a much more strict pep8 standard, identified by:
We have decided to continue to ignore
E402 module level import not at top of file
due to our preference to place imports in modules below theDOCUMENTATION
/RETURN
/EXAMPLES
/METADATA
variables, as we treat those similarly to module level docstrings. This allows us to keep all code and imports together instead of split from each other.Changes to validate-modules
To follow suit with the ignore of
E402
, we will updatevalidate-modules
to validate that imports are placed below documentation in a module.Dependencies (optional)
Explain any dependencies. This section is optional but could be helpful.
Testing (optional)
This extends testing capabilities
Documentation (optional)
Documentation for developing modules is required
Anything else?
To expand on the description of goals and the spirit of what we are doing here:
From PEP8:
Of important note, is that style guidelines as defined by PEP8 are for readability and don't necessarily imply "bad programming practice".
Sometimes external style guide recommendations just aren't applicable. Based on careful and in depth discussion, we have decided to work to a point where we are explicitly ignoring 2 recommendations made by PEP8.
These exclusions are to
E402 module level import not at top of file
and an increase in max line length to 160 columns.The decision to exclude E402 is based on readability. As described above, documentation strings in a module are much more similar to module level docstrings, than code, and are never utilized by the module itself. Placing the imports below this documentation and closer to the code, consolidates and groups all related code in a congruent manner to improve readability, debugging and understanding. Discussions about removing or changing how we document modules is off topic for this discussion, although can potentially impact these decisions at a later date.
The 160 column limit is largely based on larger monitors and more current development environments. This concession was decided upon quite some time ago, and was not debated for change in this proposal.
The text was updated successfully, but these errors were encountered: