shiv
shiv copied to clipboard
Error if output path doesn't exist
Summary
If the output path doesn't exist, then shiv will fail with an error FileNotFoundError: [Errno 2] No such file or directory.
Log
Traceback (most recent call last):
File "/tmp/test/.venv/bin/shiv", line 8, in <module>
sys.exit(main())
File "/tmp/test/.venv/lib/python3.10/site-packages/click/core.py", line 1130, in __call__
return self.main(*args, **kwargs)
File "/tmp/test/.venv/lib/python3.10/site-packages/click/core.py", line 1055, in main
rv = self.invoke(ctx)
File "/tmp/test/.venv/lib/python3.10/site-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/tmp/test/.venv/lib/python3.10/site-packages/click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "/tmp/test/.venv/lib/python3.10/site-packages/shiv/cli.py", line 269, in main
builder.create_archive(
File "/tmp/test/.venv/lib/python3.10/site-packages/shiv/builder.py", line 94, in create_archive
with target.open(mode="wb") as fd:
File "/usr/lib/python3.10/pathlib.py", line 1119, in open
return self._accessor.open(self, mode, buffering, encoding, errors,
FileNotFoundError: [Errno 2] No such file or directory: 'dist/main'
To reproduce
python -m venv .venv. .venv/bin/activatepip install shiv==1.0.3echo "print('hello world')" >> __main__.pyshiv -e __main__.py -o dist/main --site-packages .venv/lib/python3.10/site-packages/
Expected behavior
Shiv should create leading directories if they do not exist.
Versions
- python: 3.10
- shiv: 1.0.3
Additional
Maybe something like
target_dir = os.path.dirname(target)
if not os.path.exists(target_dir):
os.makedirs(target_dir)
should be inserted somewhere here https://github.com/linkedin/shiv/blob/eeec71f31a08203cffd184602eb6d10e30634126/src/shiv/builder.py#L93-L94
Hi @vitoyucepi
Thanks for the report, I agree that shiv could & should create the path if it doesn't exist. I'm happy to make this change, but I would also accept a PR with the same, assuming it comes with a test :)