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:
parent
6754f04fcd
commit
bb6de05709
4 changed files with 240 additions and 2 deletions
21
noxfile.py
21
noxfile.py
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue