diff --git a/nomad/cli/dev.py b/nomad/cli/dev.py index 8936027d4a6fd6788a265f6bf80cf6a09971adc3..85a8d39d29e51fb58550f02eab4eb29cdbe3f329 100644 --- a/nomad/cli/dev.py +++ b/nomad/cli/dev.py @@ -254,7 +254,7 @@ def _generate_example_upload_metadata(): import yaml with open('examples/data/uploads/example_uploads.yml') as infile: - return yaml.load(infile, Loader=yaml.FullLoader) + return yaml.load(infile, Loader=yaml.SafeLoader) @dev.command( @@ -340,7 +340,7 @@ def update_parser_readmes(parser): # read local yaml metadata file with open(path, 'r') as metadata_f: try: - metadata = yaml.load(metadata_f, Loader=yaml.FullLoader) + metadata = yaml.load(metadata_f, Loader=yaml.SafeLoader) except Exception as e: print(f'Error reading metadata.yaml: {e}') metadata = None diff --git a/nomad/config/__init__.py b/nomad/config/__init__.py index 99a5666cfe3b603b703e5dc35ce6eb6c456c440a..e3cc0156b9716e1f606f0ffbe05a8ebf7dfa1ebc 100644 --- a/nomad/config/__init__.py +++ b/nomad/config/__init__.py @@ -786,7 +786,7 @@ def _apply_nomad_yaml(): with open(config_file, 'r') as stream: try: - config_data = yaml.load(stream, Loader=getattr(yaml, 'FullLoader')) + config_data = yaml.load(stream, Loader=yaml.SafeLoader) except yaml.YAMLError as e: logger.error(f'cannot read nomad config: {e}') return diff --git a/nomad/config/plugins.py b/nomad/config/plugins.py index c59a027f146d8b5997ede37d9e527d9044da8890..f5d819df347311d482171bdf8c5cf49510c3b4ba 100644 --- a/nomad/config/plugins.py +++ b/nomad/config/plugins.py @@ -106,7 +106,7 @@ class PythonPluginBase(PluginBase): if os.path.exists(metadata_path): try: with open(metadata_path, 'r', encoding='UTF-8') as f: - metadata = yaml.load(f, Loader=yaml.FullLoader) + metadata = yaml.load(f, Loader=yaml.SafeLoader) except Exception as e: raise ValueError( f'Cannot load plugin metadata file {metadata_path}.', e diff --git a/nomad/files.py b/nomad/files.py index 1bb49ffcc3472fbeb597228ab5901e9e51902c6e..921a6fdafb6b13a8e0eafa50c68f38cb5a93f83d 100644 --- a/nomad/files.py +++ b/nomad/files.py @@ -1170,7 +1170,7 @@ class StagingUploadFiles(UploadFiles): if full_path.endswith('.json'): return json.load(f) elif full_path.endswith('.yaml') or full_path.endswith('.yml'): - return yaml.load(f, Loader=getattr(yaml, 'FullLoader')) + return yaml.load(f, Loader=yaml.SafeLoader) else: return {} except Exception as e: diff --git a/nomad/mkdocs.py b/nomad/mkdocs.py index a30f5d57688df24941414ea46a68ea1a52246764..542f4957e081711f1860bfd18f3f552dacab5138 100644 --- a/nomad/mkdocs.py +++ b/nomad/mkdocs.py @@ -251,7 +251,7 @@ def define_env(env): with open(file_path, 'rt') as f: if file_path.endswith('.yaml'): - data = yaml.load(f, Loader=yaml.FullLoader) + data = yaml.load(f, Loader=yaml.SafeLoader) elif file_path.endswith('.json'): data = json.load(f) else: diff --git a/nomad/parsing/parser.py b/nomad/parsing/parser.py index 439325df858ca88e750ee3fbdba665867278588d..5d401eddf82a1ca36ea80846f3dae76f8e44fa52 100644 --- a/nomad/parsing/parser.py +++ b/nomad/parsing/parser.py @@ -252,7 +252,7 @@ class MatchingParser(Parser): logger = utils.get_logger(__name__) try: with open(metadata_file, 'r', encoding='UTF-8') as f: - parser_metadata = yaml.load(f, Loader=yaml.FullLoader) + parser_metadata = yaml.load(f, Loader=yaml.SafeLoader) except Exception as e: logger.warning('failed to read parser metadata', exc_info=e) raise @@ -523,7 +523,7 @@ class ArchiveParser(MatchingParser): else: import yaml - archive_data = yaml.load(f, Loader=getattr(yaml, 'FullLoader')) + archive_data = yaml.load(f, Loader=yaml.SafeLoader) except Exception as e: if logger: logger.error('Cannot parse archive json or yaml.', exc_info=e) diff --git a/ops/scripts/submodules/__init__.py b/ops/scripts/submodules/__init__.py index d2f70fd365f585d8f8d4254ad410464e9f336c98..3cbf46d782435274d619e84e2a7764e2f7fd7fab 100644 --- a/ops/scripts/submodules/__init__.py +++ b/ops/scripts/submodules/__init__.py @@ -70,8 +70,8 @@ def move_submodule_to_github(path: str): return origin = next( - line for line in sh('git remote -v').split('\n') - if line.startswith('origin')) + line for line in sh('git remote -v').split('\n') if line.startswith('origin') + ) origin = re.split(r'\t| ', origin)[1] if 'github.com/nomad-coe' in origin: @@ -95,19 +95,22 @@ def move_submodule_to_github(path: str): os.remove('LICENSE.txt') # 2. update copyright headers header_templ = os.path.join(os.path.dirname(__file__), 'apache-2.tmpl') - sh(f'licenseheaders -t {header_templ} -o "The NOMAD Authors" -u "https://nomad-lab.eu" -n NOMAD -x "*.yaml" "*.yml"') + sh( + f'licenseheaders -t {header_templ} -o "The NOMAD Authors" -u "https://nomad-lab.eu" -n NOMAD -x "*.yaml" "*.yml"' + ) # 3. create an authors file authors_file = 'AUTHORS' authors = [ re.split(r'\t| ', line.strip(), 1)[1] - for line in sh('git shortlog -sne').splitlines()] + for line in sh('git shortlog -sne').splitlines() + ] with open(authors_file, 'wt') as f: f.write('\n'.join(authors)) f.write('\n') # 4. update the metadata with open('metadata.yaml', 'rt') as f: - parser_metadata = yaml.load(f, Loader=yaml.FullLoader) + parser_metadata = yaml.load(f, Loader=yaml.SafeLoader) title = parser_metadata['codeLabel'] parser_metadata['parserGitUrl'] = github_url parser_metadata['preamble'] = '' @@ -125,17 +128,21 @@ def move_submodule_to_github(path: str): 'https://api.github.com/orgs/nomad-coe/repos', headers={ 'Accept': 'application/vnd.github.v3+json', - 'Authorization': f'token {os.environ["GITHUB_TOKEN"]}'}, - data=json.dumps({ - 'name': f'nomad-parser-{name}', - 'description': f'This is a NOMAD parser for {title}. It will read {title} input and output files and provide all information in NOMAD\'s unified Metainfo based Archive format.', - 'private': False, - 'visibility': True, - 'has_issues': True, - 'has_projects': False, - 'has_wiki': False, - 'team_id': 4443059 - })) + 'Authorization': f'token {os.environ["GITHUB_TOKEN"]}', + }, + data=json.dumps( + { + 'name': f'nomad-parser-{name}', + 'description': f"This is a NOMAD parser for {title}. It will read {title} input and output files and provide all information in NOMAD's unified Metainfo based Archive format.", + 'private': False, + 'visibility': True, + 'has_issues': True, + 'has_projects': False, + 'has_wiki': False, + 'team_id': 4443059, + } + ), + ) if result.status_code >= 400: print('Could not create github repository: ', result.text) @@ -148,10 +155,10 @@ def move_submodule_to_github(path: str): f'https://api.github.com/orgs/nomad-coe/teams/nomad-parser-developer/repos/nomad-coe/nomad-parser-{name}', headers={ 'Accept': 'application/vnd.github.v3+json', - 'Authorization': f'token {os.environ["GITHUB_TOKEN"]}'}, - data=json.dumps({ - 'permission': 'push' - })) + 'Authorization': f'token {os.environ["GITHUB_TOKEN"]}', + }, + data=json.dumps({'permission': 'push'}), + ) if result.status_code >= 400: print('Could not set tream permission repository: ', result.text) diff --git a/tests/metainfo/test_to_dict.py b/tests/metainfo/test_to_dict.py index 8732fd8982471dccaea412c42074985283ef22de..9eebee55d98e05ffb3a95532339144a59ea846cf 100644 --- a/tests/metainfo/test_to_dict.py +++ b/tests/metainfo/test_to_dict.py @@ -307,7 +307,7 @@ section_definitions: def test_schema_deserialization(schema_yaml): - schema_dict = yaml.load(schema_yaml, yaml.FullLoader) + schema_dict = yaml.load(schema_yaml, yaml.SafeLoader) pkg = Package.m_from_dict(schema_dict) pkg.init_metainfo() @@ -342,7 +342,7 @@ def test_schema_definition_id(schema_yaml): """ Test if the definition id is correctly generated. """ - schema_dict = yaml.load(schema_yaml, yaml.FullLoader) + schema_dict = yaml.load(schema_yaml, yaml.SafeLoader) pkg = Package.m_from_dict(schema_dict) pkg.init_metainfo()