-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetup_check.py
56 lines (40 loc) · 1.49 KB
/
setup_check.py
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
import os
import sys
from typing import Tuple
# setup function must run only if setup.py is running as a script
try:
import setup
except SystemExit:
print(f'You have to wrap setup(...) call with: if __name__ == "__main__"', file=sys.stderr)
sys.exit(1)
def check_import_variables(required_vars: Tuple[str]):
missing_vars = [varname for varname in required_vars if not hasattr(setup, varname)]
if missing_vars:
print(f"Variables not found in setup.py: {missing_vars}", file=sys.stderr)
sys.exit(1)
required_vars = ("MODULE_NAME", "REQUIREMENTS_FILE", "SETUP_ARGS")
check_import_variables(required_vars)
from setup import MODULE_NAME, REQUIREMENTS_FILE, SETUP_ARGS
# MODULE_NAME must be the repository name
repo_name = "cfdibills"
assert repo_name == MODULE_NAME, f'REPO_NAME != "{repo_name}"'
# There must be a VERSION file in folder libname/VERSION
assert "VERSION" in os.listdir(f"{MODULE_NAME}/"), f'Cannot find file "{MODULE_NAME}/VERSION"'
# REQUIREMENTS_FILE must be 'requirements.in'
assert REQUIREMENTS_FILE == "requirements.in", f'REQUIREMENTS_FILE must be "requirements.in"'
# Check SETUP_ARGS keys
required = (
"name",
"url",
"author",
"packages",
"keywords",
"license",
"version",
"install_requires",
"extras_require",
"classifiers",
)
missing = sorted(list(set(required) - set(SETUP_ARGS.keys())))
assert not missing, f"Not all required keys were found in SETUP_ARGS: {missing}"
print("Everything ok with setup.py!")