-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsetuputil.py
74 lines (56 loc) · 1.74 KB
/
setuputil.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import platform
import sys
import os
import importlib
import re
# import setuptools
def find_version(fnam, version="VERSION"):
with open(fnam) as f:
cont = f.read()
regex = f'{version}\\s*=\\s*["]([^"]+)["]'
match = re.search(regex, cont)
if match is None:
raise Exception(
f"version with spec={version} not found, use double quotes for version string"
)
return match.group(1)
def find_projectname():
cwd = os.getcwd()
name = os.path.basename(cwd)
return name
def load_requirements():
with open("requirements.txt") as f:
lines = f.readlines()
lines = map(lambda x: x.strip(), lines)
lines = filter(lambda x: len(x) > 0, lines)
lines = filter(lambda x: x[0] != "#", lines)
return list(lines)
def get_scripts(projectname):
console_scripts = []
gui_scripts = []
try:
mod = importlib.import_module(f"{projectname}.__main__")
if "main_func" in dir(mod):
console_scripts = [
f"{projectname} = {projectname}.__main__:main_func",
]
if "gui_func" in dir(mod):
gui_scripts = [
f"{projectname}-ui = {projectname}.__main__:gui_func",
]
except:
print("no scripts found", file=sys.stderr)
raise Exception()
entry_points = {
"console_scripts": console_scripts,
"gui_scripts": gui_scripts,
}
return entry_points
pyver = platform.python_version_tuple()[:2]
pyversion = ".".join(pyver)
python_requires = f">={pyversion}"
projectname = find_projectname()
file = os.path.join(projectname, "const.py")
version = find_version(file)
install_requires = load_requirements()
entry_points = get_scripts(projectname)