Skip to content

Commit

Permalink
Merge branch 'master' into autonbands
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew-S-Rosen committed May 21, 2024
2 parents da260bd + 8832873 commit 4270f3f
Show file tree
Hide file tree
Showing 103 changed files with 2,810 additions and 573 deletions.
17 changes: 17 additions & 0 deletions .coderabbit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
language: "en-US"
early_access: false
reviews:
request_changes_workflow: false
high_level_summary: false
poem: false
review_status: false
collapse_walkthrough: false
auto_review:
enabled: true
ignore_title_keywords:
- "WIP"
- "DO NOT MERGE"
drafts: false
chat:
auto_reply: true
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ ci:

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.2
rev: v0.4.3
hooks:
- id: ruff
args: [--fix, --ignore, D]
args: [--fix, --ignore, D, --unsafe-fixes]
- id: ruff-format

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: check-yaml
exclude: pymatgen/analysis/vesta_cutoffs.yaml
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
rev: v1.10.0
hooks:
- id: mypy
additional_dependencies: [types-requests]
Expand Down
2 changes: 1 addition & 1 deletion custodian/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"Shyue Ping Ong, William Davidson Richards, Stephen Dacek, Xiaohui Qu, Matthew Horton, "
"Samuel M. Blau, Janosh Riebesell"
)
__version__ = "2024.1.9"
__version__ = "2024.4.18"


PKG_DIR = os.path.dirname(__file__)
Expand Down
139 changes: 70 additions & 69 deletions custodian/ansible/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
def get_nested_dict(input_dict, key):
"""Helper function to interpret a nested dict input."""
current = input_dict
toks = key.split("->")
n = len(toks)
for i, tok in enumerate(toks):
tokens = key.split("->")
n = len(tokens)
for i, tok in enumerate(tokens):
if tok not in current and i < n - 1:
current[tok] = {}
elif i == n - 1:
return current, toks[-1]
return current, tokens[-1]
current = current[tok]
return None

Expand Down Expand Up @@ -46,7 +46,7 @@ class DictActions:
"""

@staticmethod
def set(input_dict, settings, directory=None):
def set(input_dict, settings, directory=None) -> None:
"""
Sets a value using MongoDB syntax.
Expand All @@ -55,12 +55,12 @@ def set(input_dict, settings, directory=None):
settings (dict): The specification of the modification to be made.
directory (None): dummy parameter for compatibility with FileActions
"""
for k, v in settings.items():
(d, key) = get_nested_dict(input_dict, k)
d[key] = v
for key, val in settings.items():
dct, sub_key = get_nested_dict(input_dict, key)
dct[sub_key] = val

@staticmethod
def unset(input_dict, settings, directory=None):
def unset(input_dict, settings, directory=None) -> None:
"""
Unset a value using MongoDB syntax.
Expand All @@ -74,7 +74,7 @@ def unset(input_dict, settings, directory=None):
del dct[inner_key]

@staticmethod
def push(input_dict, settings, directory=None):
def push(input_dict, settings, directory=None) -> None:
"""
Push to a list using MongoDB syntax.
Expand All @@ -83,15 +83,15 @@ def push(input_dict, settings, directory=None):
settings (dict): The specification of the modification to be made.
directory (None): dummy parameter for compatibility with FileActions
"""
for k, v in settings.items():
(d, key) = get_nested_dict(input_dict, k)
if key in d:
d[key].append(v)
for key, val in settings.items():
dct, sub_key = get_nested_dict(input_dict, key)
if sub_key in dct:
dct[sub_key].append(val)
else:
d[key] = [v]
dct[sub_key] = [val]

