forked from OSInside/kiwi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·221 lines (190 loc) · 6.41 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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
from setuptools import setup
from setuptools.command import sdist as setuptools_sdist
from distutils.command import build as distutils_build
from distutils.command import install as distutils_install
from distutils.command import clean as distutils_clean
import distutils
import subprocess
import os
import sys
import platform
from kiwi.version import __version__
python_version = platform.python_version().split('.')[0]
# sys.base_prefix points to the installation prefix set during python
# compilation and sys.prefix points to the same path unless we are inside
# a venv, in which case points to the $VIRTUAL_ENV value.
is_venv = sys.base_prefix != sys.prefix if sys.version_info >= (3, 3) else False
class sdist(setuptools_sdist.sdist):
"""
Custom sdist command
Host requirements: git
"""
def run(self):
"""
Run first the git commit format update $Format:%H$
and after that the usual Python sdist
"""
# git attributes
command = ['make', 'git_attributes']
self.announce(
'Running make git_attributes target: %s' % str(command),
level=distutils.log.INFO
)
self.announce(
subprocess.check_output(command).decode(),
level=distutils.log.INFO
)
# standard sdist process
setuptools_sdist.sdist.run(self)
# cleanup attributes
command = ['make', 'clean_git_attributes']
self.announce(
subprocess.check_output(command).decode(),
level=distutils.log.INFO
)
class build(distutils_build.build):
"""
Custom build command
Host requirements: make, C compiler, glibc
"""
distutils_build.build.user_options += [
('cflags=', None, 'compile flags')
]
def initialize_options(self):
"""
Set default values for options
Each user option must be listed here with their default value.
"""
distutils_build.build.initialize_options(self)
self.cflags = ''
def run(self):
"""
Run first the related KIWI C compilation and after that
the usual Python build
"""
# kiwi C tools compilation
command = ['make']
if self.cflags:
command.append('CFLAGS=%s' % self.cflags)
command.append('python_version={0}'.format(python_version))
command.append('tools')
self.announce(
'Running make tools target: %s' % str(command),
level=distutils.log.INFO
)
self.announce(
subprocess.check_output(command).decode(),
level=distutils.log.INFO
)
# standard build process
distutils_build.build.run(self)
class clean(distutils_clean.clean):
"""
Custom clean command to remove temporary files after `setup.py sdist` or
`setup.py develop`
"""
def initialize_options(self):
distutils_clean.clean.initialize_options(self)
self.clean_directories = [
'{0}.egg-info'.format(self.distribution.get_name()), 'dist'
]
def finalize_options(self):
distutils_clean.clean.finalize_options(self)
def run(self):
for directory in self.clean_directories:
if os.path.exists(directory):
distutils.dir_util.remove_tree(directory, dry_run=self.dry_run)
# standard cleaning
distutils_clean.clean.run(self)
class install(distutils_install.install):
"""
Custom install command
Host requirements: make
"""
distutils_install.install.user_options += [
('single-version-externally-managed', None,
"used by system package builders to create 'flat' eggs")
]
sub_commands = [
('install_lib', lambda self:True),
('install_headers', lambda self:False),
('install_scripts', lambda self:True),
('install_data', lambda self:False),
('install_egg_info', lambda self:True),
]
def initialize_options(self):
"""
Set default values for options
Each user option must be listed here with their default value.
"""
distutils_install.install.initialize_options(self)
self.single_version_externally_managed = None
def run(self):
"""
Run first the related KIWI installation tasks and after
that the usual Python installation
"""
# kiwi tools, completion and manual pages
command = ['make']
if self.root:
command.append('buildroot={0}/'.format(self.root))
elif is_venv:
command.append('buildroot={0}/'.format(sys.prefix))
command.append('python_version={0}'.format(python_version))
command.append('tools')
command.append('install')
self.announce(
'Running make tools, install targets: %s' % str(command),
level=distutils.log.INFO
)
self.announce(
subprocess.check_output(command).decode(),
level=distutils.log.INFO
)
# standard installation
distutils_install.install.run(self)
config = {
'name': 'kiwi',
'description': 'KIWI - Appliance Builder (next generation)',
'author': 'Marcus Schaefer',
'url': 'https://osinside.github.io/kiwi',
'download_url': 'https://download.opensuse.org/repositories/Virtualization:/Appliances:/Builder',
'author_email': '[email protected]',
'version': __version__,
'license' : 'GPLv3+',
'install_requires': [
'docopt>=0.6.2',
'lxml',
'pyxattr',
'requests',
'PyYAML'
],
'packages': ['kiwi'],
'cmdclass': {
'build': build,
'install': install,
'sdist': sdist,
'clean': clean
},
'entry_points': {
'console_scripts': [
'kiwi-ng=kiwi.kiwi:main',
'kiwicompat=kiwi.kiwi_compat:main'
]
},
'include_package_data': True,
'zip_safe': False,
'classifiers': [
# classifier: http://pypi.python.org/pypi?%3Aaction=list_classifiers
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)',
'Operating System :: POSIX :: Linux',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Topic :: System :: Operating System',
]
}
setup(**config)