-
Notifications
You must be signed in to change notification settings - Fork 13
/
do.py
123 lines (91 loc) · 2.81 KB
/
do.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
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
import datetime
import os
import re
import shutil
import subprocess
import sys
from pathlib import Path
import PyInstaller.__main__ as compile
import click
import neatest
from chkpkg import Package
@click.group()
def app():
pass
@app.command()
def test():
_test()
def _test():
neatest.run(warnings=neatest.Warnings.fail)
@app.command()
def test_pkg():
with Package() as pkg:
pkg.run_shell_code('img2texture --version')
# running console_scripts defined in setup.py
pkg.run_shell_code('img2texture --help')
pkg.run_shell_code('img2texture', expected_return_code=2)
# running img2texture/__main__.py
pkg.run_shell_code('python -m img2texture',
expected_return_code=2)
pkg.run_shell_code('python -m img2texture --help',
expected_return_code=0)
print("\nPackage is OK!")
@app.command()
def run():
subprocess.call([sys.executable, "-m", "img2texture"])
@app.command()
def lint():
_lint()
def _lint():
print("Running mypy...")
if subprocess.call(['mypy', 'img2texture',
'--ignore-missing-imports']) != 0:
exit(1)
def _replace_build_date(fn: Path):
now = datetime.datetime.now().isoformat(sep=" ", timespec="seconds")
text = fn.read_text()
new_text = re.sub(
r'__build_timestamp__.+',
f'__build_timestamp__ = "{now}"',
text)
print(new_text)
assert new_text != text, "timestamp not changed"
fn.write_text(new_text)
def _get_single_file(dirpath: Path) -> Path:
exes = list(dirpath.glob("*"))
assert len(exes) == 1
return Path(exes[0])
@app.command()
def build():
name = "img2texture"
project_dir = Path(__file__).parent
_test()
_lint()
_replace_build_date(Path("img2texture/_constants.py"))
compile.run([
"--clean", "--onefile", "-y",
"--collect-all", "img2texture",
#"--log-level", "DEBUG",
#"--specpath", "pyinstaller.myspec",
"--exclude-module", 'FixTk',
"--exclude-module", 'tcl',
"--exclude-module", 'tk',
"--exclude-module", '_tkinter',
"--exclude-module", 'tkinter',
"--exclude-module", 'Tkinter',
"--exclude-module", "IPython",
"--exclude-module", "mypy",
"--exclude-module", "pip",
"--exclude-module", "click",
"--exclude-module", "neatest",
"--exclude-module", "chkpkg",
"--name", name, "_run.py"
])
exe = _get_single_file(project_dir / "dist")
print()
print(f"Created {exe}")
print(f"Exe size: {exe.stat().st_size / 1024 / 1024:.0f} MiB")
os.remove(project_dir / "img2texture.spec") # этот генерируется автоматичски
shutil.rmtree(project_dir / "build")
if __name__ == "__main__":
app()