@staticmethod
def push_all(input_dict, settings, directory=None):
def push_all(input_dict, settings, directory=None) -> None:
"""
Push multiple items to a list using MongoDB syntax.
Expand All @@ -108,24 +108,24 @@ def push_all(input_dict, settings, directory=None):
dct[k2] = val

@staticmethod
def inc(input_dict, settings, directory=None):
def inc(input_dict, settings, directory=None) -> None:
"""
Increment a value using MongdoDB syntax.
Increment a value using MongoDB syntax.
Args:
input_dict (dict): The input dictionary to be modified.
settings (dict): The specification of the modification to be made.
directory (None): dummy parameter for compatibility with FileActions
"""
for k, v in settings.items():
(d, key) = get_nested_dict(input_dict, k)
if key in d:
d[key] += v
for key, val in settings.items():
dct, sub_key = get_nested_dict(input_dict, key)
if sub_key in dct:
dct[sub_key] += val
else:
d[key] = v
dct[sub_key] = val

@staticmethod
def rename(input_dict, settings, directory=None):
def rename(input_dict, settings, directory=None) -> None:
"""
Rename a key using MongoDB syntax.
Expand All @@ -134,12 +134,12 @@ def rename(input_dict, settings, directory=None):
settings (dict): The specification of the modification to be made.
directory (None): dummy parameter for compatibility with FileActions
"""
for key, v in settings.items():
if val := input_dict.pop(key, None):
input_dict[v] = val
for key, val in settings.items():
if input_val := input_dict.pop(key, None):
input_dict[val] = input_val

@staticmethod
def add_to_set(input_dict, settings, directory=None):
def add_to_set(input_dict, settings, directory=None) -> None:
"""
Add to set using MongoDB syntax.
Expand All @@ -148,17 +148,17 @@ def add_to_set(input_dict, settings, directory=None):
settings (dict): The specification of the modification to be made.
directory (None): dummy parameter for compatibility with FileActions
"""
for k, v in settings.items():
(d, key) = get_nested_dict(input_dict, k)
if key in d and (not isinstance(d[key], list)):
raise ValueError(f"Keyword {k} does not refer to an array.")
if key in d and v not in d[key]:
d[key].append(v)
elif key not in d:
d[key] = v
for key, val in settings.items():
dct, sub_key = get_nested_dict(input_dict, key)
if sub_key in dct and (not isinstance(dct[sub_key], list)):
raise ValueError(f"Keyword {key} does not refer to an array.")
if sub_key in dct and val not in dct[sub_key]:
dct[sub_key].append(val)
elif sub_key not in dct:
dct[sub_key] = val

@staticmethod
def pull(input_dict, settings, directory=None):
def pull(input_dict, settings, directory=None) -> None:
"""
Pull an item using MongoDB syntax.
Expand All @@ -175,7 +175,7 @@ def pull(input_dict, settings, directory=None):
dct[k2] = [itm for itm in dct[k2] if itm != val]

@staticmethod
def pull_all(input_dict, settings, directory=None):
def pull_all(input_dict, settings, directory=None) -> None:
"""
Pull multiple items to a list using MongoDB syntax.
Expand All @@ -191,7 +191,7 @@ def pull_all(input_dict, settings, directory=None):
DictActions.pull(input_dict, {key: itm})

@staticmethod
def pop(input_dict, settings, directory=None):
def pop(input_dict, settings, directory=None) -> None:
"""
Pop item from a list using MongoDB syntax.
Expand All @@ -200,14 +200,14 @@ def pop(input_dict, settings, directory=None):
settings (dict): The specification of the modification to be made.
directory (None): dummy parameter for compatibility with FileActions
"""
for k, v in settings.items():
(d, key) = get_nested_dict(input_dict, k)
if key in d and (not isinstance(d[key], list)):
raise ValueError(f"Keyword {k} does not refer to an array.")
if v == 1:
d[key].pop()
elif v == -1:
d[key].pop(0)
for key, val in settings.items():
dct, sub_key = get_nested_dict(input_dict, key)
if sub_key in dct and (not isinstance(dct[sub_key], list)):
raise ValueError(f"Keyword {key} does not refer to an array.")
if val == 1:
dct[sub_key].pop()
elif val == -1:
dct[sub_key].pop(0)


class FileActions:
Expand All @@ -218,7 +218,7 @@ class FileActions:
"""

@staticmethod
def file_create(filename, settings, directory):
def file_create(filename, settings, directory) -> None:
"""
Creates a file.
Expand All @@ -229,13 +229,13 @@ def file_create(filename, settings, directory):
"""
if len(settings) != 1:
raise ValueError("Settings must only contain one item with key 'content'.")
for k, v in settings.items():
if k == "content":
for key, val in settings.items():
if key == "content":
with open(filename, "w") as file:
file.write(v)
file.write(val)

