Skip to content

Commit 44b9eea

Browse files
authored
Merge pull request #442 from jkloetzke/fix-pyyaml-compat
Fix pyyaml compatibility and other potential problems
2 parents cb7ee2b + 78ad0a2 commit 44b9eea

File tree

15 files changed

+146
-103
lines changed

15 files changed

+146
-103
lines changed

.github/workflows/workflow.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ jobs:
2222
- name: Install dependencies
2323
run: |
2424
python -m pip install --upgrade pip
25-
pip install PyYAML codecov schema python-magic pyparsing sphinx wheel
25+
pip install PyYAML coverage schema python-magic pyparsing sphinx wheel
2626
sudo apt-get update
2727
sudo apt-get install cvs
2828
2929
- name: Run unit tests
3030
run: |
3131
git config --global init.defaultBranch master # keep the old name
32-
eatmydata ./test/run-tests.sh
32+
eatmydata ./test/run-tests.sh -c xml
3333
3434
- name: Build Python package
3535
run: |
@@ -38,7 +38,7 @@ jobs:
3838
- name: Upload coverage to Codecov
3939
# Coverage is not complete on Python <3.7 (see pym/bob/utils.py)
4040
if: matrix.python-version != '3.6'
41-
uses: codecov/codecov-action@v1
41+
uses: codecov/codecov-action@v2
4242

4343
- name: Publish package
4444
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')

pym/bob/archive.py

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,11 @@ def canUploadJenkins(self):
8989
def canCache(self):
9090
return False
9191

92-
async def uploadPackage(self, step, buildId, audit, content):
92+
async def uploadPackage(self, step, buildId, audit, content, executor=None):
9393
pass
9494

95-
async def downloadPackage(self, step, buildId, audit, content, caches=[]):
95+
async def downloadPackage(self, step, buildId, audit, content, caches=[],
96+
executor=None):
9697
return False
9798

9899
def upload(self, step, buildIdFile, tgzFile):
@@ -101,19 +102,19 @@ def upload(self, step, buildIdFile, tgzFile):
101102
def download(self, step, buildIdFile, tgzFile):
102103
return ""
103104

104-
async def uploadLocalLiveBuildId(self, step, liveBuildId, buildId):
105+
async def uploadLocalLiveBuildId(self, step, liveBuildId, buildId, executor=None):
105106
pass
106107

107-
async def downloadLocalLiveBuildId(self, step, liveBuildId):
108+
async def downloadLocalLiveBuildId(self, step, liveBuildId, executor=None):
108109
return None
109110

110111
def uploadJenkinsLiveBuildId(self, step, liveBuildId, buildId, isWin):
111112
return ""
112113

113-
async def uploadLocalFingerprint(self, step, key, fingerprint):
114+
async def uploadLocalFingerprint(self, step, key, fingerprint, executor=None):
114115
pass
115116

116-
async def downloadLocalFingerprint(self, step, key):
117+
async def downloadLocalFingerprint(self, step, key, executor=None):
117118
return None
118119

119120
def uploadJenkinsFingerprint(self, step, keyFile, fingerprintFile):
@@ -199,7 +200,8 @@ def __extractPackage(self, tar, audit, content):
199200
def _openDownloadFile(self, buildId, suffix):
200201
raise ArtifactNotFoundError()
201202

202-
async def downloadPackage(self, step, buildId, audit, content, caches=[]):
203+
async def downloadPackage(self, step, buildId, audit, content, caches=[],
204+
executor=None):
203205
if not self.canDownloadLocal():
204206
return False
205207

