MolSSI/cookiecutter-cms

[Question] How to use Yapf and other tools?

btjanaka opened this issue · 4 comments

Some context: This is my first time using this template, and only my third-ish attempt to create a Python package.

My question is, what is the proper way to use tools like yapf and flake8 with a project made from this template? In setup.cfg, I see several settings for yapf and flake8, but I am not sure how the settings are used.

In a similar vein, would one add yapf and flake8 to the dependencies in setup.py, or would one add them to a development Conda environment, for instance devtools/conad-envs/dev.yml?

Thanks!

@btjanaka - you may find it helpful to review our Python Package Development workshop material, available at https://molssi-education.github.io/python-package-best-practices/

This material will walk through creating a package with the cookiecutter.

YAPF is discussed in the lesson on Python coding style (https://molssi-education.github.io/python-package-best-practices/05-function-style/index.html). If you wish to use yapf, you can install it into your environment using conda or pip. You run yapf on the command line (see lesson for example). When you run it, yapf will check the directory you are working in for local style settings. This is what is set in setup.cfg. YAPF will look at the format of the python file that you specify, and the information in setup.cfg, and format that file according to your settings.

You can see more on yapf usage on the yapf GitHub: https://github.com/google/yapf

In my opinion, you do not need to add it as a dependency as your package does not need it to run.

Comments by others also appreciated!

@janash Thanks! I do use yapf already (actually, I have a Vim plugin that runs it automatically), but I was not aware that yapf checks for a setup.cfg. This is good to know. Thank you for providing the links; I'll make sure to take a look.

yep! See this section of YAPF documentation (https://github.com/google/yapf#id7). There are four places YAPF looks for style settings. If none of these are set, it will default to pep8. The settings in the cookiecutter differ from pep8 mainly in that we set a 119 character column width and pep8 specifies a 79 character column width.