Skip to content

Commit 69ff557

Browse files
committed
Initial implementation
1 parent eba8336 commit 69ff557

File tree

5 files changed

+91
-0
lines changed

5 files changed

+91
-0
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
For those times you need to register a name prior to having the code ready, but
44
can't be bothered to remember which fields are required.
55

6+
Usage:
7+
8+
```
9+
python -m squatter generate --upload mypackage
10+
```
11+
12+
(Uses author information from git config)
13+
614

715
# License
816

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
from setuptools import setup
2+
23
setup(use_scm_version=True)

squatter/__init__.py

Whitespace-only changes.

squatter/__main__.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import tempfile
2+
from typing import Optional
3+
4+
import click
5+
6+
from .templates import Env
7+
8+
9+
@click.group()
10+
def cli():
11+
pass
12+
13+
14+
@cli.command(help="Generate a package")
15+
@click.option(
16+
"--upload", is_flag=True, default=False, help="Whether to invoke twine upload"
17+
)
18+
@click.option("--author", help="Author name, defaults to reading from git config")
19+
@click.option(
20+
"--author-email", help="Author email, defaults to reading from git config"
21+
)
22+
@click.argument("package_name")
23+
def generate(
24+
package_name: str, upload: bool, author: Optional[str], author_email: Optional[str]
25+
) -> None:
26+
# TODO flag for delete
27+
with tempfile.TemporaryDirectory(prefix=package_name) as d:
28+
env = Env(d)
29+
env.generate(
30+
package_name=package_name, author=author, author_email=author_email
31+
)
32+
if upload:
33+
env.upload()
34+
else:
35+
print("Rerun with --upload to upload")
36+
37+
38+
if __name__ == "__main__":
39+
cli()

squatter/templates.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import sys
2+
from pathlib import Path
3+
from subprocess import check_call, check_output
4+
from typing import Optional
5+
6+
SETUP_PY_TMPL = """\
7+
from setuptools import setup
8+
9+
setup(
10+
name={package_name!r},
11+
description="coming soon",
12+
version="0.0.0",
13+
author={author!r},
14+
author_email={author_email!r},
15+
)
16+
"""
17+
18+
19+
class Env:
20+
def __init__(self, staging_directory: str) -> None:
21+
self.staging_directory = staging_directory
22+
23+
def generate(
24+
self,
25+
package_name: str,
26+
author: Optional[str] = None,
27+
author_email: Optional[str] = None,
28+
) -> None:
29+
if author is None:
30+
author = check_output(
31+
["git", "config", "user.name"], encoding="utf-8"
32+
).strip()
33+
if author_email is None:
34+
author_email = check_output(
35+
["git", "config", "user.email"], encoding="utf-8"
36+
).strip()
37+
38+
data = SETUP_PY_TMPL.format(**locals())
39+
(Path(self.staging_directory) / "setup.py").write_text(data)
40+
41+
def upload(self) -> None:
42+
check_call([sys.executable, "setup.py", "sdist"], cwd=self.staging_directory)
43+
# check_call(["twine", "upload"], cwd=self.staging_directory)

0 commit comments

Comments
 (0)