linkedin / linkedin/shiv

Error if output path doesn't exist

Open
#231 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
1.9k
Forks
114
PR merge metrics
No merged PRs in 30d

Description

## 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
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`
1. `. .venv/bin/activate`
1. `pip install shiv==1.0.3`
1. `echo "print('hello world')" >> __main__.py`
1. `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
```py
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

Contributor guide

Open the contributing guide

Research direction

Start in src/shiv/builder.py around the target.open call cited in the issue, then reproduce the command using an output path such as dist/main. The change is done when shiv creates any missing leading directories and successfully writes the archive to the requested path.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.