@@ -181,7 +181,7 @@ def __init__(self, cfg):
181181 if not os .path .exists (self ._log_file ):
182182 self .table = {}
183183 else :
184- with open (self ._log_file , 'r' ) as file :
184+ with open (self ._log_file , 'r' , encoding = 'utf-8' ) as file :
185185 self .table = yaml .safe_load (file )
186186
187187 def log (self , filename , record ):
@@ -212,8 +212,8 @@ def log(self, filename, record):
212212 if isinstance (filename , Path ):
213213 filename = str (filename )
214214 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 )
217217
218218 self .table [filename ] = record
219219
@@ -222,7 +222,7 @@ def _save(self):
222222 dirname = os .path .dirname (self ._log_file )
223223 if not os .path .exists (dirname ):
224224 os .makedirs (dirname )
225- with open (self ._log_file , 'w' ) as file :
225+ with open (self ._log_file , 'w' , encoding = 'utf-8' ) as file :
226226 yaml .safe_dump (self .table , file )
227227
228228 def __enter__ (self ):
@@ -253,9 +253,8 @@ def select_metadata(metadata, **attributes):
253253 """
254254 selection = []
255255 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 ()):
259258 selection .append (attribs )
260259 return selection
261260
@@ -424,7 +423,7 @@ def get_cfg(filename=None):
424423 """Read diagnostic script configuration from settings.yml."""
425424 if filename is None :
426425 filename = sys .argv [1 ]
427- with open (filename ) as file :
426+ with open (filename , encoding = 'utf-8' ) as file :
428427 cfg = yaml .safe_load (file )
429428 return cfg
430429
@@ -441,7 +440,7 @@ def _get_input_data_files(cfg):
441440
442441 input_files = {}
443442 for filename in metadata_files :
444- with open (filename ) as file :
443+ with open (filename , encoding = 'utf-8' ) as file :
445444 metadata = yaml .safe_load (file )
446445 input_files .update (metadata )
447446
@@ -469,6 +468,10 @@ def main(cfg):
469468 with run_diagnostic() as cfg:
470469 main(cfg)
471470
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+
472475 The `cfg` dict passed to `main` contains the script configuration that
473476 can be used with the other functions in this module.
474477 """
@@ -568,7 +571,9 @@ def main(cfg):
568571 logger .info ("Removing %s from previous run." , provenance_file )
569572 os .remove (provenance_file )
570573
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 :
572577 try :
573578 client = distributed .Client (cfg ['scheduler_address' ])
574579 except OSError as exc :
0 commit comments