Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error if output path doesn't exist #231

Open
vitoyucepi opened this issue Jan 30, 2023 · 1 comment
Open

Error if output path doesn't exist #231

vitoyucepi opened this issue Jan 30, 2023 · 1 comment

Comments

@vitoyucepi
Copy link

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

  1. python -m venv .venv
  2. . .venv/bin/activate
  3. pip install shiv==1.0.3
  4. echo "print('hello world')" >> __main__.py
  5. shiv -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

shiv/src/shiv/builder.py

Lines 93 to 94 in eeec71f

with target.open(mode="wb") as fd:

@lorencarvalho
Copy link
Contributor

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants