Skip to content

Commit

Permalink
fix(cli): ensure entrypoint only exists if npm install passes (#708)
Browse files Browse the repository at this point in the history
## Change Summary

closes #705

I haven't tested these changes yet and have not confirmed that this does achieve the desired behaviour.

## Checklist

- [ ] Unit tests for the changes exist
- [ ] Tests pass without significant drop in coverage
- [ ] Documentation reflects changes where applicable
- [ ] Test snapshots have been
[updated](https://prisma-client-py.readthedocs.io/en/latest/contributing/contributing/#snapshot-tests)
if applicable

## Agreement

By submitting this pull request, I confirm that you can use, modify,
copy and redistribute this contribution, under the terms of your choice.
  • Loading branch information
RobertCraigie authored Mar 2, 2023
1 parent 0ecec2e commit c88cb8e
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions src/prisma/cli/prisma.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,30 @@ def ensure_cached() -> CLICache:

if not entrypoint.exists():
click.echo('Installing Prisma CLI')
proc = npm.run(
'install',
f'prisma@{config.prisma_version}',
cwd=config.binary_cache_dir,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)
if proc.returncode != 0:
click.echo(
f'An error ocurred while installing the Prisma CLI; npm install log: {proc.stdout.decode("utf-8")}'

try:
proc = npm.run(
'install',
f'prisma@{config.prisma_version}',
cwd=config.binary_cache_dir,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)
proc.check_returncode()
if proc.returncode != 0:
click.echo(
f'An error ocurred while installing the Prisma CLI; npm install log: {proc.stdout.decode("utf-8")}'
)
proc.check_returncode()
except Exception:
# as we use the entrypoint existing to check whether or not we should run `npm install`
# we need to make sure it doesn't exist if running `npm install` fails as it will otherwise
# lead to a broken state, https://github.com/RobertCraigie/prisma-client-py/issues/705
if entrypoint.exists():
try:
entrypoint.unlink()
except Exception:
pass
raise

if not entrypoint.exists():
raise PrismaError(
Expand Down

0 comments on commit c88cb8e

Please sign in to comment.