forked from python-packaging/squatter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplates.py
More file actions
55 lines (45 loc) · 1.49 KB
/
templates.py
File metadata and controls
55 lines (45 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from pathlib import Path
from subprocess import check_call, check_output
from typing import Optional
PYPROJECT_TEMPLATE = """\
["build-system"]
requires = ["hatchling"]
build-backend = "hatchling.build"
[project]
name = {package_name!r}
description = "coming soon"
version = "0.0.0a1"
authors = [
{{name={author!r}, email={author_email!r} }},
]
"""
INIT_TEMPLATE = """\
'''coming soon'''
"""
class Env:
def __init__(self, staging_directory: str) -> None:
self.staging_directory = staging_directory
def generate(
self,
package_name: str,
author: Optional[str] = None,
author_email: Optional[str] = None,
) -> None:
if author is None:
author = check_output(
["git", "config", "user.name"], encoding="utf-8"
).strip()
if author_email is None:
author_email = check_output(
["git", "config", "user.email"], encoding="utf-8"
).strip()
data = PYPROJECT_TEMPLATE.format(**locals())
(Path(self.staging_directory) / "pyproject.toml").write_text(data)
pkg_dir = Path(self.staging_directory) / package_name.replace("-", "_")
pkg_dir.mkdir(parents=True, exist_ok=True)
(pkg_dir / "__init__.py").write_text(INIT_TEMPLATE)
def sdist(self) -> None:
check_call(["hatch", "build"], cwd=self.staging_directory)
def upload(self) -> None:
self.sdist()
check_call(["hatch", "upload"], cwd=self.staging_directory)