Python 3 library and CLI application for SporeStack
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
1.6 KiB

import shutil
import subprocess
from pathlib import Path
from typing import List
import typer
app = typer.Typer()
def run(command: List[str]) -> None:
typer.echo(f"Running command: {' '.join(command)}", err=True)
try:
subprocess.run(command).check_returncode()
except subprocess.CalledProcessError:
# Hide traceback, it's not useful.
raise typer.Exit(code=1) from None
@app.command()
def format() -> None:
"""
Format the code as needed.
"""
run(["black", "."])
run(["isort", "."])
@app.command()
def test() -> None:
_test_formatting()
_test_common()
@app.command()
def format_test() -> None:
format()
_test_common()
def _test_formatting() -> None:
run(["black", "--check", "."])
run(["isort", "--check", "."])
def _test_common() -> None:
run(["flake8", "."])
run(["mypy", "--strict", "."])
test_pytest()
@app.command()
def test_pytest() -> None:
run(
[
"pytest",
"--cov=sporestack",
"--cov-fail-under=49",
"--cov-report=term",
"--durations=3",
"--cache-clear",
]
)
@app.command()
def build_dist() -> None:
dist = Path("dist")
if dist.exists():
shutil.rmtree(dist)
run(["python", "-m", "build", "--sdist", "--no-isolation"])
run(["asaman", "-o", str(dist), "-d", str(dist)])
run(["twine", "check", "--strict", f"{dist}/*"])
@app.command()
def publish() -> None:
dist = Path("dist")
build_dist()
run(["twine", "upload", f"{dist}/*"])
if __name__ == "__main__":
app()