|
| 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