-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClickfile
170 lines (122 loc) · 4.04 KB
/
Clickfile
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
"""Klak Development Clickfile."""
import os
import sys
import logging
import subprocess
import webbrowser
from pathlib import Path
import click
import toml
from klak.cli import cli
logging.basicConfig(level=logging.DEBUG)
log = logging.getLogger("Clickfile")
# -------------------------------------
# Klak Test
# -------------------------------------
@cli.group()
def tests():
"""List commands with `klak test`."""
pass
@tests.command(name="run")
def tests_run():
"""Run the test suite."""
subprocess.run("py.test", shell=True)
@tests.command(name="tox")
def tests_tox():
"""Run the test suite under tox."""
subprocess.run("tox", shell=True)
# -------------------------------------
# Klak Docs
# -------------------------------------
@cli.group()
def docs():
"""List commands with `klak docs`."""
pass
@docs.command(name="build-module")
def docs_build_module():
"""Build klak auto-module docs."""
subprocess.run("rm -rf docs/klak.rst docs/modules.rst", shell=True)
subprocess.run("sphinx-apidoc -o docs/ klak", shell=True)
@docs.command(name="build-html")
def docs_build_html():
"""Build klack html docs."""
cwd = os.getcwd()
os.chdir("./docs")
subprocess.run("make clean", shell=True)
subprocess.run("make html", shell=True)
os.chdir(cwd)
@docs.command(name="build")
@click.pass_context
def docs_build(ctx):
"""Build package docs."""
ctx.invoke(docs_build_module)
ctx.invoke(docs_build_html)
@docs.command(name="watch")
def docs_watch():
"""Watch docs directory for changes and rebuld."""
click.secho("Watching *.rst...", fg="green")
subprocess.run(
"watchmedo shell-command -p '*.rst' -c 'klak docs build-html' -R -D . ",
shell=True,
)
@docs.command(name="serve")
def docs_serve():
"""Serve package docs locally."""
subprocess.run(
"python -m http.server --directory ./docs/_build/html 8001", shell=True
)
@docs.command(name="browse")
def docs_browse():
"""Browse docs locally, requires `klak docs serve` is running."""
subprocess.run("python -m webbrowser -t 'http://localhost:8001'", shell=True)
# -------------------------------------
# Klak Clean
# -------------------------------------
@cli.group()
def clean():
"""List commands with `klak clean`."""
@clean.command(name="build")
def clean_build():
"""Clean build artifacts."""
click.secho("Cleaning build artifacts...", fg="green")
subprocess.run("rm -rf build/ dist/ .eggs/", shell=True)
subprocess.run("find . -name '*.egg-info' -exec rm -fr {} +", shell=True)
subprocess.run("find . -name '*.egg' -exec rm -rf {} +", shell=True)
@clean.command(name="pyc")
def clean_pyc():
"""Clean Python file artifacts."""
click.secho("Cleaning Python file artifacts...", fg="green")
subprocess.run("find . -name '*.pyc' -exec rm -f {} +", shell=True)
subprocess.run("find . -name '*.pyo' -exec rm -f {} +", shell=True)
subprocess.run("find . -name '*~' -exec rm -f {} +", shell=True)
subprocess.run("find . -name '__pycache__' -exec rm -fr {} +", shell=True)
@clean.command(name="test")
def clean_test():
"""Clean test and coverage artifacts."""
click.secho("Cleaning test artifacts...", fg="green")
subprocess.run("rm -rf .tox/ .coverage .htmlcov", shell=True)
@clean.command(name="all")
@click.pass_context
def clean_all(ctx):
"""Run all clean commands."""
ctx.invoke(clean_build)
ctx.invoke(clean_pyc)
ctx.invoke(clean_test)
# -------------------------------------
# Klak Dist
# -------------------------------------
@cli.group()
def dist():
"""List commands with `klak dist`."""
@dist.command(name="build")
def dist_build():
"""Build package."""
subprocess.run("poetry build -vvv", shell=True)
@dist.command(name="publish")
def dist_publish():
"""Publish package."""
private = toml.load(Path.cwd().joinpath("private.toml"))
pypi = private["pypi"]
username = pypi["username"]
password = pypi["password"]
subprocess.run(f"poetry publish -vvv -u {username} -p {password}", shell=True)