From a07741493f631778f9e5ce1fe8c964091f9b5326 Mon Sep 17 00:00:00 2001 From: Tim Hatch Date: Thu, 15 May 2025 10:10:14 -0700 Subject: [PATCH 1/3] Add --keep, dep on newer twine --- squatter/__main__.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/squatter/__main__.py b/squatter/__main__.py index 429dd08..25cd9ad 100644 --- a/squatter/__main__.py +++ b/squatter/__main__.py @@ -12,6 +12,9 @@ def cli() -> None: # pragma: no cover @cli.command(help="Generate a package") +@click.option( + "--keep", is_flag=True, default=False, help="Do not delete temp dir" +) @click.option( "--upload", is_flag=True, default=False, help="Whether to invoke twine upload" ) @@ -21,11 +24,13 @@ def cli() -> None: # pragma: no cover ) @click.argument("package_name") def generate( - package_name: str, upload: bool, author: Optional[str], author_email: Optional[str] + package_name: str, upload: bool, keep: bool, author: Optional[str], author_email: Optional[str] ) -> None: # TODO flag for delete - with tempfile.TemporaryDirectory(prefix=package_name) as d: + with tempfile.TemporaryDirectory(prefix=package_name, delete=not keep) as d: env = Env(d) + if keep: + print("Generating in", d) env.generate( package_name=package_name, author=author, author_email=author_email ) From e931957ee57841906c419436647fd8914a672b0c Mon Sep 17 00:00:00 2001 From: Tim Hatch Date: Fri, 16 May 2025 02:18:02 -0700 Subject: [PATCH 2/3] Add test for --keep --- squatter/__main__.py | 10 ++++++---- squatter/tests/__init__.py | 11 +++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/squatter/__main__.py b/squatter/__main__.py index 25cd9ad..701d38f 100644 --- a/squatter/__main__.py +++ b/squatter/__main__.py @@ -12,9 +12,7 @@ def cli() -> None: # pragma: no cover @cli.command(help="Generate a package") -@click.option( - "--keep", is_flag=True, default=False, help="Do not delete temp dir" -) +@click.option("--keep", is_flag=True, default=False, help="Do not delete temp dir") @click.option( "--upload", is_flag=True, default=False, help="Whether to invoke twine upload" ) @@ -24,7 +22,11 @@ def cli() -> None: # pragma: no cover ) @click.argument("package_name") def generate( - package_name: str, upload: bool, keep: bool, author: Optional[str], author_email: Optional[str] + package_name: str, + upload: bool, + keep: bool, + author: Optional[str], + author_email: Optional[str], ) -> None: # TODO flag for delete with tempfile.TemporaryDirectory(prefix=package_name, delete=not keep) as d: diff --git a/squatter/tests/__init__.py b/squatter/tests/__init__.py index 1f1d78f..d815cc5 100644 --- a/squatter/tests/__init__.py +++ b/squatter/tests/__init__.py @@ -1,3 +1,4 @@ +import re import tarfile import unittest from pathlib import Path @@ -106,3 +107,13 @@ def patched_check_call(cmd: List[str], **kwargs: Any) -> Any: self.assertEqual("", result.output) self.assertFalse(result.exception) self.assertEqual(1, uploads) + + @patch("squatter.templates.check_output") + @patch("squatter.templates.check_call") + def test_cli_keep_flag(self, check_call_mock: Any, check_output_mock: Any) -> None: + runner = CliRunner() + result = runner.invoke(generate, ["--keep", "foo"]) + m = re.match("Generating in (.+)", result.output) + assert Path(m.group(1)).exists() + assert Path(m.group(1), "pyproject.toml") + self.assertFalse(result.exception) From d60d281fd527526c1632d67f445340eff133f2c1 Mon Sep 17 00:00:00 2001 From: Amethyst Reese Date: Mon, 19 May 2025 10:47:37 -0400 Subject: [PATCH 3/3] Fix types --- squatter/tests/__init__.py | 1 + 1 file changed, 1 insertion(+) diff --git a/squatter/tests/__init__.py b/squatter/tests/__init__.py index d815cc5..911d7c6 100644 --- a/squatter/tests/__init__.py +++ b/squatter/tests/__init__.py @@ -114,6 +114,7 @@ def test_cli_keep_flag(self, check_call_mock: Any, check_output_mock: Any) -> No runner = CliRunner() result = runner.invoke(generate, ["--keep", "foo"]) m = re.match("Generating in (.+)", result.output) + assert m is not None assert Path(m.group(1)).exists() assert Path(m.group(1), "pyproject.toml") self.assertFalse(result.exception)