-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
181 lines (155 loc) · 5.02 KB
/
setup.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
from setuptools import setup, find_packages
import re, io, os
class getPackageInfo:
def __init__(self):
self._package_module_name = None
self._package_main_file = None
self._git_config_file = None
self._long_description = None
self._description = None
self._version = None
self._author = None
self._author_email = None
self._git_host = None
self._package_name = None
self._git_issues_host = None
self._required_packages = None
self.__Process()
def __Process(self):
self.__getPackageModuleNameFromProject()
self.__getPacketInitFileContent()
self.__getconfigGIT()
self.__getLongDescription()
self.__getDescription()
self.__getVersion()
self.__getAuthor()
self.__getAuthorEmail()
self.__getGITHost()
self.__getPackageName()
self.__getGITIssuesHost()
self.__getRequiredPackageList()
def __getRequiredPackageList(self):
dependencies =[]
with open("requirements.txt", "r", encoding="utf-8") as fh:
lines = fh.readlines()
for line in lines:
cleanline = re.sub('\s+', '', line)
if (not cleanline == ""):
dependencies.append(re.sub('\s+', '', line))
self._required_packages = dependencies
return True
def __getPackageModuleNameFromProject(self):
for dir in next(os.walk(".\src"))[1]:
if not ".egg-info" in str(dir):
self._package_module_name = dir
return True
def __getLongDescription(self):
with open("README.md", "r", encoding="utf-8") as fh:
self._long_description = fh.read()
return True
def __getPacketInitFileContent(self):
self._package_main_file = io.open(
os.path.join('src', self._package_module_name,'__init__.py'),
encoding='utf_8_sig'
).read()
return True
def __getconfigGIT(self):
with open(os.path.join(os.getcwd(), '.git', 'config'), "r", encoding="utf-8") as fh:
self._git_config_file = fh.read()
return True
def __getDescription(self):
self._description = re.search(
r'(?<=\"\"\")((.|\n)*)(?=\"\"\")',
self._package_main_file
).group(1)
return True
def __getVersion(self):
self._version = re.search(
r'__version__\s*=\s*[\'"]([^\'"]*)[\'"]',
self._package_main_file
).group(1)
return True
def __getAuthor(self):
self._author = re.search(
r'__author__\s*=\s*[\'"]([^\'"]*)[\'"]',
self._package_main_file
).group(1)
return True
def __getAuthorEmail(self):
self._author_email = re.search(
r'__email__\s*=\s*[\'"]([^\'"]*)[\'"]',
self._package_main_file
).group(1)
return True
def __getGITHost(self):
self._git_host = re.search(
r'(?<=\[remote "origin"\]\n\turl = )((.|\n)*)(?=\.git)',
self._git_config_file
).group(1)
return True
def __getGITIssuesHost(self):
self._git_issues_host = self._git_host + "/issues"
return True
def __getPackageName(self):
self._package_name = self._git_host.rsplit('/', 1)[-1]
return True
@property
def package_name(self):
return self._package_name
@property
def long_description(self):
return self._long_description
@property
def description(self):
return self._description
@property
def version(self):
return self._version
@property
def author(self):
return self._author
@property
def author_email(self):
return self._author_email
@property
def git_host(self):
return self._git_host
@property
def git_issues_host(self):
return self._git_issues_host
@property
def required_packages(self):
return self._required_packages
PACKAGE_INFO = getPackageInfo()
setup(
name = PACKAGE_INFO.package_name,
version = PACKAGE_INFO.version,
author = PACKAGE_INFO.author ,
author_email = PACKAGE_INFO.author_email ,
description = PACKAGE_INFO.description,
long_description = PACKAGE_INFO.long_description,
long_description_content_type = "text/markdown",
url = PACKAGE_INFO.git_host,
project_urls = {
"Bug Tracker": PACKAGE_INFO.git_issues_host,
},
data_files=[
(
'.git.',
['.git/config']
),
(
'.',
["requirements.txt"]
)
],
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
package_dir = { "": "src"},
packages = find_packages(where = "src"),
python_requires = ">=3.10",
install_requires=PACKAGE_INFO.required_packages
)