-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.py
53 lines (39 loc) · 1.5 KB
/
config.py
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
""" configuration for the package """
import toml
from pathlib import Path
import typer
here = Path(__file__).parent.resolve()
docs = here / "docs"
requirements = docs / "requirements.txt"
pyproject = here / "pyproject.toml"
conf = typer.Typer()
@conf.command("hello")
def hello():
""" at least two commands required. This function is just dummy. """
typer.echo("hello world")
@conf.command("create", help="create requirements.txt in docs folder")
def create_requirements():
'''
Sphinx is grouchy about requirements.txt
So, before pushing to Github, we create a fresh requirements.txt from pyproject.toml
'''
t = toml.load(pyproject).get("tool", {}).get("poetry", {})
with open(requirements, "w") as f:
# get dependencies without versions
dep = t.get("dependencies", {}).keys()
# skip python
dep = list(dep)[1:]
print("# These dependencies are derived from pyproject.toml",
"# The file is prepared for Sphinx, which is grouchy about using it :(",
"",
"# Dependencies", sep="\n",
file=f)
for key in dep:
print(key, file=f)
devdep = list(t.get("dev-dependencies", {}).keys())
print("# Dev-Dependencies", file=f)
for key in devdep:
print(key, file=f)
typer.secho("created requirements.txt in docs folder", bold=True, fg="red")
if __name__ == "__main__":
conf()