@staticmethod
def file_move(filename, settings, directory):
def file_move(filename, settings, directory) -> None:
"""
Moves a file. {'_file_move': {'dest': 'new_file_name'}}.
Expand All @@ -246,12 +246,12 @@ def file_move(filename, settings, directory):
"""
if len(settings) != 1:
raise ValueError("Settings must only contain one item with key 'dest'.")
for k, v in settings.items():
if k == "dest":
shutil.move(os.path.join(directory, filename), os.path.join(directory, v))
for key, val in settings.items():
if key == "dest":
shutil.move(os.path.join(directory, filename), os.path.join(directory, val))

@staticmethod
def file_delete(filename, settings, directory):
def file_delete(filename, settings, directory) -> None:
"""
Deletes a file. {'_file_delete': {'mode': "actual"}}.
Expand All @@ -263,18 +263,18 @@ def file_delete(filename, settings, directory):
"""
if len(settings) != 1:
raise ValueError("Settings must only contain one item with key 'mode'.")
for k, v in settings.items():
if k == "mode" and v == "actual":
for key, val in settings.items():
if key == "mode" and val == "actual":
try:
os.remove(os.path.join(directory, filename))
except OSError:
# Skip file not found error.
pass
elif k == "mode" and v == "simulated":
elif key == "mode" and val == "simulated":
print(f"Simulated removal of {filename}")

@staticmethod
def file_copy(filename, settings, directory):
def file_copy(filename, settings, directory) -> None:
"""
Copies a file. {'_file_copy': {'dest': 'new_file_name'}}.
Expand All @@ -283,12 +283,12 @@ def file_copy(filename, settings, directory):
settings (dict): Must be {"dest": path of new file}
directory (str): Directory to copy file to/from
"""
for k, v in settings.items():
if k.startswith("dest"):
shutil.copyfile(os.path.join(directory, filename), os.path.join(directory, v))
for key, val in settings.items():
if key.startswith("dest"):
shutil.copyfile(os.path.join(directory, filename), os.path.join(directory, val))

@staticmethod
def file_modify(filename, settings, directory):
def file_modify(filename, settings, directory) -> None:
"""
Modifies file access.
Expand All @@ -297,8 +297,9 @@ def file_modify(filename, settings, directory):
settings (dict): Can be "mode" or "owners"
directory (str): Directory to modify file in
"""
for k, v in settings.items():
if k == "mode":
os.chmod(os.path.join(directory, filename), v)
if k == "owners":
os.chown(os.path.join(directory, filename), v)
for key, val in settings.items():
if key == "mode":
os.chmod(os.path.join(directory, filename), val)
if key == "owners":
# TODO fix this mypy error, missing 3rd positional argument to chown
os.chown(os.path.join(directory, filename), val) # type: ignore[call-arg]
6 changes: 4 additions & 2 deletions custodian/ansible/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Modder:
'Universe'
"""

def __init__(self, actions=None, strict=True, directory="./"):
def __init__(self, actions=None, strict=True, directory="./") -> None:
"""Initialize a Modder from a list of supported actions.
Args:
Expand All @@ -41,6 +41,8 @@ def __init__(self, actions=None, strict=True, directory="./"):
mode, unsupported actions are simply ignored without any
errors raised. In strict mode, if an unsupported action is
supplied, a ValueError is raised. Defaults to True.
directory (str): The directory containing the files to be modified.
Defaults to "./".
"""
self.supported_actions = {}
actions = actions if actions is not None else [DictActions]
Expand All @@ -51,7 +53,7 @@ def __init__(self, actions=None, strict=True, directory="./"):
self.strict = strict
self.directory = directory

def modify(self, modification, obj):
def modify(self, modification, obj) -> None:
"""
Note that modify makes actual in-place modifications. It does not
return a copy.
Expand Down
2 changes: 1 addition & 1 deletion custodian/cli/converge_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def get_runs(args):
)


def do_run(args):
def do_run(args) -> None:
"""Perform the run."""
handlers = [
VaspErrorHandler(),
Expand Down
4 changes: 2 additions & 2 deletions custodian/cli/converge_kpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def get_runs(vasp_command, target=1e-3, max_steps=10, mode="linear"):
)


def do_run(args):
def do_run(args) -> None:
"""Perform the run."""
handlers = [VaspErrorHandler(), UnconvergedErrorHandler()]
c = Custodian(
Expand All @@ -65,7 +65,7 @@ def do_run(args):
c.run()


def main():
def main() -> None:
"""Main method."""
import argparse

Expand Down
Loading

0 comments on commit 4270f3f

Please sign in to comment.