@@ -208,7 +210,7 @@ async def downloadPackage(self, step, buildId, audit, content, caches=[]):
208210
details = " from {}".format(self._remoteName(buildId, suffix))
209211
with stepAction(step, "DOWNLOAD", content, details=details) as a:
210212
try:
211-
ret, msg, kind = await loop.run_in_executor(None, BaseArchive._downloadPackage,
213+
ret, msg, kind = await loop.run_in_executor(executor, BaseArchive._downloadPackage,
212214
self, buildId, suffix, audit, content, caches)
213215
if not ret: a.fail(msg, kind)
214216
return ret
@@ -255,14 +257,14 @@ def _downloadPackage(self, buildId, suffix, audit, content, caches):
255257
# to prevent ugly backtraces when user presses ctrl+c.
256258
signal.signal(signal.SIGINT, signal.SIG_DFL)
257259

258-
async def downloadLocalLiveBuildId(self, step, liveBuildId):
260+
async def downloadLocalLiveBuildId(self, step, liveBuildId, executor=None):
259261
if not self.canDownloadLocal():
260262
return None
261263

262264
loop = asyncio.get_event_loop()
263265
with stepAction(step, "MAP-SRC", self._remoteName(liveBuildId, BUILDID_SUFFIX), (INFO,TRACE)) as a:
264266
try:
265-
ret, msg, kind = await loop.run_in_executor(None,
267+
ret, msg, kind = await loop.run_in_executor(executor,
266268
BaseArchive._downloadLocalFile, self, liveBuildId, BUILDID_SUFFIX)
267269
if ret is None: a.fail(msg, kind)
268270
return ret
@@ -294,7 +296,7 @@ def _downloadLocalFile(self, key, suffix):
294296
def _openUploadFile(self, buildId, suffix):
295297
raise ArtifactUploadError("not implemented")
296298

297-
async def uploadPackage(self, step, buildId, audit, content):
299+
async def uploadPackage(self, step, buildId, audit, content, executor=None):
298300
if not self.canUploadLocal():
299301
return
300302
if not audit:
@@ -307,7 +309,7 @@ async def uploadPackage(self, step, buildId, audit, content):
307309
details = " to {}".format(self._remoteName(buildId, suffix))
308310
with stepAction(step, "UPLOAD", content, details=details) as a:
309311
try:
310-
msg, kind = await loop.run_in_executor(None, BaseArchive._uploadPackage,
312+
msg, kind = await loop.run_in_executor(executor, BaseArchive._uploadPackage,
311313
self, buildId, suffix, audit, content)
312314
a.setResult(msg, kind)
313315
except (concurrent.futures.CancelledError, concurrent.futures.process.BrokenProcessPool):
@@ -339,14 +341,14 @@ def _uploadPackage(self, buildId, suffix, audit, content):
339341
signal.signal(signal.SIGINT, signal.SIG_DFL)
340342
return ("ok", EXECUTED)
341343

342-
async def uploadLocalLiveBuildId(self, step, liveBuildId, buildId):
344+
async def uploadLocalLiveBuildId(self, step, liveBuildId, buildId, executor=None):
343345
if not self.canUploadLocal():
344346
return
345347

346348
loop = asyncio.get_event_loop()
347349
with stepAction(step, "CACHE-BID", self._remoteName(liveBuildId, BUILDID_SUFFIX), (INFO,TRACE)) as a:
348350
try:
349-
msg, kind = await loop.run_in_executor(None, BaseArchive._uploadLocalFile, self, liveBuildId, BUILDID_SUFFIX, buildId)
351+
msg, kind = await loop.run_in_executor(executor, BaseArchive._uploadLocalFile, self, liveBuildId, BUILDID_SUFFIX, buildId)
350352
a.setResult(msg, kind)
351353
except (concurrent.futures.CancelledError, concurrent.futures.process.BrokenProcessPool):
352354
raise BuildError("Upload of build-id interrupted.")
@@ -372,26 +374,26 @@ def _uploadLocalFile(self, key, suffix, content):
372374
signal.signal(signal.SIGINT, signal.SIG_DFL)
373375
return ("ok", EXECUTED)
374376

375-
async def uploadLocalFingerprint(self, step, key, fingerprint):
377+
async def uploadLocalFingerprint(self, step, key, fingerprint, executor=None):
376378
if not self.canUploadLocal():
377379
return
378380

379381
loop = asyncio.get_event_loop()
380382
with stepAction(step, "CACHE-FPR", self._remoteName(key, FINGERPRINT_SUFFIX)) as a:
381383
try:
382-
msg, kind = await loop.run_in_executor(None, BaseArchive._uploadLocalFile, self, key, FINGERPRINT_SUFFIX, fingerprint)
384+
msg, kind = await loop.run_in_executor(executor, BaseArchive._uploadLocalFile, self, key, FINGERPRINT_SUFFIX, fingerprint)
383385
a.setResult(msg, kind)
384386
except (concurrent.futures.CancelledError, concurrent.futures.process.BrokenProcessPool):
385387
raise BuildError("Upload of build-id interrupted.")
386388

387-
async def downloadLocalFingerprint(self, step, key):
389+
async def downloadLocalFingerprint(self, step, key, executor=None):
388390
if not self.canDownloadLocal():
389391
return None
390392

391393
loop = asyncio.get_event_loop()
392394
with stepAction(step, "MAP-FPRNT", self._remoteName(key, FINGERPRINT_SUFFIX)) as a:
393395
try:
394-
ret, msg, kind = await loop.run_in_executor(None,
396+
ret, msg, kind = await loop.run_in_executor(executor,
395397
BaseArchive._downloadLocalFile, self, key, FINGERPRINT_SUFFIX)
396398
if ret is None: a.fail(msg, kind)
397399
return ret
@@ -1193,16 +1195,16 @@ def canDownloadJenkins(self):
11931195
def canUploadJenkins(self):
11941196
return any(i.canUploadJenkins() for i in self.__archives)
11951197

1196-
async def uploadPackage(self, step, buildId, audit, content):
1198+
async def uploadPackage(self, step, buildId, audit, content, executor=None):
11971199
for i in self.__archives:
11981200
if not i.canUploadLocal(): continue
1199-
await i.uploadPackage(step, buildId, audit, content)
1201+
await i.uploadPackage(step, buildId, audit, content, executor=executor)
12001202

1201-
async def downloadPackage(self, step, buildId, audit, content):
1203+
async def downloadPackage(self, step, buildId, audit, content, executor=None):
12021204
for i in self.__archives:
12031205
if not i.canDownloadLocal(): continue
12041206
caches = [ a for a in self.__archives if (a is not i) and a.canCache() ]
1205-
if await i.downloadPackage(step, buildId, audit, content, caches):
1207+
if await i.downloadPackage(step, buildId, audit, content, caches, executor):
12061208
return True
12071209
return False
12081210

@@ -1216,16 +1218,16 @@ def download(self, step, buildIdFile, tgzFile):
12161218
i.download(step, buildIdFile, tgzFile) for i in self.__archives
12171219
if i.canDownloadJenkins())
12181220

1219-
async def uploadLocalLiveBuildId(self, step, liveBuildId, buildId):
1221+
async def uploadLocalLiveBuildId(self, step, liveBuildId, buildId, executor=None):
12201222
for i in self.__archives:
12211223
if not i.canUploadLocal(): continue
1222-
await i.uploadLocalLiveBuildId(step, liveBuildId, buildId)
1224+
await i.uploadLocalLiveBuildId(step, liveBuildId, buildId, executor=executor)
12231225

1224-
async def downloadLocalLiveBuildId(self, step, liveBuildId):
1226+
async def downloadLocalLiveBuildId(self, step, liveBuildId, executor=None):
12251227
ret = None
12261228
for i in self.__archives:
12271229
if not i.canDownloadLocal(): continue
1228-
ret = await i.downloadLocalLiveBuildId(step, liveBuildId)
1230+
ret = await i.downloadLocalLiveBuildId(step, liveBuildId, executor=executor)
12291231
if ret is not None: break
12301232
return ret
12311233

@@ -1234,16 +1236,16 @@ def uploadJenkinsLiveBuildId(self, step, liveBuildId, buildId, isWin):
12341236
i.uploadJenkinsLiveBuildId(step, liveBuildId, buildId, isWin)
12351237
for i in self.__archives if i.canUploadJenkins())
12361238

1237-
async def uploadLocalFingerprint(self, step, key, fingerprint):
1239+
async def uploadLocalFingerprint(self, step, key, fingerprint, executor=None):
12381240
for i in self.__archives:
12391241
if not i.canUploadLocal(): continue
1240-
await i.uploadLocalFingerprint(step, key, fingerprint)
1242+
await i.uploadLocalFingerprint(step, key, fingerprint, executor=executor)
12411243

1242-
async def downloadLocalFingerprint(self, step, key):
1244+
async def downloadLocalFingerprint(self, step, key, executor=None):
12431245
ret = None
12441246
for i in self.__archives:
12451247
if not i.canDownloadLocal(): continue
1246-
ret = await i.downloadLocalFingerprint(step, key)
1248+
ret = await i.downloadLocalFingerprint(step, key, executor=executor)
12471249
if ret is not None: break
12481250
return ret
12491251

pym/bob/cmds/build/build.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def _downloadArgument(arg):
3939
return arg
4040
raise argparse.ArgumentTypeError("{} invalid.".format(arg))
4141
def _downloadLayerArgument(arg):
42-
if re.match('^(yes|no|forced)=\S+$', arg):
42+
if re.match(r'^(yes|no|forced)=\S+$', arg):
4343
return arg
4444
raise argparse.ArgumentTypeError("{} invalid.".format(arg))
4545

@@ -139,7 +139,7 @@ def _downloadLayerArgument(arg):
139139

140140
startTime = time.time()
141141

142-
with EventLoopWrapper() as loop:
142+
with EventLoopWrapper() as (loop, executor):
143143
recipes = RecipeSet()
144144
recipes.defineHook('releaseNameFormatter', LocalBuilder.releaseNameFormatter)
145145
recipes.defineHook('developNameFormatter', LocalBuilder.developNameFormatter)
@@ -223,6 +223,7 @@ def _downloadLayerArgument(arg):
223223
args.preserve_env, envWhiteList, bobRoot, args.clean,
224224
args.no_logfiles)
225225

226+
builder.setExecutor(executor)
226227
builder.setArchiveHandler(getArchiver(recipes))
227228
builder.setUploadMode(args.upload)
228229
builder.setDownloadMode(args.download)

pym/bob/cmds/build/builder.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,10 @@ def __init__(self, verbose, force, skipDeps, buildOnly, preserveEnv,
307307
self.__share = NullShare()
308308
self.__useSharedPackages = False
309309
self.__installSharedPackages = False
310+
self.__executor = None
311+
312+
def setExecutor(self, executor):
313+
self.__executor = executor
310314

311315
def setArchiveHandler(self, archive):
312316
self.__archive = archive
@@ -622,7 +626,8 @@ async def _runShell(self, step, scriptName, logger, cleanWorkspace=None):
622626

623627
invoker = Invoker(spec, self.__preserveEnv, self.__noLogFile,
624628
self.__verbose >= INFO, self.__verbose >= NORMAL,
625-
self.__verbose >= DEBUG, self.__bufferedStdIO)
629+
self.__verbose >= DEBUG, self.__bufferedStdIO,
630+
executor=self.__executor)
626631
if step.jobServer() and self.__jobServer:
627632
invoker.setMakeParameters(self.__jobServer.getMakeFd(), self.__jobs)
628633
ret = await invoker.executeStep(InvocationMode.CALL, cleanWorkspace)
@@ -643,7 +648,8 @@ async def _runLocalSCMs(self, step, logger):
643648
spec = StepSpec.fromStep(step, logFile=logFile)
644649
invoker = Invoker(spec, self.__preserveEnv, self.__noLogFile,
645650
self.__verbose >= INFO, self.__verbose >= NORMAL,
646-
self.__verbose >= DEBUG, self.__bufferedStdIO)
651+
self.__verbose >= DEBUG, self.__bufferedStdIO,
652+
executor=self.__executor)
647653
ret = await invoker.executeLocalSCMs()
648654
if not self.__bufferedStdIO: ttyReinit() # work around MSYS2 messing up the console
649655
if ret == -int(signal.SIGINT):
@@ -1081,7 +1087,8 @@ async def _cookCheckoutStep(self, checkoutStep, depth):
10811087
if created and self.__archive.canUploadLocal() and checkoutStep.hasLiveBuildId():
10821088
liveBId = checkoutStep.calcLiveBuildId()
10831089
if liveBId is not None:
1084-
await self.__archive.uploadLocalLiveBuildId(checkoutStep, liveBId, checkoutHash)
1090+
await self.__archive.uploadLocalLiveBuildId(checkoutStep, liveBId, checkoutHash,
1091+
executor=self.__executor)
10851092

