Add a code formatting tool chain

- (auto-)format code with:
  + autoflake => * remove unused imports and variables
                 * remove duplicate dict keys
                 * expand star imports
  + black => enforce an uncompromising code style
  + isort => enforce a consistent import style
             (complying with Google's Python Style Guide)
- implement the nox session "format" that runs all these tools
- add the following file:
  + setup.cfg => holds configurations for the develop tools
This commit is contained in:
Alexander Hess 2020-08-03 21:39:49 +02:00
commit bb6de05709
Signed by: alexander
GPG key ID: 344EA5AB10D868E0
4 changed files with 240 additions and 2 deletions

View file

@ -35,8 +35,27 @@ nox.options.sessions = (
@nox.session(name='format', python=MAIN_PYTHON)
def format_(session: Session):
"""Format source files."""
"""Format source files with autoflake, black, and isort."""
_begin(session)
_install_packages(session, 'autoflake', 'black', 'isort')
# Interpret extra arguments as locations of source files.
locations = session.posargs or SRC_LOCATIONS
session.run('autoflake', '--version')
session.run(
'autoflake',
'--in-place',
'--recursive',
'--expand-star-imports',
'--remove-all-unused-imports',
'--ignore-init-module-imports', # modifies --remove-all-unused-imports
'--remove-duplicate-keys',
'--remove-unused-variables',
*locations,
)
session.run('black', '--version')
session.run('black', *locations)
session.run('isort', '--version')
session.run('isort', *locations)
@nox.session(python=MAIN_PYTHON)