-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage.py
77 lines (66 loc) · 2.43 KB
/
manage.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# -*- coding: utf-8 -*-
# ~ Jesse K. Rubin ~ Pretty Useful Python
from os import path
from subprocess import run
from sys import argv
from pupy.foreign import files_gen
from pupy.savings_n_loads import lstr
from pupy.savings_n_loads import sstr
from pupy.sh import basename
PUPY_HEADER = "# -*- coding: utf-8 -*-\n# Pretty ~ Useful ~ Python"
CDPATH = path.split(path.abspath(__file__))[0]
SRC_PATH = path.join(CDPATH, "pupy")
STUBS_PATH = path.join(CDPATH, "stubs")
TESTS_PATH = path.join(SRC_PATH, "tests")
def mkstub(filepath):
run(args=["stubgen", "-o", "stubs", filepath])
def mkstubs():
ignore = ["__init__.py", "__main__.py", "_version.py", "_typing.py"]
src_python_files = (fpath for fpath in files_gen(SRC_PATH) if fpath.endswith(".py"))
src_python_files = [f for f in src_python_files if not any(s in f for s in ignore)]
for src_file in src_python_files:
mkstub(src_file)
stub_files = (fpath for fpath in files_gen(STUBS_PATH) if fpath.endswith(".pyi"))
for stub in stub_files:
print(stub)
stub_name = basename(stub)
stub_filepath = path.join(SRC_PATH, stub_name)
stublimes = lstr(stub).splitlines(keepends=False)[3:]
stub_file_string = "\n".join([PUPY_HEADER, *stublimes])
sstr(stub, stub_file_string)
def cleanup_file(filepath):
filename = filepath.replace(SRC_PATH, "").strip("\\")
mkstub(filepath)
# run(args=['black', filepath])
# run(args=['isort', '-sl', filepath])
def cleanup_src():
print("cleaning src")
print(CDPATH)
src_python_files = (fpath for fpath in files_gen(SRC_PATH) if fpath.endswith(".py"))
python_test_files = (
fpath for fpath in files_gen(TESTS_PATH) if fpath.endswith(".py")
)
print("PROCESSING SRC CODE")
for python_file in src_python_files:
cleanup_file(python_file)
print("PROCESSING TESTS CODE")
for python_file in python_test_files:
cleanup_file(python_file)
def redoc():
sphinx_args = ["python", "-m", "sphinx", "-b", "html", "docs/", "docs/_build/"]
run(args=sphinx_args)
def main():
if len(argv) == 1:
commands = ["python manage.py cleanup ~ cleanup the src files"]
print("__SHELDON_MANAGE__")
print("\n".join(commands))
return
#########
if "mkstubs" in argv:
mkstubs()
if "cleanup" in argv:
cleanup_src()
if "redoc" in argv:
redoc()
if __name__ == "__main__":
main()