django-sortedm2m
django-sortedm2m copied to clipboard
PEP8 Errors in the package
While trying to solve some issues and after taking reviews from people, I've observed that the code isn't compliant with the PEP8 guidelines. We can use tools like autopep8 to fix these at once.
I think we can follow the convention that is followed in the core of django: use flake8 and isort end enforce these style conventions in the build, see the django tox.ini configuration (look for isort and flake8).
What do you think about using YAPF (https://github.com/google/yapf) which autoformats all code to a deterministic format (much like prettier does for JavaScript)?
We could enforce that the format is the same as YAPF would give us. The output is pep8 compatible and there will never be any discussions of one persons preferred style.
I didn't know yapf. I think is a good idea to use it in combination with isort.
Django uses flake8 + isort, but you are right in the sense that sometimes different styles will pass the flake8 validation, so having a neutral judge may be better.
Started to work on this in #113 If someone feels like helping out on fixing the flake8 errors, feel free to contribute! You can create a PR based on the flake8-check branch.
I didn't went for yapf as the output it produces looks really strange in many cases, especially since it doesn't put a tuple/list items one by one per line. This really messes up the settings.INSTALLED_APPS for example.
@gregmuellegger great! that may happen even with flake8 and isort, I usually configure some files like settings.py and migrations to be ignored because there's really no great value to spend time on those (especially because migrations are usually autogenerated and not touched very much by humans plus may be added often over time on some projects), here's an example of one of the latest flake8 and isort configuration I recently improved: https://github.com/openwisp/netjsonconfig/blob/master/setup.cfg#L4-L15
Here's an example of travis.yml configuration: https://github.com/openwisp/netjsonconfig/blob/master/.travis.yml#L14-L18
After almost a couple of years I started to run these checks in the before_script
section of travis-ci, so the main dependencies (eg: django, etc) are installed only if the static checks pass, this allows to spot style issues faster because those checks are run almost straightaway.