Skip to content

[WIP] Added more informative output - Addresses #42 #47

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 12 commits into
base: main
Choose a base branch
from
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@ target/
.python-version
.pytest_cache/
venv/
.venv
activate

# mypy
.mypy_cache
None/

# IDE
.vscode
pyrightconfig.json
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ tag = True

[flake8]
max-line-length = 160
max-complexity = 15
max-complexity = 18
exclude = docs test/package/setup.py

[tool:pytest]
Expand Down
43 changes: 41 additions & 2 deletions src/shiv/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import click

from . import pip
from .info import write_info
from . import builder
from . import bootstrap
from .bootstrap.environment import Environment
Expand Down Expand Up @@ -94,6 +95,13 @@ def _interpreter_path(append_version: bool = False) -> str:
return sys.executable


def write_completed(output_file: str, entry_point: str = None):
""" Echo a completed summary """

click.secho(f"Done, create pyz with settings : ", fg="green", bold=True, nl=False)
write_info(False, pyz=output_file)


@click.command(
context_settings=dict(
help_option_names=["-h", "--help", "--halp"], ignore_unknown_options=True
Expand All @@ -116,6 +124,11 @@ def _interpreter_path(append_version: bool = False) -> str:
default=True,
help="Whether or not to compress your zip.",
)
@click.option(
"--verbose/--quiet", "-v/-q",
default=False,
help="Whether or not to generate versose output.",
)
@click.option(
"--compile-pyc/--no-compile-pyc",
default=False,
Expand All @@ -132,6 +145,7 @@ def main(
console_script: Optional[str],
python: Optional[str],
site_packages: Optional[str],
verbose: bool,
compressed: bool,
compile_pyc: bool,
extend_pythonpath: bool,
Expand All @@ -141,7 +155,6 @@ def main(
Shiv is a command line utility for building fully self-contained Python zipapps
as outlined in PEP 441, but with all their dependencies included!
"""

if not pip_args and not site_packages:
sys.exit(NO_PIP_ARGS_OR_SITE_PACKAGES)

Expand All @@ -157,6 +170,19 @@ def main(
arg=supplied_arg, reason=DISALLOWED_ARGS[disallowed]
)
)
if verbose:
click.secho("Running Shiv with args : \n", fg="green", bold=True, nl=False)
click.secho("output_file: ", fg="blue", bold=True, nl=False)
click.secho(f"{output_file}", fg="white")
click.secho("entry_point: ", fg="blue", bold=True, nl=False)
click.secho(f"{entry_point or 'None'}", fg="white")
click.secho("python: ", fg="blue", bold=True, nl=False)
click.secho(f"{python or sys.executable}", fg="white")
click.secho("compressed: ", fg="blue", bold=True, nl=False)
click.secho(f"{compressed}", fg="white")
click.secho("pip args: ", fg="blue", bold=True, nl=False)
click.secho(f"{' '.join(pip_args)}")
click.echo()

with TemporaryDirectory() as working_path:
tmp_site_packages = Path(working_path, "site-packages")
Expand All @@ -165,13 +191,17 @@ def main(
shutil.copytree(site_packages, tmp_site_packages)

if pip_args:
if verbose:
click.secho(f"Pip installing dependencies to {site_packages}...", fg="green", bold=True, nl=False)
# install deps into staged site-packages
pip.install(["--target", str(tmp_site_packages)] + list(pip_args))

click.secho("")
# if entry_point is a console script, get the callable
if entry_point is None and console_script is not None:
try:
entry_point = find_entry_point(tmp_site_packages, console_script)
if verbose:
click.secho(f"Discovered entry point '{entry_point}'")

except KeyError:
if not Path(tmp_site_packages, "bin", console_script).exists():
Expand All @@ -194,9 +224,15 @@ def main(
bootstrap_target = Path(working_path, "_bootstrap")
bootstrap_target.mkdir(parents=True, exist_ok=True)

if verbose:
click.secho("Injecting bootstrap code")

# copy bootstrap code
copy_bootstrap(bootstrap_target)

if verbose:
click.secho("Creating zip archive")

# create the zip
builder.create_archive(
Path(working_path),
Expand All @@ -206,6 +242,9 @@ def main(
compressed=compressed,
)

if verbose:
write_completed(output_file, entry_point)


if __name__ == "__main__":
main() # pragma: no cover
16 changes: 11 additions & 5 deletions src/shiv/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
import zipfile


@click.command(context_settings=dict(help_option_names=["-h", "--help", "--halp"]))
@click.option("--json", "-j", "print_as_json", is_flag=True, help="output as plain json")
@click.argument("pyz")
def main(print_as_json, pyz):
"""A simple utility to print debugging information about PYZ files created with ``shiv``"""
def write_info(print_as_json: bool, pyz: str):
"""print debugging information about the PYZ file passed in """

zip_file = zipfile.ZipFile(pyz)
data = json.loads(zip_file.read("environment.json"))
Expand All @@ -26,3 +23,12 @@ def main(print_as_json, pyz):
click.secho(f"{value}", fg="white")

click.echo()


@click.command(context_settings=dict(help_option_names=["-h", "--help", "--halp"]))
@click.option("--json", "-j", "print_as_json", is_flag=True, help="output as plain json")
@click.argument("pyz")
def main(print_as_json, pyz):
"""A simple utility to print debugging information about PYZ files created with ``shiv``"""

write_info(print_as_json, pyz)
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ envlist = py36, py37
passenv = TRAVIS TRAVIS_*
commands=
py.test --cov=shiv
mypy src/
mypy --ignore-missing-imports src/
flake8 src/ test/
deps=
pytest
Expand Down