Files
openfe/openfecli/parameters/utils.py
David W.H. Swenson 41068e0185 CLI for AtomMapping (#57)
* Initial skeleton for the CLI

Currently requires the OPS CLI to be installed as well; next steps:

1. Add parameter core classes to infrastructure
2. Fully separate infrastructure into its own package

* switch to using plugcli

* tests for CLI

* helps if you add the tests...

* pep8 and deps cleanup

* add test_plugins

* Start of CLI atommapping report

* Add tests for parameters

* Almost-working atommapping command

* add hack to work-around lomap issue

* fix test

* pep8; docstrings; add header comments

* Add tests for commands/atommapping

* docstrings

* add init to command to stop circular import error

* remove init and it still works?

Co-authored-by: richard <richard@nextmovesoftware.com>
2022-02-23 16:43:01 +00:00

31 lines
872 B
Python

# This code is part of OpenFE and is licensed under the MIT license.
# For details, see https://github.com/OpenFreeEnergy/openfe
from plugcli.params import NOT_PARSED
from openfecli.utils import import_thing
def import_parameter(import_str: str):
"""Return object from a qualname, or NOT_PARSED if not valid.
This is used specifically for parameter instantiation strategies based
on importing an object given by the user on the command line. If the
user input cannot interpreted as a qualname, then NOT_PARSED is
returned.
Parameters
----------
import_str : str
the qualname
Returns
-------
Any :
the desired object or NOT_PARSED if an error was encountered.
"""
try:
result = import_thing(import_str)
except (ImportError, AttributeError):
result = NOT_PARSED
return result