Skip to content

Deterministic zipfile #273

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
8 changes: 4 additions & 4 deletions src/shiv/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@
# N.B.: `importlib.resources.{contents,is_resource,path}` are deprecated in 3.11 and gone in 3.13.
if sys.version_info < (3, 11):
def iter_package_files(package: Union[str, ModuleType]) -> Iterator[Tuple[Path, str]]:
for bootstrap_file in importlib_resources.contents(bootstrap):
if importlib_resources.is_resource(bootstrap, bootstrap_file):
with importlib_resources.path(bootstrap, bootstrap_file) as path:
for bootstrap_file in sorted(importlib_resources.contents(package)):
if importlib_resources.is_resource(package, bootstrap_file):
with importlib_resources.path(package, bootstrap_file) as path:
yield (path, bootstrap_file)
else:
def iter_package_files(package: Union[str, ModuleType]) -> Iterator[Tuple[Path, str]]:
for resource in importlib_resources.files(package).iterdir():
for resource in sorted(importlib_resources.files(package).iterdir(), key=lambda r: r.name):
if resource.is_file():
with importlib_resources.as_file(resource) as path:
yield (path, resource.name)
Expand Down
5 changes: 3 additions & 2 deletions src/shiv/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,14 +219,15 @@ def main(
shutil.copy(Path(preamble).absolute(), bin_dir / Path(preamble).name)

sources.append(Path(tmp_site_packages).absolute())
sources.sort()
hashes = {}

if no_modify:
# if no_modify is specified, we need to build a map of source files and their
# sha256 hashes, to be checked at runtime:
hashes = {}

for source in sources:
for path in source.rglob("**/*.py"):
for path in sorted(source.rglob("**/*.py")):
hashes[str(path.relative_to(source))] = hashlib.sha256(path.read_bytes()).hexdigest()

# if entry_point is a console script, get the callable and null out the console_script variable
Expand Down