-
Notifications
You must be signed in to change notification settings - Fork 2
/
tasks.py
73 lines (52 loc) · 1.8 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import itertools
import platform
import shutil
import zipfile
from pathlib import Path
from invoke import task
ROOTDIR = Path(__file__).parent.resolve()
PLATFORM_NAME = platform.system().lower().replace("darwin", "osx")
@task
def clean(c):
print("Cleaning project...")
cleaning_generator = itertools.chain(
ROOTDIR.rglob("*.py[co]"),
ROOTDIR.rglob("*~"),
ROOTDIR.rglob("*.egg-info"),
ROOTDIR.rglob("*.pyxapp"),
ROOTDIR.rglob(".coverage"),
ROOTDIR.rglob("__pycache__"),
ROOTDIR.rglob("dist"),
ROOTDIR.rglob("build"),
)
for path in cleaning_generator:
if path.is_dir():
shutil.rmtree(path)
else:
path.unlink()
print("Cleaning done!")
@task
def lint(c):
print("Running isort and flake8...")
c.run("isort .")
c.run("black .")
c.run("flake8 --max-line-length 88 --exclude .hatch,.mypy_cache .")
print("Linting done!")
@task(pre=[clean])
def package(c):
print("Packaging the game...")
package_name = f"pyxel-lander-{PLATFORM_NAME}"
code_dir = ROOTDIR / "pyxel_lander"
startup_file = code_dir / "__main__.py"
dist_dir = ROOTDIR / "dist"
package_dir = dist_dir / package_name
c.run(f"pyxel package {code_dir} {startup_file}")
package_dir.mkdir(parents=True, exist_ok=True)
shutil.move(str(ROOTDIR / "pyxel_lander.pyxapp"), str(package_dir))
shutil.copy(str(ROOTDIR / "README.md"), str(package_dir))
shutil.copy(str(ROOTDIR / "LICENSE"), str(package_dir / "LICENSE.txt"))
shutil.copy(str(ROOTDIR / "images" / "icon.png"), str(package_dir))
with zipfile.ZipFile(dist_dir / f"{package_name}.zip", "w") as fp:
for file in package_dir.iterdir():
fp.write(file, f"pyxel-lander/{file.name}")
print("Packaging done!")