Skip to content

Commit

Permalink
_load_pmg_settings() make SETTINGS_FILE read op atomic
Browse files Browse the repository at this point in the history
  • Loading branch information
janosh committed Oct 21, 2022
1 parent b53d22e commit 3e54dc9
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions pymatgen/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@
def _load_pmg_settings() -> dict[str, str]:
settings = {}
# Load .pmgrc.yaml file
if os.path.exists(SETTINGS_FILE):
try:
yaml = YAML()
with open(SETTINGS_FILE) as f:
d_yml = yaml.load(f)
settings.update(d_yml)
except Exception as ex:
# If there are any errors, default to using environment variables
# if present.
warnings.warn(f"Error loading .pmgrc.yaml: {ex}. You may need to reconfigure your yaml file.")
try:
yaml = YAML()
with open(SETTINGS_FILE) as yml_file:
settings = yaml.load(yml_file)
except FileNotFoundError:
pass
except Exception as ex:
# If there are any errors, default to using environment variables
# if present.
warnings.warn(f"Error loading .pmgrc.yaml: {ex}. You may need to reconfigure your yaml file.")

# Override .pmgrc.yaml with env vars if present
for k, v in os.environ.items():
Expand Down

0 comments on commit 3e54dc9

Please sign in to comment.