Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/shiv/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ def create_archive(
timestamp = datetime.strptime(env.built_at, BUILD_AT_TIMESTAMP_FORMAT).replace(tzinfo=timezone.utc).timestamp()
zipinfo_datetime: Tuple[int, int, int, int, int, int] = time.gmtime(int(timestamp))[0:6]

# Create leading directories when -o points into a missing path (#231).
target.parent.mkdir(parents=True, exist_ok=True)

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

# Write shebang.
Expand Down
9 changes: 9 additions & 0 deletions test/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ def test_create_archive(self, sp, env):
with pytest.raises(ZipAppError):
create_archive(sp, target, sys.executable, "alsjdbas,,,", env)


def test_create_archive_creates_missing_parent_dirs(self, sp, env):
"""-o into a missing directory must create parents (#231)."""
with tempfile.TemporaryDirectory() as tmpdir:
target = Path(tmpdir, "nested", "out", "test.zip")
assert not target.parent.exists()
create_archive(sp, target, sys.executable, "code:interact", env)
assert zipfile.is_zipfile(str(target))

@pytest.mark.skipif(os.name == "nt", reason="windows has no concept of execute permissions")
def test_archive_permissions(self, sp, env):
with tempfile.TemporaryDirectory() as tmpdir:
Expand Down