10861093
# We're done. The sanity check below won't change the result but would
10871094
# trigger this step again.
@@ -1333,7 +1340,7 @@ async def _downloadPackage(self, packageStep, depth, packageBuildId):
13331340
if BobState().getResultHash(prettyPackagePath) is None:
13341341
audit = os.path.join(prettyPackagePath, "..", "audit.json.gz")
13351342
wasDownloaded = await self.__archive.downloadPackage(packageStep,
1336-
packageBuildId, audit, prettyPackagePath)
1343+
packageBuildId, audit, prettyPackagePath, executor=self.__executor)
13371344
if wasDownloaded:
13381345
self.__statistic.packagesDownloaded += 1
13391346
BobState().setInputHashes(prettyPackagePath,
@@ -1400,7 +1407,7 @@ async def _cookPackageStep(self, packageStep, checkoutOnly, depth, mayUpOrDownlo
14001407
audit = await self._generateAudit(packageStep, depth, packageHash)
14011408
if mayUpOrDownload and self.__archive.canUploadLocal():
14021409
await self.__archive.uploadPackage(packageStep, packageBuildId,
1403-
audit, prettyPackagePath)
1410+
audit, prettyPackagePath, executor=self.__executor)
14041411

14051412
# Rehash directory if content was changed
14061413
if workspaceChanged:
@@ -1499,7 +1506,7 @@ async def __translateLiveBuildId(self, step, liveBId):
14991506
if bid is not None:
15001507
return bid
15011508

1502-
bid = await self.__archive.downloadLocalLiveBuildId(step, liveBId)
1509+
bid = await self.__archive.downloadLocalLiveBuildId(step, liveBId, executor=self.__executor)
15031510
if bid is not None:
15041511
BobState().setBuildId(key, bid)
15051512

@@ -1727,7 +1734,8 @@ async def __calcFingerprintTask(self, step, sandbox, key, depth):
17271734
async with self.__runners:
17281735
# If this is built in a sandbox then the artifact cache may help...
17291736
if sandbox:
1730-
fingerprint = await self.__archive.downloadLocalFingerprint(sandbox, key)
1737+
fingerprint = await self.__archive.downloadLocalFingerprint(sandbox, key,
1738+
executor=self.__executor)
17311739
else:
17321740
fingerprint = None
17331741

@@ -1743,7 +1751,8 @@ async def __calcFingerprintTask(self, step, sandbox, key, depth):
17431751
# only be run once so we don't need to worry here about duplicate
17441752
# uploads.
17451753
if sandbox:
1746-
await self.__archive.uploadLocalFingerprint(sandbox, key, fingerprint)
1754+
await self.__archive.uploadLocalFingerprint(sandbox, key, fingerprint,
1755+
executor=self.__executor)
17471756

17481757
# Cache result so that we don't ever need to spawn a task
17491758
self.__fingerprints[key] = fingerprint
@@ -1757,7 +1766,8 @@ async def __calcFingerprintTask(self, step, sandbox, key, depth):
17571766

17581767
async def __runFingerprintScript(self, step, logger):
17591768
spec = StepSpec.fromStep(step, None, self.__envWhiteList)
1760-
invoker = Invoker(spec, self.__preserveEnv, True, True, True, False, True)
1769+
invoker = Invoker(spec, self.__preserveEnv, True, True, True, False, True,
1770+
executor=self.__executor)
17611771
(ret, stdout, stderr) = await invoker.executeFingerprint()
17621772

17631773
if ret == -int(signal.SIGINT):
@@ -1780,7 +1790,8 @@ async def __runScmSwitch(self, step, scmPath, scm, oldSpec):
17801790
spec = StepSpec.fromStep(step, None, self.__envWhiteList, logFile)
17811791
invoker = Invoker(spec, self.__preserveEnv, self.__noLogFile,
17821792
self.__verbose >= INFO, self.__verbose >= NORMAL,
1783-
self.__verbose >= DEBUG, self.__bufferedStdIO)
1793+
self.__verbose >= DEBUG, self.__bufferedStdIO,
1794+
executor=self.__executor)
17841795

