generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathdev.py
More file actions
executable file
·88 lines (63 loc) · 2.07 KB
/
dev.py
File metadata and controls
executable file
·88 lines (63 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/usr/bin/env python3
import argparse
import subprocess
import shutil
import sys
import os
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
def run(cmd, check=True, env=None):
print("\n$ {}".format(' '.join(cmd) if isinstance(cmd, list) else cmd))
result = subprocess.run(cmd, shell=isinstance(cmd, str), check=check, env=env)
if result.returncode != 0 and check:
sys.exit(result.returncode)
def init():
print("Initializing environment")
run(["poetry", "install"])
def test():
print("Running tests")
run(["poetry", "run", "pytest", "tests"])
def lint():
print("Running linters")
run(["poetry", "run", "ruff", "check", "awslambdaric/", "tests/"])
def format_code():
print("Formatting code")
run(["poetry", "run", "ruff", "format", "awslambdaric/", "tests/"])
def clean():
print("Cleaning build artifacts")
dirs_to_remove = ["build", "dist", "*.egg-info"]
for pattern in dirs_to_remove:
for path in ROOT.glob(pattern):
if path.is_dir():
shutil.rmtree(path)
print("Removed directory: {}".format(path))
elif path.is_file():
path.unlink()
print("Removed file: {}".format(path))
def build():
print("Building package")
env = os.environ.copy()
# Set BUILD=true on Linux for native compilation
import platform
if platform.system() == "Linux":
env["BUILD"] = "true"
elif os.getenv("BUILD") == "true":
env["BUILD"] = "true"
run([sys.executable, "setup.py", "sdist", "bdist_wheel"], env=env)
def main():
parser = argparse.ArgumentParser(description="Development scripts")
parser.add_argument("command", choices=[
"init", "test", "lint", "format", "clean", "build"
])
args = parser.parse_args()
command_map = {
"init": init,
"test": test,
"lint": lint,
"format": format_code,
"clean": clean,
"build": build,
}
command_map[args.command]()
if __name__ == "__main__":
main()