-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsetup.py
129 lines (110 loc) · 3.8 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
"""
l18n
Locale internationalization package
(c) 2014-2021 Thomas Khyn and contributors (see CONTRIBUTORS.rst)
MIT License (see LICENSE.txt)
"""
import os
import io
from setuptools import setup
from distutils import log
import subprocess
# imports __version__ variable
exec(open('l18n/version.py').read())
dev_status = __version_info__[3]
if dev_status == 'alpha' and not __version_info__[4]:
dev_status = 'pre'
DEV_STATUS = {'pre': '2 - Pre-Alpha',
'alpha': '3 - Alpha',
'beta': '4 - Beta',
'rc': '4 - Beta',
'final': '5 - Production/Stable'}
CMD_PACKAGES = {
'sdist': 'setuptools.command',
'bdist': 'distutils.command',
'bdist_wheel': 'wheel',
'bdist_egg': 'setuptools.command',
'bdist_rpm': 'setuptools.command',
}
try:
from setuptools.command import bdist_wininst
CMD_PACKAGES['bdist_wininst'] = 'setuptools.command'
except ImportError:
# python > 3.10
pass
class PredistBuild(object):
"""
Mixin class to build translation files
"""
def build_trans(self):
log.info('building translation files')
# we need to use buildout, call the following commands in the specified
# order, and reverse if an issue is raised
cmds = [[os.path.join('bin', 'build')],
[os.path.join('bin', 'buildout'), 'parts=build'],
['python', 'bootstrap.py']]
cmd = 0
try:
from subprocess import DEVNULL
except ImportError:
DEVNULL = open(os.devnull, 'wb')
while True:
try:
log.info(' - calling "%s"' % ' '.join(cmds[cmd]))
if subprocess.Popen(cmds[cmd], stderr=DEVNULL,
stdout=DEVNULL).wait():
raise OSError
if not cmd:
break
else:
cmd -= 1
except OSError:
cmd += 1
if cmd > 2:
if os.path.exists(os.path.join(os.path.dirname(__file__),
'l18n', '__maps.py')):
break
else:
raise RuntimeError('Could not build translation files')
log.info('translation files built successfully')
cmd_classes = {}
for cmd, module in CMD_PACKAGES.items():
cmd_module = getattr(__import__(module, fromlist=[cmd]), cmd)
base_class = getattr(cmd_module, cmd)
def get_run(base_class):
def run(self):
self.build_trans()
return base_class.run(self)
return run
cmd_classes[cmd] = type(cmd + '_build', (base_class, PredistBuild), {
'run': get_run(base_class)
})
# setup function parameters
setup(
name='l18n',
version=__version__,
description='Internationalization for pytz timezones and territories',
long_description=io.open('README.rst', mode='r', encoding='utf-8').read(),
author='Thomas Khyn',
author_email='[email protected]',
url='https://github.com/tkhyn/l18n',
keywords=['pytz', 'translation', 'i18n'],
classifiers=[
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'License :: OSI Approved :: MIT License',
'Operating System :: OS Independent',
'Development Status :: %s' % DEV_STATUS[dev_status],
'Intended Audience :: Developers',
'Environment :: Other Environment',
'Topic :: Software Development :: Internationalization'
],
packages=('l18n',),
install_requires=(
'pytz>=2020.1',
'six'
),
cmdclass=cmd_classes,
zip_safe=False,
include_package_data=True,
)