-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7b7315d
commit bc78b85
Showing
10 changed files
with
251 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
help: | ||
@echo "FastDevCli development makefile" | ||
@echo | ||
@echo "Usage: make <target>" | ||
@echo "Targets:" | ||
@echo " up Updates dev/test dependencies" | ||
@echo " deps Ensure dev/test dependencies are installed" | ||
@echo " check Checks that build is sane" | ||
@echo " test Runs all tests" | ||
@echo " style Auto-formats the code" | ||
@echo " lint Auto-formats the code and check type hints" | ||
|
||
up: | ||
@poetry run fast upgrade | ||
|
||
deps: | ||
@poetry install | ||
|
||
_check: | ||
./scripts/check.py | ||
check: deps _build _check | ||
|
||
_lint: | ||
@poetry run fast lint | ||
lint: deps _build _lint | ||
|
||
_test: | ||
./scripts/test.py | ||
test: deps _test | ||
|
||
_style: | ||
./scripts/format.py | ||
style: deps _style | ||
|
||
_build: | ||
rm -fR dist/ | ||
poetry build | ||
build: deps _build |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/env python | ||
""" | ||
Check style by `ruff` and verify type hints by `mypy`, | ||
then run `bandit -r <package>` to find security issue. | ||
Usage:: | ||
./scripts/check.py | ||
""" | ||
|
||
import os | ||
import sys | ||
|
||
CMD = "fast check" | ||
TOOL = ("poetry", "pdm", "")[0] | ||
BANDIT = True | ||
parent = os.path.abspath(os.path.dirname(__file__)) | ||
work_dir = os.path.dirname(parent) | ||
if os.getcwd() != work_dir: | ||
os.chdir(work_dir) | ||
|
||
cmd = "{} run {}".format(TOOL, CMD) if TOOL else CMD | ||
if os.system(cmd) != 0: | ||
print("\033[1m Please run './scripts/format.py' to auto-fix style issues \033[0m") | ||
sys.exit(1) | ||
|
||
if BANDIT: | ||
package_name = os.path.basename(work_dir).replace("-", "_") | ||
cmd = "{}bandit -r {}".format(TOOL and f"{TOOL} run ", package_name) | ||
print("-->", cmd) | ||
if os.system(cmd) != 0: | ||
sys.exit(1) | ||
print("Done. ✨ 🍰 ✨") |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/usr/bin/env python | ||
""" | ||
Run `ruff format` to make style and `ruff check --fix` to remove unused imports | ||
Usage: | ||
./scripts/format.py | ||
""" | ||
|
||
import os | ||
import shlex | ||
import subprocess | ||
import sys | ||
from pathlib import Path | ||
|
||
CMD = "fast lint" | ||
TOOL = ("poetry", "pdm", "")[0] | ||
work_dir = Path(__file__).parent.resolve().parent | ||
if Path.cwd() != work_dir: | ||
os.chdir(str(work_dir)) | ||
|
||
cmd = (TOOL and f"{TOOL} run ") + CMD | ||
r = subprocess.run(shlex.split(cmd), env=dict(os.environ, SKIP_MYPY="1")) | ||
sys.exit(None if r.returncode == 0 else 1) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#!/usr/bin/env python | ||
import os | ||
import shlex | ||
import subprocess | ||
import sys | ||
import time | ||
from pathlib import Path | ||
|
||
TOOL = ("poetry", "pdm", "")[0] | ||
work_dir = Path(__file__).parent.resolve().parent | ||
if Path.cwd() != work_dir: | ||
os.chdir(str(work_dir)) | ||
|
||
PREPARE = "python tests/prepare_media.py" | ||
CMD = "python scripts/parallel_test.py" | ||
COMBINE = "coverage combine examples/*/.coverage tests/*/.coverage" | ||
REPORT = 'coverage report --omit="tests/*" -m' | ||
|
||
|
||
def get_result_files(): | ||
for folder in ("examples", "tests"): | ||
for file in work_dir.joinpath(folder).rglob(".coverage"): | ||
yield file | ||
|
||
|
||
def remove_outdate_files(start_time: float) -> None: | ||
for file in get_result_files(): | ||
if file.stat().st_mtime < start_time: | ||
file.unlink() | ||
print(f"Removed outdate file: {file}") | ||
|
||
|
||
def chdir(path: Path) -> None: | ||
os.chdir(str(path)) | ||
print("--> cd", path) | ||
|
||
|
||
def run_command(cmd: str, shell=False, tool=TOOL, env=None) -> None: | ||
prefix = tool + " run " | ||
if tool and not cmd.startswith(prefix): | ||
cmd = prefix + cmd | ||
print("-->", cmd, flush=True) | ||
if env is not None: | ||
env = dict(os.environ, **env) | ||
r = subprocess.run(cmd if shell else shlex.split(cmd), shell=shell, env=None) | ||
r.returncode and sys.exit(1) | ||
|
||
|
||
def combine_result_files(shell=COMBINE) -> None: | ||
to_be_combine = [i.name for i in get_result_files()] | ||
if to_be_combine: | ||
if sys.platform == "win32": | ||
shell = "coverage combine " | ||
if work_dir.joinpath(".coverage").exists(): | ||
shell += ".coverage " | ||
shell += " ".join(to_be_combine) | ||
run_command(shell, True) | ||
|
||
|
||
started_at = time.time() | ||
run_command(PREPARE) | ||
if "--no-parallel" in sys.argv: | ||
for folder in work_dir.joinpath("tests").glob("*"): | ||
if not folder.is_dir(): | ||
continue | ||
chdir(folder) | ||
run_command("coverage run -m pytest -s", tool="") | ||
else: | ||
run_command(CMD) | ||
for eg in ("normal", "offline"): | ||
chdir(work_dir / "examples" / eg) | ||
run_command("coverage run -m pytest -s", tool="") | ||
os.chdir(str(work_dir)) | ||
remove_outdate_files(started_at) | ||
combine_result_files() | ||
run_command(REPORT) |
This file was deleted.
Oops, something went wrong.