Source
1
1
import collections
2
2
import distutils.cmd
3
3
import distutils.log
4
-
import multiprocessing
5
4
import os
6
5
import shutil
7
6
import subprocess
8
7
import sys
9
8
10
9
import setuptools
11
10
from setuptools.command.build_py import build_py
12
11
13
12
ENCODING = 'utf-8' # locale.getpreferredencoding()
14
13
PIPELINE_PACKAGES = ['h', 'hif', 'hifa', 'hifas', 'hifv', 'hsd', 'hsdn']
194
193
dir_path = os.path.dirname(os.path.realpath(__file__))
195
194
196
195
if self.inplace:
197
196
self.build_path = dir_path
198
197
else:
199
198
# get the path to the build directory
200
199
build_py_cmd = self.get_finalized_command('build_py')
201
200
self.build_path = os.path.join(dir_path, build_py_cmd.build_lib)
202
201
203
202
def run(self):
204
-
nproc = min(os.cpu_count(), len(PIPELINE_PACKAGES))
205
-
self.announce(f'Running buildmytasks with {nproc} processes...', level=distutils.log.INFO)
206
-
pool = multiprocessing.Pool(nproc)
207
203
for d in PIPELINE_PACKAGES:
208
-
pool.apply_async(self.run_for_package, (d,))
209
-
pool.close()
210
-
pool.join()
211
-
212
-
def run_for_package(self, d):
213
-
cli_dir = os.path.join('pipeline', d, 'cli')
214
-
cli_module = '.'.join(['pipeline', d, 'cli'])
215
-
src_dir = os.path.join(self.build_path, cli_dir)
216
-
if not os.path.exists(src_dir):
217
-
return
218
-
219
-
cli_init_py = os.path.join(src_dir, '__init__.py')
220
-
# Remove old init module to avoid incompatible code and duplication
221
-
if os.path.exists(cli_init_py):
222
-
os.remove(cli_init_py)
223
-
224
-
gotasks_dir = os.path.join(src_dir, 'gotasks')
225
-
gotasks_init_py = os.path.join(gotasks_dir, '__init__.py')
226
-
# Remove old init module to avoid incompatible code and duplication
227
-
if os.path.exists(gotasks_init_py):
228
-
os.remove(gotasks_init_py)
229
-
230
-
for xml_file in [f for f in os.listdir(src_dir) if f.endswith('.xml')]:
231
-
self.announce('Building task from XML: {}'.format(xml_file), level=distutils.log.INFO)
232
-
subprocess.check_output([
233
-
'buildmytasks',
234
-
'--module',
235
-
cli_module,
236
-
xml_file
237
-
], cwd=src_dir)
238
-
239
-
root, _ = os.path.splitext(xml_file)
240
-
import_statement = 'from .{} import {}'.format(root, root)
241
-
with open(cli_init_py, 'a+', encoding=ENCODING) as init_file:
242
-
import_exists = any(import_statement in line for line in init_file)
243
-
if not import_exists:
244
-
init_file.seek(0, os.SEEK_END)
245
-
init_file.write('{}\n'.format(import_statement))
246
-
247
-
with open(gotasks_init_py, 'a+', encoding=ENCODING) as init_file:
248
-
import_exists = any(import_statement in line for line in init_file)
249
-
if not import_exists:
250
-
init_file.seek(0, os.SEEK_END)
251
-
init_file.write('{}\n'.format(import_statement))
204
+
cli_dir = os.path.join('pipeline', d, 'cli')
205
+
cli_module = '.'.join(['pipeline', d, 'cli'])
206
+
src_dir = os.path.join(self.build_path, cli_dir)
207
+
if not os.path.exists(src_dir):
208
+
continue
209
+
210
+
cli_init_py = os.path.join(src_dir, '__init__.py')
211
+
# Remove old init module to avoid incompatible code and duplication
212
+
if os.path.exists(cli_init_py):
213
+
os.remove(cli_init_py)
214
+
215
+
gotasks_dir = os.path.join(src_dir, 'gotasks')
216
+
gotasks_init_py = os.path.join(gotasks_dir, '__init__.py')
217
+
# Remove old init module to avoid incompatible code and duplication
218
+
if os.path.exists(gotasks_init_py):
219
+
os.remove(gotasks_init_py)
220
+
221
+
for xml_file in [f for f in os.listdir(src_dir) if f.endswith('.xml')]:
222
+
self.announce('Building task from XML: {}'.format(xml_file), level=distutils.log.INFO)
223
+
subprocess.check_output([
224
+
'buildmytasks',
225
+
'--module',
226
+
cli_module,
227
+
xml_file
228
+
], cwd=src_dir)
229
+
230
+
root, _ = os.path.splitext(xml_file)
231
+
import_statement = 'from .{} import {}'.format(root, root)
232
+
with open(cli_init_py, 'a+', encoding=ENCODING) as init_file:
233
+
import_exists = any(import_statement in line for line in init_file)
234
+
if not import_exists:
235
+
init_file.seek(0, os.SEEK_END)
236
+
init_file.write('{}\n'.format(import_statement))
237
+
238
+
with open(gotasks_init_py, 'a+', encoding=ENCODING) as init_file:
239
+
import_exists = any(import_statement in line for line in init_file)
240
+
if not import_exists:
241
+
init_file.seek(0, os.SEEK_END)
242
+
init_file.write('{}\n'.format(import_statement))
252
243
253
244
254
245
class VersionCommand(distutils.cmd.Command):
255
246
description = 'Generate the version file'
256
247
user_options = [('inplace', 'i', 'Generate the version file in src directory')]
257
248
boolean_options = ['inplace']
258
249
259
250
def __init__(self, dist):
260
251
distutils.cmd.Command.__init__(self, dist)
261
252
300
291
out,err = pipe_decode(proc.communicate( ))
301
292
#print(out)
302
293
releasetag = out.split(" ")[1].strip()
303
294
dirty=""
304
295
version = releasetag
305
296
if (len(out.split(" ")) == 3):
306
297
#print("Latest commit doesn't have a tag. Adding -dirty flag to version string.")
307
298
dirty="+" + out.split(" ")[2].strip() # "+" denotes local version identifier as described in PEP440
308
299
version = version + dirty
309
300
return version
310
-
else:
301
+
else:
311
302
# Retrieve info about current commit.
312
303
try:
313
304
# Set version to latest tag, number of commits since tag, and latest
314
305
# commit hash.
315
306
commit_hash = subprocess.check_output(['git', 'describe', '--always', '--tags', '--long', '--dirty'],
316
307
stderr=subprocess.DEVNULL).decode().strip()
317
308
print(commit_hash)
318
309
except (FileNotFoundError, subprocess.CalledProcessError):
319
310
# FileNotFoundError: if git is not on PATH.
320
311
# subprocess.CalledProcessError: if git command returns error.