Skip to content

Commit 8a38e94

Browse files
author
AntoniaSzecsi
committed
Delegate dev commands to scripts/dev.py
1 parent 4737561 commit 8a38e94

File tree

2 files changed

+79
-19
lines changed

2 files changed

+79
-19
lines changed

Makefile

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,23 @@ target:
55

66
.PHONY: init
77
init:
8-
poetry install
8+
python scripts/dev.py init
99

1010
.PHONY: test
11-
test: check-format
12-
poetry run pytest --cov awslambdaric --cov-report term-missing --cov-fail-under 90 tests
11+
test:
12+
python scripts/dev.py test
13+
14+
.PHONY: lint
15+
lint:
16+
python scripts/dev.py lint
17+
18+
.PHONY: clean
19+
clean:
20+
python scripts/dev.py clean
21+
22+
.PHONY: build
23+
build:
24+
python scripts/dev.py build
1325

1426
.PHONY: setup-codebuild-agent
1527
setup-codebuild-agent:
@@ -45,30 +57,21 @@ pr: init check-format check-security dev
4557
codebuild: setup-codebuild-agent
4658
CODEBUILD_IMAGE_TAG=codebuild-agent DISTRO="$(DISTRO)" tests/integration/codebuild-local/test_all.sh tests/integration/codebuild
4759

48-
.PHONY: clean
49-
clean:
50-
rm -rf dist
51-
rm -rf awslambdaric.egg-info
52-
find . -type d -name "__pycache__" -exec rm -r {} +
53-
54-
.PHONY: build
55-
build: clean
56-
poetry build
57-
5860
define HELP_MESSAGE
5961

6062
Usage: $ make [TARGETS]
6163

6264
TARGETS
6365
check-security Run bandit to find security issues.
6466
format Run black to automatically update your code to match formatting.
65-
build Builds the package with poetry.
66-
clean Cleans the working directory by removing built artifacts.
67-
dev Run all development tests after a change.
68-
init Install dependencies via Poetry.
67+
build Build the package using scripts/dev.py.
68+
clean Cleans the working directory using scripts/dev.py.
69+
dev Run all development tests using scripts/dev.py.
70+
init Install dependencies via scripts/dev.py.
6971
pr Perform all checks before submitting a Pull Request.
70-
test Run the unit tests.
72+
test Run unit tests using scripts/dev.py.
73+
lint Run all linters via scripts/dev.py.
7174
test-smoke Run smoke tests inside Docker.
7275
test-integ Run all integration tests.
7376

74-
endef
77+
endef

scripts/dev.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env python3
2+
import argparse
3+
import subprocess
4+
import shutil
5+
import sys
6+
from pathlib import Path
7+
8+
ROOT = Path(__file__).resolve().parent.parent
9+
10+
11+
def run(cmd, check=True):
12+
print(f"\n$ {' '.join(cmd) if isinstance(cmd, list) else cmd}")
13+
result = subprocess.run(cmd, shell=isinstance(cmd, str), check=check)
14+
if result.returncode != 0 and check:
15+
sys.exit(result.returncode)
16+
17+
18+
def init():
19+
print("Initializing environment")
20+
run(["poetry", "install"])
21+
22+
23+
def test():
24+
print("Running tests")
25+
run(["poetry", "run", "pytest", "tests"])
26+
27+
28+
def lint():
29+
print("Running lint checks")
30+
run(["poetry", "run", "flake8", "awslambdaric"])
31+
run(["poetry", "run", "pylint", "awslambdaric"])
32+
run(["poetry", "run", "black", "--check", "awslambdaric"])
33+
run(["poetry", "run", "bandit", "-r", "awslambdaric"])
34+
35+
36+
def clean():
37+
print("Cleaning build and cache files")
38+
patterns = ["__pycache__", "*.pyc", "*.pyo", ".pytest_cache", ".mypy_cache"]
39+
for pattern in patterns:
40+
for path in ROOT.rglob(pattern):
41+
if path.is_dir():
42+
shutil.rmtree(path)
43+
elif path.is_file():
44+
path.unlink()
45+
46+
47+
def build():
48+
print("Building package")
49+
run(["poetry", "build"])
50+
51+
52+
if __name__ == "__main__":
53+
parser = argparse.ArgumentParser(description="Development command-line tool")
54+
parser.add_argument("command", choices=["init", "test", "lint", "clean", "build"])
55+
args = parser.parse_args()
56+
57+
globals()[args.command]()

0 commit comments

Comments
 (0)