From 89b008cca8045558c3616e626e049049a5312080 Mon Sep 17 00:00:00 2001 From: foefl Date: Thu, 3 Apr 2025 14:41:27 +0200 Subject: [PATCH] add delete option for precompilation, closes #4 --- pyproject.toml | 6 +++--- src/pycage/compile.py | 31 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 227cfd8..090d845 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "pycage" -version = "0.2.2" +version = "0.2.3" description = "tool to handle standalone Python installations from the CLI" authors = [ {name = "Florian Förster", email = "f.foerster@d-opt.com"}, @@ -78,7 +78,7 @@ directory = "reports/coverage" [tool.bumpversion] -current_version = "0.1.1" +current_version = "0.2.3" parse = """(?x) (?P0|[1-9]\\d*)\\. (?P0|[1-9]\\d*)\\. @@ -111,7 +111,7 @@ pre_commit_hooks = [] post_commit_hooks = [] [tool.bumpversion.parts.pre_l] -values = ["dev", "a", "b", "rc", "final"] +values = ["dev", "rc", "final"] optional_value = "final" [[tool.bumpversion.files]] diff --git a/src/pycage/compile.py b/src/pycage/compile.py index 746126f..13904be 100644 --- a/src/pycage/compile.py +++ b/src/pycage/compile.py @@ -4,10 +4,27 @@ import subprocess import click +from pycage import clean from pycage.helpers import get_interpreter, print_error @click.command(help="precompile all Python files in the standalone distribution") +@click.option( + "-q", + "--quiet", + is_flag=True, + default=False, + show_default=True, + help=("do not list compiling files during procedure"), +) +@click.option( + "-d", + "--delete-existing", + is_flag=True, + default=False, + show_default=True, + help=("delete other pre-compiled files before compilation"), +) @click.option( "-f", "--force", @@ -33,6 +50,8 @@ from pycage.helpers import get_interpreter, print_error def compile( optimise: int, force: bool, + delete_existing: bool, + quiet: bool, ) -> None: try: pth_intp = get_interpreter() @@ -40,12 +59,23 @@ def compile( click.echo("Base interpreter path could not be found", err=True) return + if delete_existing: + try: + clean.delete_files(r"**/*.pyc") + except Exception as err: + print_error(err) + return + opt_level: str = "" if optimise == 1: opt_level = "-O" elif optimise == 2: opt_level = "-OO" + quiet_opt: str = "" + if quiet: + quiet_opt = "-q" + exclude_rx: str = "[\\\\|/]+tcl[\\\\|/]+" run_cmd: list[str] = [ str(pth_intp), @@ -57,6 +87,7 @@ def compile( exclude_rx, "-o", str(optimise), + quiet_opt, ] if force: run_cmd.extend(("-f",))