17851796
class Abort(Exception):
17861797
pass

pym/bob/cmds/invoke.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,21 @@ def doInvoke(argv, bobRoot):
4545
raise BuildError("Error reading spec: " + str(e))
4646

4747
# Let's do it...
48-
with EventLoopWrapper() as loop:
48+
with EventLoopWrapper() as (loop, executor):
4949
if args.mode == 'shell':
50-
invoker = Invoker(spec, args.preserve_env, True, True, True, False, False)
50+
invoker = Invoker(spec, args.preserve_env, True, True, True, False,
51+
False, executor=executor)
5152
ret = loop.run_until_complete(invoker.executeStep(InvocationMode.SHELL,
5253
args.clean, args.keep_sandbox))
5354
elif args.mode == 'run':
5455
invoker = Invoker(spec, args.preserve_env, args.no_logfiles,
55-
verbosity >= 2, verbosity >= 1, verbosity >= 3, False)
56+
verbosity >= 2, verbosity >= 1, verbosity >= 3, False,
57+
executor=executor)
5658
ret = loop.run_until_complete(invoker.executeStep(InvocationMode.CALL,
5759
args.clean, args.keep_sandbox))
5860
elif args.mode == 'fingerprint':
59-
invoker = Invoker(spec, args.preserve_env, True, True, True, verbosity >= 3, False)
61+
invoker = Invoker(spec, args.preserve_env, True, True, True,
62+
verbosity >= 3, False, executor=executor)
6063
(ret, stdout, stderr) = loop.run_until_complete(invoker.executeFingerprint(args.keep_sandbox))
6164
if ret == 0:
6265
sys.stdout.buffer.write(stdout)

0 commit comments

Comments
 (0)