Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ToolkitRegistry misbehaves in an edge case if OpenEye installed but unlicensed #1435

Closed
mattwthompson opened this issue Oct 19, 2022 · 0 comments
Assignees
Labels

Comments

@mattwthompson
Copy link
Member

Describe the bug
If a user has OpenEye Toolkits installed but not licensed, some missed logic in #1426 allows OpenEyeToolkitWrapper to be registered as an un-instantiated class, resulting in all sorts of weird things.

To Reproduce

(openff-dev) [openff-toolkit] git checkout 0.11.2                                          13:23:14  ☁  1e7fa6ca ☀
HEAD is now at 1e7fa6ca Finalize 0.11.2 release notes (#1433)
(openff-dev) [openff-toolkit] conda list | grep openeye                                    13:23:16  ☁  1e7fa6ca ☀
openeye-toolkits          2022.1.1                py310_0    openeye
(openff-dev) [openff-toolkit] python                                                       13:23:21  ☁  1e7fa6ca ☀
Python 3.10.6 | packaged by conda-forge | (main, Aug 22 2022, 20:43:44) [Clang 13.0.1 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from openeye import oechem
>>> oechem.OEChemIsLicensed()
LICENSE: Could not open license file specified by OE_LICENSE environment variable "/Users/mattthompson/.oe_license.txt"
LICENSE: Could not open license file "oe_license.txt" in local directory
LICENSE: N.B. OE_DIR environment variable is not set
LICENSE: No product keys!
False
>>> from openff.toolkit.utils import *
LICENSE: No product keys!
LICENSE: No product keys!
LICENSE: No product keys!
LICENSE: No product keys!
The OpenEye Toolkits are found to be installed but not licensed and therefore will not be used.
The OpenEye Toolkits require a (free for academics) license, see https://docs.eyesopen.com/toolkits/python/quickstart-python/license.html
>>> GLOBAL_TOOLKIT_REGISTRY.registered_toolkits
[<class 'openff.toolkit.utils.openeye_wrapper.OpenEyeToolkitWrapper'>, ToolkitWrapper around The RDKit version 2022.03.5, ToolkitWrapper around AmberTools version 22.0, ToolkitWrapper around Built-in Toolkit version None]

Output

This gets weird i.e. the __repr__ will make IPython/Jupyter unhappy:

In [1]: from openff.toolkit.utils import *
LICENSE: Could not open license file specified by OE_LICENSE environment variable "/Users/mattthompson/.oe_license.txt"
LICENSE: Could not open license file "oe_license.txt" in local directory
LICENSE: N.B. OE_DIR environment variable is not set
LICENSE: No product keys!
LICENSE: No product keys!
LICENSE: No product keys!
LICENSE: No product keys!
The OpenEye Toolkits are found to be installed but not licensed and therefore will not be used.
The OpenEye Toolkits require a (free for academics) license, see https://docs.eyesopen.com/toolkits/python/quickstart-python/license.html

In [2]: GLOBAL_TOOLKIT_REGISTRY
Out[2]: ---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
File ~/mambaforge/envs/openff-dev/lib/python3.10/site-packages/IPython/core/formatters.py:707, in PlainTextFormatter.__call__(self, obj)
    700 stream = StringIO()
    701 printer = pretty.RepresentationPrinter(stream, self.verbose,
    702     self.max_width, self.newline,
    703     max_seq_length=self.max_seq_length,
    704     singleton_pprinters=self.singleton_printers,
    705     type_pprinters=self.type_printers,
    706     deferred_pprinters=self.deferred_printers)
--> 707 printer.pretty(obj)
    708 printer.flush()
    709 return stream.getvalue()

File ~/mambaforge/envs/openff-dev/lib/python3.10/site-packages/IPython/lib/pretty.py:410, in RepresentationPrinter.pretty(self, obj)
    407                         return meth(obj, self, cycle)
    408                 if cls is not object \
    409                         and callable(cls.__dict__.get('__repr__')):
--> 410                     return _repr_pprint(obj, self, cycle)
    412     return _default_pprint(obj, self, cycle)
    413 finally:

File ~/mambaforge/envs/openff-dev/lib/python3.10/site-packages/IPython/lib/pretty.py:778, in _repr_pprint(obj, p, cycle)
    776 """A pprint that just redirects to the normal repr function."""
    777 # Find newlines and replace them with p.break_()
--> 778 output = repr(obj)
    779 lines = output.splitlines()
    780 with p.group():

File ~/software/openff-toolkit/openff/toolkit/utils/toolkit_registry.py:372, in ToolkitRegistry.__repr__(self)
    371 def __repr__(self):
--> 372     return f"<ToolkitRegistry containing {', '.join([tk.toolkit_name for tk in self._toolkits])}>"

TypeError: sequence item 0: expected str instance, property found

Additional context

This is my doing and I take full responsibility for it. However, I think it's a weird case and should not be arrived at easily; conda-forge packages don't allow OpenEye Toolkits to be pulled down and users are unlikely to accidentally install them. This is not an issue if they're properly licensed. We excluded this case from the test matrix for a reason.

@mattwthompson mattwthompson self-assigned this Oct 19, 2022
mattwthompson added a commit that referenced this issue Oct 19, 2022
@mattwthompson mattwthompson changed the title ToolkitRegistry misbehaves in and edge case if OpenEye installed but unlicensed ToolkitRegistry misbehaves in an edge case if OpenEye installed but unlicensed Oct 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant