replace build script with dev script

This commit is contained in:
Izalia Mae 2024-03-19 19:12:43 -04:00
parent f863bc5e0a
commit 1950773e67

View file

@ -1,5 +1,7 @@
#!/usr/bin/env python3
import platform
import shlex
import shutil
import subprocess
import sys
@ -7,11 +9,39 @@ from gemi import __version__
from pathlib import Path
from tempfile import TemporaryDirectory
try:
import click
except ImportError:
proc = subprocess.run([sys.executable, "-m", "pip", "install", "click"], check = False)
if proc.returncode != 0:
sys.exit()
print("Successfully installed click")
import click
REPO = Path(__file__).resolve().parent
if __name__ == "__main__":
@click.group("cli")
def cli():
pass
@cli.command("clean")
def cli_clean():
for directory in {"build", "dist", "gemi_python.egg-info"}:
try:
shutil.rmtree(directory)
except FileNotFoundError:
pass
@cli.command("build")
def cli_build():
with TemporaryDirectory() as tmp:
arch = "amd64" if sys.maxsize >= 2**32 else "i386"
bins = (
@ -36,7 +66,7 @@ if __name__ == "__main__":
cmd.append("--noconsole")
# putting the spec path on a different drive than the source dir breaks
if str(SCRIPT)[0] == tmp[0]:
if str(REPO)[0] == tmp[0]:
cmd.extend(["--specpath", tmp])
else:
@ -45,5 +75,23 @@ if __name__ == "__main__":
subprocess.run(cmd, check = True)
# for specfile in REPO.glob("*.spec"):
# specfile.unlink()
for specfile in REPO.glob("*.spec"):
specfile.unlink()
@cli.command("lint")
def cli_lint():
click.echo("--- flake8 ---")
subprocess.run(shlex.split(f"{sys.executable} -m flake8 gemi"))
click.echo("\n--- mypy ---")
subprocess.run(shlex.split(f"{sys.executable} -m mypy gemi"))
@cli.command("install")
def cli_install():
subprocess.run(shlex.split(f"{sys.executable} -m pip install -e .[dev,doc]"), check = False)
if __name__ == "__main__":
cli()