@jihoonl, @bit-pirate, @dwlee, @hughie, @piyushk
This is carried over from Piyush's work initiated in the multimaster repo (robotics-in-concert/rocon_multimaster#259). It's useful here as a reminder when creating new or updating old rocon python packages.
Roslint
All python packages in the rocon repositories should conform to pep8. To enable automated testing:
- Add a build dependency on roslint:
<build_depend>roslint</build_depend>
- Enable roslint macros and call them:
find_package(catkin REQUIRED COMPONENTS roslint)
...
# Lint Python modules for PEP8 compatibility
file(GLOB_RECURSE ${PROJECT_NAME}_PY_SCRIPTS
RELATIVE ${PROJECT_SOURCE_DIR} scripts/*)
file(GLOB_RECURSE ${PROJECT_NAME}_PY_SRC
RELATIVE ${PROJECT_SOURCE_DIR} src/${PROJECT_NAME}/*.py)
roslint_python(${${PROJECT_NAME}_PY_SCRIPTS})
roslint_python(${${PROJECT_NAME}_PY_SRC})
- Test pep8 conformance using:
catkin_make roslint_<package_name>
To automatically cut down a lot of errors:
sudo pip install autopep8
autopep8 --max-line-length 120 --in-place scripts/*
autopep8 --max-line-length 120 --in-place src/<package-name>/*.py
You can also try the --aggresive for more aggresive correction. See autopep8 --help.
Roslint Tips
- Ignoring a line of code for analysis - add a
# noqa comment at the end of the line.
This should in general be avoided and appears to be a contentious issue in the python world. The main argument against it is that it creates noise in the source file. I'm agnostic about it and care more just to get on with our work so do as you wish. One use case for it is in formatting a set of lines with extra whitespace for ease of reading (and hence arguably creating less noise in the source file despite the comment).
@jihoonl, @bit-pirate, @dwlee, @hughie, @piyushk
This is carried over from Piyush's work initiated in the multimaster repo (robotics-in-concert/rocon_multimaster#259). It's useful here as a reminder when creating new or updating old rocon python packages.
Roslint
All python packages in the rocon repositories should conform to pep8. To enable automated testing:
To automatically cut down a lot of errors:
You can also try the --aggresive for more aggresive correction. See
autopep8 --help.Roslint Tips
# noqacomment at the end of the line.This should in general be avoided and appears to be a contentious issue in the python world. The main argument against it is that it creates noise in the source file. I'm agnostic about it and care more just to get on with our work so do as you wish. One use case for it is in formatting a set of lines with extra whitespace for ease of reading (and hence arguably creating less noise in the source file despite the comment).