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
15 changes: 10 additions & 5 deletions src/shiv/bootstrap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,17 @@ def bootstrap(): # pragma: no cover

# get a handle of the currently executing zip file
with current_zipfile() as archive:
if archive:
# create an environment object (a combination of env vars and json metadata)
env = Environment.from_json(archive.read("environment.json").decode())

# create an environment object (a combination of env vars and json metadata)
env = Environment.from_json(archive.read("environment.json").decode())

# get a site-packages directory (from env var or via build id)
site_packages = cache_path(archive, env.root, env.build_id) / "site-packages"
# get a site-packages directory (from env var or via build id)
site_packages = cache_path(archive, env.root, env.build_id) / "site-packages"
else:
# not in zip file, now it is in a directory
parent_dir = Path(os.path.abspath(sys.argv[0])).parent
env = Environment.from_json(open(parent_dir / 'environment.json').read())
site_packages = Path(parent_dir / 'site-packages')

# determine if first run or forcing extract
if not site_packages.exists() or env.force_extract:
Expand Down
4 changes: 4 additions & 0 deletions src/shiv/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ def iter_package_files(package: Union[str, ModuleType]) -> Iterator[Tuple[Path,
# zipapp __main__.py template
MAIN_TEMPLATE = """\
# -*- coding: utf-8 -*-
# add current path to sys.path for module search
import sys
sys.path.insert(0, '.')

import {module}
{module}.{fn}()
"""
Expand Down