diff --git a/custodian/__init__.py b/custodian/__init__.py index d7d9e7ae..f55fec2d 100644 --- a/custodian/__init__.py +++ b/custodian/__init__.py @@ -1,6 +1,6 @@ __author__ = "Shyue Ping Ong, William Davidson Richards, Stephen Dacek, " \ "Xiaohui Qu" __date__ = "Jul 14 2014" -__version__ = "0.7.4" +__version__ = "0.7.5" from custodian import Custodian diff --git a/custodian/vasp/tests/test_handlers.py b/custodian/vasp/tests/test_handlers.py index 6b9e221e..06c4b46f 100644 --- a/custodian/vasp/tests/test_handlers.py +++ b/custodian/vasp/tests/test_handlers.py @@ -286,7 +286,6 @@ def tearDownClass(cls): class BadVasprunXMLHandlerTest(unittest.TestCase): - def test_check_and_correct(self): os.chdir(os.path.join(test_dir, "bad_vasprun")) h = BadVasprunXMLHandler() diff --git a/docs/_build/doctrees/custodian.ansible.doctree b/docs/_build/doctrees/custodian.ansible.doctree index 45ada509..6f6ad770 100644 Binary files a/docs/_build/doctrees/custodian.ansible.doctree and b/docs/_build/doctrees/custodian.ansible.doctree differ diff --git a/docs/_build/doctrees/custodian.nwchem.doctree b/docs/_build/doctrees/custodian.nwchem.doctree index 96c102ce..f9473b1e 100644 Binary files a/docs/_build/doctrees/custodian.nwchem.doctree and b/docs/_build/doctrees/custodian.nwchem.doctree differ diff --git a/docs/_build/doctrees/custodian.qchem.doctree b/docs/_build/doctrees/custodian.qchem.doctree index a4a83ab7..5d4c588d 100644 Binary files a/docs/_build/doctrees/custodian.qchem.doctree and b/docs/_build/doctrees/custodian.qchem.doctree differ diff --git a/docs/_build/doctrees/custodian.vasp.doctree b/docs/_build/doctrees/custodian.vasp.doctree index 4fab0965..84685285 100644 Binary files a/docs/_build/doctrees/custodian.vasp.doctree and b/docs/_build/doctrees/custodian.vasp.doctree differ diff --git a/docs/_build/doctrees/environment.pickle b/docs/_build/doctrees/environment.pickle index c9d12ace..3fe4d758 100644 Binary files a/docs/_build/doctrees/environment.pickle and b/docs/_build/doctrees/environment.pickle differ diff --git a/docs/_build/doctrees/index.doctree b/docs/_build/doctrees/index.doctree index 66c92d21..d8761cee 100644 Binary files a/docs/_build/doctrees/index.doctree and b/docs/_build/doctrees/index.doctree differ diff --git a/docs/_build/doctrees/modules.doctree b/docs/_build/doctrees/modules.doctree index 4f8f84d6..721ffc7a 100644 Binary files a/docs/_build/doctrees/modules.doctree and b/docs/_build/doctrees/modules.doctree differ diff --git a/docs/_build/html/.buildinfo b/docs/_build/html/.buildinfo index 71532920..685ed266 100644 --- a/docs/_build/html/.buildinfo +++ b/docs/_build/html/.buildinfo @@ -1,4 +1,4 @@ # Sphinx build info version 1 # This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. -config: ce604e9da68f63aa2c1f3752b4718248 +config: 027556057d184ab38babdd14d30b0a67 tags: 645f666f9bcd5a90fca523b33c5a78b7 diff --git a/docs/_build/html/_modules/custodian/ansible/actions.html b/docs/_build/html/_modules/custodian/ansible/actions.html index 62e1aa52..6e854fc2 100644 --- a/docs/_build/html/_modules/custodian/ansible/actions.html +++ b/docs/_build/html/_modules/custodian/ansible/actions.html @@ -6,7 +6,7 @@
-
+#!/usr/bin/env python
+
+"""
+This module implements a Modder class that performs modifications on objects
+using support actions.
+"""
+
+from __future__ import division
+
+__author__ = "Shyue Ping Ong"
+__copyright__ = "Copyright 2012, The Materials Project"
+__version__ = "0.1"
+__maintainer__ = "Shyue Ping Ong"
+__email__ = "ongsp@ucsd.edu"
+__date__ = "Jun 1, 2012"
+
+
+import re
+
+from custodian.ansible.actions import DictActions
+
+
+[docs]class Modder(object):
+ """
+ Class to modify a dict/file/any object using a mongo-like language.
+ Keywords are mostly adopted from mongo's syntax, but instead of $, an
+ underscore precedes action keywords. This is so that the modification can
+ be inserted into a mongo db easily.
+
+ Allowable actions are supplied as a list of classes as an argument. Refer
+ to the action classes on what the actions do. Action classes are in
+ pymatpro.ansible.actions.
+
+ Examples:
+ >>> modder = Modder()
+ >>> d = {"Hello": "World"}
+ >>> mod = {'_set': {'Hello':'Universe', 'Bye': 'World'}}
+ >>> modder.modify(mod, d)
+ >>> d['Bye']
+ 'World'
+ >>> d['Hello']
+ 'Universe'
+ """
+ def __init__(self, actions=None, strict=True):
+ """
+ Initializes a Modder from a list of supported actions.
+
+ Args:
+ actions ([Action]): A sequence of supported actions. See
+ :mod:`custodian.ansible.actions`. Default is None,
+ which means only DictActions are supported.
+ strict (bool): Indicating whether to use strict mode. In non-strict
+ 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.
+ """
+ self.supported_actions = {}
+ actions = actions if actions is not None else [DictActions]
+ for action in actions:
+ for i in dir(action):
+ if (not re.match('__\w+__', i)) and \
+ callable(getattr(action, i)):
+ self.supported_actions["_" + i] = getattr(action, i)
+ self.strict = strict
+
+[docs] def modify(self, modification, obj):
+ """
+ Note that modify makes actual in-place modifications. It does not
+ return a copy.
+
+ Args:
+ modification (dict): Modification must be {action_keyword :
+ settings}. E.g., {'_set': {'Hello':'Universe', 'Bye': 'World'}}
+ obj (dict/str/object): Object to modify depending on actions. For
+ example, for DictActions, obj will be a dict to be modified.
+ For FileActions, obj will be a string with a full pathname to a
+ file.
+ """
+ for action, settings in modification.items():
+ if action in self.supported_actions:
+ self.supported_actions[action].__call__(obj, settings)
+ elif self.strict:
+ raise ValueError("{} is not a supported action!"
+ .format(action))
+
+[docs] def modify_object(self, modification, obj):
+ """
+ Modify an object that supports pymatgen's to_dict and from_dict API.
+
+ Args:
+ modification (dict): Modification must be {action_keyword :
+ settings}. E.g., {'_set': {'Hello':'Universe', 'Bye': 'World'}}
+ obj (object): Object to modify
+ """
+ d = obj.to_dict
+ self.modify(modification, d)
+ return obj.from_dict(d)
+
+
+if __name__ == "__main__":
+ import doctest
+ doctest.testmod()
+