-
Notifications
You must be signed in to change notification settings - Fork 3
/
setup.py
executable file
·195 lines (170 loc) · 5.94 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
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/usr/bin/env python
import os
import re
import shlex
import sys
from distutils.dep_util import newer
from shutil import which
from cx_Freeze import setup, Executable
import jinja2
#import setuptools
from setuptools import Command, find_packages
PO_FILES = 'po/*/messages.po'
class CleanCommand(Command):
"""
Custom clean command to tidy up the project root, because even
python setup.py clean --all
doesn't remove build/dist and egg-info directories, which can and have caused
install problems in the past.
"""
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
os.system('rm -vrf ./build ./dist ./*.pyc ./*.tgz ./*.egg-info')
if sys.version_info < (3, 6, 0):
sys.exit("Python 3.6.0 is the minimum required version")
PROJECT_ROOT = os.path.dirname(__file__)
with open(os.path.join(PROJECT_ROOT, "README.md"), "r", encoding="utf8") as file:
doc = {}
lines = []
title = "Summary"
Package_name = ""
for line in file:
line = line.strip()
if line != '':
if line.startswith("##"):
if len(lines):
if title not in doc:
doc[title] = lines
else:
doc[title] = doc[title] + lines
title = line.lstrip("#").strip()
lines = []
else:
if not line.startswith('#'):
lines.append(line)
if Package_name == "" and line.startswith('# '):
Package_name = line.lstrip("#").strip()
if len(lines):
if title not in doc:
doc[title] = lines
else:
doc[title] = doc[title] + lines
Summary = doc['Summary'][0]
Long_desc = '\n'.join(doc['Introduction'])
Website = doc['Website'][0].strip()
Copyright = doc['Copyright'][0].strip()
s = re.search('^([^\<]*)\<([^\>]*)\>$', doc['Authors'][0])
if s:
Author = s.group(1).strip()
Mail = s.group(2).strip()
Mail = Mail.replace(" dot ", ".").replace(" at ", "@").replace(" ", "")
License = doc['License'][0]
_version_re = re.compile(r"__version__\s*=\s*[\'\"](?P<version>.*)[\'\"]")
with open(os.path.join(PROJECT_ROOT, 'pid_tune', '__init__.py'), "r", encoding="utf8") as f:
match = _version_re.search(f.read())
Version = match.group("version") if match is not None else '"unknown"'
def generate_translation_files():
lang_files = []
if not os.path.exists('po'):
return []
langs = (os.path.splitext(l)[0]
for l in os.listdir('po')
if l.endswith('po') and l != "messages.po")
for lang in langs:
pofile = os.path.join("po", "%s.po" % lang)
modir = os.path.join("bootinfo", "share", "locale", lang, "LC_MESSAGES")
mofile = os.path.join(modir, "bootinfo.mo")
if not os.path.exists(modir):
os.makedirs(modir)
lang_files.append(('share/locale/%s/LC_MESSAGES' % lang, [mofile]))
if newer(pofile, mofile):
print("Generating %s" % mofile)
os.system("msgfmt %s -o %s" % (pofile, mofile))
return lang_files
def generate_doc_file():
# apply templating to all documentation files
macros = {
'package': Package_name,
'version': Version,
'man_section': '1',
'short_desc': Summary,
'long_desc': Long_desc,
'website': Website,
'copyright': Copyright,
'author': Author,
'mail': Mail,
'doc_title' : Package_name.strip() + ' Documentation',
}
for root, dirs, files in os.walk("docs"):
for file in files:
if file.endswith(".jinja"):
with open(os.path.join(root, file), 'r') as file_:
template = jinja2.Template(file_.read())
string = template.render(macros)
with open(os.path.join(root, os.path.splitext(file)[0]), "w") as ofile_:
ofile_.write(string)
if not which("asciidoctor"):
print("asciidoctor could not be located")
raise (SystemExit)
for root, dirs, files in os.walk("doc"):
for file in files:
if file.endswith(".man.adoc"):
os.subprocess.run(shlex.split("asciidoctor -b manpage %s" % os.path.join(root, file)))
data_files= [
] + generate_translation_files()
build_options = {'packages': [], 'excludes': []}
base = 'Win32GUI' if sys.platform=='win32' else None
#executables = [
# Executable('start.py', base=base, target_name = 'pid_tune')
#]
executables = [
Executable('start.py', base=base)
]
setup(
name=Package_name,
version=Version,
python_requires=">=3.6.0",
description=Summary,
long_description=Long_desc,
long_description_content_type="text/markdown",
platforms = ['Linux'],
url=Website,
author=Author,
author_email=Mail,
license=License,
classifiers=[
"Development Status :: 5 - Production/Stable",
"Environment :: Console",
"Intended Audience :: Developers",
"License :: OSI Approved :: BSD License",
"Operating System :: POSIX :: Linux",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Topic :: System :: Systems Administration",
"Topic :: System :: Operating System",
"Topic :: Utilities"
],
message_extractors = {
'pid_tune' : [
('**.py', 'python', None)
]
},
entry_points={
'console_scripts': [
'pid_tune = pid_tune.pid_tune:main'
]
},
packages=find_packages(),
data_files = data_files,
include_package_data=True,
options = {'build_exe': build_options},
executables = executables
)