-
Notifications
You must be signed in to change notification settings - Fork 105
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
Test python module import order using flake8 #63
Conversation
ament_cmake_flake8/CMakeLists.txt
Outdated
@@ -0,0 +1,23 @@ | |||
cmake_minimum_required(VERSION 2.8.3) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We require version 3.5.
@@ -0,0 +1,22 @@ | |||
# Copyright 2014-2015 Open Source Robotics Foundation, Inc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The copyright year should be 2016.
Same below
ament_cmake_flake8/package.xml
Outdated
The CMake API for ament_flake8 to check code syntax and style conventions | ||
with flake8. | ||
</description> | ||
<maintainer email="dthomas@osrfoundation.org">Dirk Thomas</maintainer> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be your name.
Same below.
comments addressed in ee080bc. replace pep8, pyflakes, and pep257 packages? |
ament_lint_common/package.xml
Outdated
@@ -16,6 +16,7 @@ | |||
<exec_depend>ament_cmake_cppcheck</exec_depend> | |||
<exec_depend>ament_cmake_cpplint</exec_depend> | |||
<exec_depend>ament_cmake_lint_cmake</exec_depend> | |||
<exec_depend>ament_cmake_flake8</exec_depend> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move this line one up to be in alphabetical order.
Has anyone successfully setup this linter in the editor? I have |
I only use flake8 in Sublime. |
Sorry, hit send on accident. I use this plugin: https://github.com/SublimeLinter/SublimeLinter-flake8 I think there is an atom one too: https://atom.io/packages/linter-flake8 I haven't tried vim or emacs. |
I had to configure the Atom package |
ament_flake8/ament_flake8/main.py
Outdated
return super(CustomStyleGuide, self).input_file(filename, **kwargs) | ||
|
||
|
||
class CustomReport(pep8.StandardReport): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to implement this without using pep8
directly (which the package doesn't declare a dependency on)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dhood#1 gets rid of the pep8
usage.
following from ros2/ci#3 (comment): this uses flake8 v2.x. If not using flake8 3.x instead of 2.x is a blocker, I'll put this on the backburner since it'll likely take me a bit of effort to get it to work with 3.x (and this isn't particularly high priority) FYI I saw your issue/PR on flake8-import-order re the import order capitalisation sensitivity of the google style guide: I had already opened PyCQA/flake8-import-order#94 to address it (it was referenced in this PR but I could have been clearer) |
…led by flake8 anymore
The current implementation of get_style_guide does not process the config file correctly.
What is the fallback behavior if only version 2 of |
Several of these plugins look interesting. I would suggest to get the current minimum set merged before considering to add more though. |
with only flake8 v2.x the test will be added, but will fail (implemented in 81e6f10) I felt it would be misleading if the test still passes. Would it make sense to add a version check in the hook to stop it from getting added in that case? https://github.com/ament/ament_lint/pull/63/files#diff-da8d8d587f53d8cedf3b2cd20757fc40R16 Alternatively, I did have it working with v2.x originally, so we can choose to support both |
there's also the option of adding a |
Once |
ok bf07f5b adds support for both. The tests will fail with v3, however, because the |
otherwise it's not present in xunit files for tests run directly with nose (not ament_cmake_flake8)
tests can run if ament/ament_tools#130 is used Regarding building debs, here's a job with flake8 installed from apt (i.e. v2) and no import order (using https://github.com/ros2/ci/compare/flake8-apt), which I understood is what we would have for debian packages:
so I think it should be good for debian packaging. |
I'll just merge the |
Merging those two files will make it more effort to remove the legacy code in the future. Is there really no way to preserve the separation? |
OK I've fixed it. rather than trying to prevent the file from being imported, I just prefixed the whole file with these are the normal jobs (using ros2/ci#3, which gets flake8 v3, from pip): this is linux using flake8 from apt (v2) and import-order from pip (same result as above): and this is what it would be like if we are using flake8 v2 and no import-order plugin (as would be the case for debians) - no issues if the plugin is not found: I have matching PRs for the linter fixes that I'll open once this gets approved. |
Any reason to delay the PRs with the linter fixes until this one gets approved? |
I figured that depending on the outcome of this PR, the changes required to make linters pass for other packages might change |
This looks goo to me. With another round of CI which uses your linter fixes this should be good to go. |
CI jobs with fixes in PRs attached to #53 OS X: |
Can be done in a follow up but it would be great to run flake8 on Otherwise all attached fixes look good to me 👍 |
ament_lint_cmake/package.xml
Outdated
@@ -11,6 +11,7 @@ | |||
<license>Apache License 2.0</license> | |||
|
|||
<test_depend>ament_copyright</test_depend> | |||
<test_depend>ament_flake8</test_depend> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any cases which are covered by pep8 / pep257 / pyflakes which are not covered by flake8? If not I would suggest to remove the redundant tests (ament_pep8, ament_pep257, ament_pyflakes).
@@ -16,6 +16,7 @@ | |||
<exec_depend>ament_cmake_copyright</exec_depend> | |||
<exec_depend>ament_cmake_cppcheck</exec_depend> | |||
<exec_depend>ament_cmake_cpplint</exec_depend> | |||
<exec_depend>ament_cmake_flake8</exec_depend> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there any cases which are covered by pep8 / pep257 / pyflakes which are not covered by flake8? If not I would suggest to remove the redundant tests (ament_pep8, ament_pep257, ament_pyflakes).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should cover pep8
and pyflakes
, yes. I'll remove ament_pep8
and ament_pyflakes
from ament_lint_common
so that they are not added when ament_lint_auto
is used.
I haven't added the docstrings flake8 plugin. Since you mentioned the plugins won't be installable when we build debians, perhaps that's a reason to leave ament_pep257
as is - what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me.
print('%d errors' % (report.total_errors)) | ||
|
||
print('') | ||
error_type_counts = report.get_error_type_counts() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line fails when the legacy API is being used since this class doesn't have that method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for the heads up. I'll fix it
|
||
flake8_argv = [] | ||
flake8_argv.append('--config={0}'.format(config_file)) | ||
flake8_argv.append('--exclude={0}'.format(excludes)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line doesn't work. See #77
* Add flake8 linter * Don't deal with flake8-import-order just yet * Debugging prints * Reinstate import order rule * Fix reporting bug by using the inner flake8 style guide * Fixup * Add comment on wrapper StyleGuide use * use flake8 v3 (#1) * Reorder package.xml * Get the filenames from the file checkers because input_file isn't called by flake8 anymore * Output count of all error types * Get flake8 to use the config file The current implementation of get_style_guide does not process the config file correctly. * Error when flake8 v2 found * Print errors like pep8 * remove __future__ imports * add schema to manifest files * Support flake8 v2 as well as v3 * Output checked files otherwise it's not present in xunit files for tests run directly with nose (not ament_cmake_flake8) * Prevent v2 imports from happening on systems with v3 * Flake8 replaces pep8+pyflakes
connects to #53
requires ros2/ci#3
This currently adds flake8 as a linter which has pep8 and pyflakes checks included by default. I have added the flake8-import-order plugin for flake8 in ros2/ci#3.
This can replace the
ament_pep8
andament_pyflakes
linter packages if appropriate, and with the pep257 plugin it can replace theament_pep257
package as well. Should I go ahead and do that?These are the files that are failing the new linter test: http://ci.ros2.org/job/ci_linux/1783/testReport/ using the Google style guide (some will be fixed by PyCQA/flake8-import-order#94)