Skip to content

Commit

Permalink
Update dev_tools autoformat to allow specifying specific files/dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
gazpachoking committed Jun 4, 2019
1 parent 304d76a commit 043f852
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions dev_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,19 @@ def download_extract(url, dest_path):


@cli.command()
def autoformat():
@click.argument('files', nargs=-1)
def autoformat(files):
"""Reformat code with black and isort"""
project_root = os.path.dirname(os.path.realpath(__file__))
if not files:
project_root = os.path.dirname(os.path.realpath(__file__))
files = (project_root,)
venv_path = os.environ['VIRTUAL_ENV']
if not venv_path:
raise Exception('Virtualenv and activation required')

subprocess.call(['black', '-S', '-l', '99', project_root])
# isort configuration is .isort.cfg, (setup.cfg did not work for some reason)
subprocess.call(['isort', '--virtual-env', venv_path, '-rc', project_root])
# black and isort config are in pyproject.toml
subprocess.call(('black',) + files)
subprocess.call(('isort', '--virtual-env', venv_path, '-rc') + files)


if __name__ == '__main__':
Expand Down

0 comments on commit 043f852

Please sign in to comment.