mirror of
https://github.com/OpenFreeEnergy/openfe.git
synced 2026-06-04 22:34:24 +08:00
30 lines
871 B
Python
30 lines
871 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 |