robotics-in-concert / rocon

http://www.robotconcert.org
11 stars 15 forks source link

Pep8 Conformance #12

Open stonier opened 10 years ago

stonier commented 10 years ago

@jihoonl, @bit-pirate, @dwlee, @hughie, @piyushk

This is carried over from Piyush's work initiated in the multimaster repo (https://github.com/robotics-in-concert/rocon_multimaster/issues/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:

<build_depend>roslint</build_depend>
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})
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

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).

stonier commented 10 years ago

Eclipse - PyDev

So we can't get pydev running the same pep8 as roslint. However I haven't noticed any big difference except the default line length (pydev: 80, roslint: 120). I generally try and conform to that too these days, but you can always set --ignore=E501 in the eclipse settings and let roslint handle it on the command line.