Skip to content

Commit

Permalink
fix(repository): update scripts.py to better handle error cases
Browse files Browse the repository at this point in the history
Signed-off-by: Jordan Shatford <[email protected]>
  • Loading branch information
jordanshatford committed Oct 23, 2023
1 parent f330b49 commit da9a3f5
Showing 1 changed file with 25 additions and 22 deletions.
47 changes: 25 additions & 22 deletions scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,26 +57,29 @@ def venv_run(
check=True,
)

# Install dependencies if they exist in a requirements.txt file
venv_run('pip', ['install', '--upgrade', 'pip'])
if os.path.exists('requirements.txt'):
venv_run('pip', ['install', '-r', 'requirements.txt'])
try:
# Install dependencies if they exist in a requirements.txt file
venv_run('pip', ['install', '--upgrade', 'pip'])
if os.path.exists('requirements.txt'):
venv_run('pip', ['install', '-r', 'requirements.txt'])

if args.command == 'pre-commit':
# Ensure pre-commit is installed
venv_run('pip', ['install', 'pre-commit'])
if args.script == 'autoupdate':
venv_run('pre-commit', ['autoupdate'])
elif args.script == 'run':
# Get a git tracked files in CWD to run pre-commit on.
r = subprocess.run(
['git', 'ls-files'],
capture_output=True,
text=True,
check=True,
cwd=cwd
)
files = r.stdout.splitlines()
venv_run('pre-commit', ['run', '--files'] + files)
elif args.command == 'run':
venv_run(rest[0], rest[1:])
if args.command == 'pre-commit':
# Ensure pre-commit is installed
venv_run('pip', ['install', 'pre-commit'])
if args.script == 'autoupdate':
venv_run('pre-commit', ['autoupdate'])
elif args.script == 'run':
# Get a git tracked files in CWD to run pre-commit on.
r = subprocess.run(
['git', 'ls-files'],
capture_output=True,
text=True,
check=True,
cwd=cwd
)
files = r.stdout.splitlines()
venv_run('pre-commit', ['run', '--files'] + files)
elif args.command == 'run':
venv_run(rest[0], rest[1:])
except subprocess.CalledProcessError as e:
raise SystemExit(e)

0 comments on commit da9a3f5

Please sign in to comment.