Skip to content

Commit b391b8e

Browse files
thatchamyreese
andauthored
Add --keep, dep on newer twine (#4)
* Add --keep, dep on newer twine * Add test for --keep * Fix types --------- Co-authored-by: Amethyst Reese <[email protected]>
1 parent 158c2e4 commit b391b8e

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

squatter/__main__.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ def cli() -> None: # pragma: no cover
1212

1313

1414
@cli.command(help="Generate a package")
15+
@click.option("--keep", is_flag=True, default=False, help="Do not delete temp dir")
1516
@click.option(
1617
"--upload", is_flag=True, default=False, help="Whether to invoke twine upload"
1718
)
@@ -21,11 +22,17 @@ def cli() -> None: # pragma: no cover
2122
)
2223
@click.argument("package_name")
2324
def generate(
24-
package_name: str, upload: bool, author: Optional[str], author_email: Optional[str]
25+
package_name: str,
26+
upload: bool,
27+
keep: bool,
28+
author: Optional[str],
29+
author_email: Optional[str],
2530
) -> None:
2631
# TODO flag for delete
27-
with tempfile.TemporaryDirectory(prefix=package_name) as d:
32+
with tempfile.TemporaryDirectory(prefix=package_name, delete=not keep) as d:
2833
env = Env(d)
34+
if keep:
35+
print("Generating in", d)
2936
env.generate(
3037
package_name=package_name, author=author, author_email=author_email
3138
)

squatter/tests/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import re
12
import tarfile
23
import unittest
34
from pathlib import Path
@@ -106,3 +107,14 @@ def patched_check_call(cmd: List[str], **kwargs: Any) -> Any:
106107
self.assertEqual("", result.output)
107108
self.assertFalse(result.exception)
108109
self.assertEqual(1, uploads)
110+
111+
@patch("squatter.templates.check_output")
112+
@patch("squatter.templates.check_call")
113+
def test_cli_keep_flag(self, check_call_mock: Any, check_output_mock: Any) -> None:
114+
runner = CliRunner()
115+
result = runner.invoke(generate, ["--keep", "foo"])
116+
m = re.match("Generating in (.+)", result.output)
117+
assert m is not None
118+
assert Path(m.group(1)).exists()
119+
assert Path(m.group(1), "pyproject.toml")
120+
self.assertFalse(result.exception)

0 commit comments

Comments
 (0)