-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtasks.py
59 lines (49 loc) · 2 KB
/
tasks.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
import sys
from pathlib import Path
from platform import system
from shutil import rmtree
from subprocess import run
from zipfile import ZipFile
from invoke import task
sys.path.insert(0, str(Path(__file__).resolve().parent / "src"))
from fomod_validator import __arcname__, __exename__, __version__
@task
def check(c):
c.run("isort -m 3 -tc -fgw 0 -up -w 88 -rc src")
c.run("black src")
c.run("flake8 --max-line-length=80 --select=C,E,F,W,B,B950 --ignore=E501 src")
@task
def build(c):
if system().lower() != "windows":
raise OSError("Freezing only supported in Windows.")
root_path = Path(__file__).resolve().parent
rmtree(root_path / "dist", ignore_errors=True)
rmtree(root_path / "build", ignore_errors=True)
dist_dir = root_path / "dist" / "pyinstaller"
print("----> Freezing executable to {}".format(dist_dir), flush=True)
spec_path = root_path / "pyinstaller.spec"
print("----> spec file found at {}".format(spec_path), flush=True)
pyinstaller_args = [
"pyinstaller",
str(spec_path),
"--clean",
"--distpath",
str(dist_dir),
]
run(pyinstaller_args).check_returncode()
print("----> Pyinstaller ran successfully!!!", flush=True)
zip_name = "{}-{}.zip".format(__arcname__, __version__)
zip_dir = root_path / "dist"
zip_path = zip_dir / zip_name
print("----> Archive will be built to {}".format(zip_path), flush=True)
exe_path = dist_dir / (__exename__ + ".exe")
assert exe_path.exists()
print("----> Executable found at {}".format(exe_path), flush=True)
included_files = ["LICENSE", "README.md", "CHANGELOG.md"]
with ZipFile(zip_path, "w") as zipfile:
zipfile.write(exe_path, arcname=__exename__ + ".exe")
for fname in included_files:
new_fname = str(Path(fname).stem + ".txt")
file_path = root_path / fname
print("----> Adding file {} to archive.".format(file_path), flush=True)
zipfile.write(file_path, arcname=new_fname)