add clean dev command
This commit is contained in:
parent
4c753fc512
commit
e6a119c871
47
dev.py
47
dev.py
|
@ -1,23 +1,21 @@
|
|||
#!/usr/bin/env python3
|
||||
import asyncio
|
||||
import platform
|
||||
import shlex
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
import tomllib
|
||||
import traceback
|
||||
|
||||
from collections.abc import Callable
|
||||
from datetime import datetime, timedelta
|
||||
from pathlib import Path
|
||||
from tempfile import TemporaryDirectory
|
||||
from shutil import rmtree
|
||||
from typing import TypedDict
|
||||
|
||||
try:
|
||||
import watchfiles
|
||||
|
||||
from click import Context, echo, group, option, pass_context
|
||||
from click import echo, group, option
|
||||
from tomlkit.items import Array, String, StringType, Trivia
|
||||
from tomlkit.toml_file import TOMLFile
|
||||
|
||||
|
@ -32,6 +30,9 @@ except ImportError:
|
|||
|
||||
|
||||
REPO = Path(__file__).resolve().parent
|
||||
CLEAN_DIRS = ["build", "dist", "dist-pypi", "barkshark_asgi.egg-info", "docs/_build"]
|
||||
IGNORE_DIRS = ["build", "dist", "dist-pypi", "docs", ".git", "barkshark_asgi.egg-info"]
|
||||
IGNORE_PATHS = tuple(str(REPO.joinpath(path)) for path in IGNORE_DIRS)
|
||||
|
||||
|
||||
class WatchfilesOptions(TypedDict):
|
||||
|
@ -46,6 +47,19 @@ def cli() -> None:
|
|||
...
|
||||
|
||||
|
||||
|
||||
@cli.command("clean")
|
||||
def cli_clean() -> None:
|
||||
for directory in CLEAN_DIRS:
|
||||
try:
|
||||
rmtree(REPO.joinpath(directory))
|
||||
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
echo("Cleaned up build files")
|
||||
|
||||
|
||||
@cli.command("install")
|
||||
def cli_install_deps() -> None:
|
||||
with open("pyproject.toml", "rb") as fd:
|
||||
|
@ -79,8 +93,8 @@ def cli_lint(path: Path, watch: bool) -> None:
|
|||
run_python("-m", "mypy", str(path))
|
||||
|
||||
|
||||
@cli.command("build-package")
|
||||
def cli_build_package() -> None:
|
||||
@cli.command("build")
|
||||
def cli_build() -> None:
|
||||
cli_update_files.callback() # type: ignore
|
||||
run_python("-m", " build", "--outdir", "dist-pypi")
|
||||
|
||||
|
@ -106,17 +120,6 @@ def cli_update_files() -> None:
|
|||
project_file.write(project)
|
||||
|
||||
|
||||
@cli.command("exec", context_settings = {"allow_extra_args": True})
|
||||
@option("--watch", "-w", is_flag = True)
|
||||
@pass_context
|
||||
def cli_run(ctx: Context, watch: bool = False) -> None:
|
||||
if watch:
|
||||
handle_run_watcher("-m", "barkshark_social", "run")
|
||||
return
|
||||
|
||||
run_python("-m", "basgi", *ctx.args)
|
||||
|
||||
|
||||
def run_python(*arguments: str) -> subprocess.CompletedProcess[bytes]:
|
||||
return subprocess.run([sys.executable, *arguments])
|
||||
|
||||
|
@ -137,6 +140,16 @@ async def _handle_run_watcher(*command: str) -> None:
|
|||
}
|
||||
|
||||
async for changes in watchfiles.awatch(REPO.joinpath("basgi"), **options):
|
||||
skip = False
|
||||
|
||||
for _, path in changes:
|
||||
if path.startswith(IGNORE_PATHS):
|
||||
skip = True
|
||||
|
||||
if skip:
|
||||
continue
|
||||
|
||||
|
||||
if datetime.now() - timedelta(seconds = 3) < last_restart:
|
||||
continue
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ granian = [
|
|||
"granian[reload] == 1.2.2"
|
||||
]
|
||||
uvicorn = [
|
||||
"uvicorn == 0.29.0"
|
||||
"uvicorn[standard] == 0.29.0"
|
||||
]
|
||||
docs = [
|
||||
"furo == 2024.1.29",
|
||||
|
@ -65,6 +65,7 @@ docs = [
|
|||
"sphinx-external-toc == 1.0.1"
|
||||
]
|
||||
dev = [
|
||||
"build == 1.2.1",
|
||||
"mypy == 1.9.0",
|
||||
"flake8 == 7.0.0",
|
||||
"pyinstaller == 6.5.0",
|
||||
|
@ -81,7 +82,7 @@ platforms = ["any"]
|
|||
license-files = ["LICENSE.md"]
|
||||
|
||||
[tool.setuptools.package-data]
|
||||
basgi = ["frontend"]
|
||||
basgi = ["framework"]
|
||||
|
||||
[tool.distutils.bdist_wheel]
|
||||
universal = false
|
||||
|
@ -97,7 +98,6 @@ disallow_untyped_decorators = true
|
|||
warn_redundant_casts = true
|
||||
warn_unreachable = true
|
||||
warn_unused_ignores = true
|
||||
ignore_missing_imports = true
|
||||
follow_imports = "silent"
|
||||
strict = true
|
||||
implicit_reexport = true
|
||||
|
|
Loading…
Reference in a new issue