@@ -181,7 +181,7 @@ def __init__(self, cfg):
181
181
if not os .path .exists (self ._log_file ):
182
182
self .table = {}
183
183
else :
184
- with open (self ._log_file , 'r' ) as file :
184
+ with open (self ._log_file , 'r' , encoding = 'utf-8' ) as file :
185
185
self .table = yaml .safe_load (file )
186
186
187
187
def log (self , filename , record ):
@@ -212,8 +212,8 @@ def log(self, filename, record):
212
212
if isinstance (filename , Path ):
213
213
filename = str (filename )
214
214
if filename in self .table :
215
- raise KeyError (
216
- "Provenance record for {} already exists." . format ( filename ) )
215
+ msg = f"Provenance record for { filename } already exists."
216
+ raise KeyError ( msg )
217
217
218
218
self .table [filename ] = record
219
219
@@ -222,7 +222,7 @@ def _save(self):
222
222
dirname = os .path .dirname (self ._log_file )
223
223
if not os .path .exists (dirname ):
224
224
os .makedirs (dirname )
225
- with open (self ._log_file , 'w' ) as file :
225
+ with open (self ._log_file , 'w' , encoding = 'utf-8' ) as file :
226
226
yaml .safe_dump (self .table , file )
227
227
228
228
def __enter__ (self ):
@@ -253,9 +253,8 @@ def select_metadata(metadata, **attributes):
253
253
"""
254
254
selection = []
255
255
for attribs in metadata :
256
- if all (a in attribs and (
257
- attribs [a ] == attributes [a ] or attributes [a ] == '*' )
258
- for a in attributes ):
256
+ if all (a in attribs and v in (attribs [a ], '*' )
257
+ for a , v in attributes .items ()):
259
258
selection .append (attribs )
260
259
return selection
261
260
@@ -424,7 +423,7 @@ def get_cfg(filename=None):
424
423
"""Read diagnostic script configuration from settings.yml."""
425
424
if filename is None :
426
425
filename = sys .argv [1 ]
427
- with open (filename ) as file :
426
+ with open (filename , encoding = 'utf-8' ) as file :
428
427
cfg = yaml .safe_load (file )
429
428
return cfg
430
429
@@ -441,7 +440,7 @@ def _get_input_data_files(cfg):
441
440
442
441
input_files = {}
443
442
for filename in metadata_files :
444
- with open (filename ) as file :
443
+ with open (filename , encoding = 'utf-8' ) as file :
445
444
metadata = yaml .safe_load (file )
446
445
input_files .update (metadata )
447
446
@@ -469,6 +468,10 @@ def main(cfg):
469
468
with run_diagnostic() as cfg:
470
469
main(cfg)
471
470
471
+ To prevent the diagnostic script from using the Dask Distributed scheduler,
472
+ set ``no_distributed: true`` in the diagnostic script definition in the
473
+ recipe or in the resulting settings.yml file.
474
+
472
475
The `cfg` dict passed to `main` contains the script configuration that
473
476
can be used with the other functions in this module.
474
477
"""
@@ -568,7 +571,9 @@ def main(cfg):
568
571
logger .info ("Removing %s from previous run." , provenance_file )
569
572
os .remove (provenance_file )
570
573
571
- if not args .no_distributed and 'scheduler_address' in cfg :
574
+ use_distributed = not (args .no_distributed
575
+ or cfg .get ('no_distributed' , False ))
576
+ if use_distributed and 'scheduler_address' in cfg :
572
577
try :
573
578
client = distributed .Client (cfg ['scheduler_address' ])
574
579
except OSError as exc :
0 commit comments