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

Delay warning of missing requirements in io.cif as a late as possible #1507

Closed
sphuber opened this issue Jun 23, 2019 · 2 comments
Closed

Delay warning of missing requirements in io.cif as a late as possible #1507

sphuber opened this issue Jun 23, 2019 · 2 comments

Comments

@sphuber
Copy link

sphuber commented Jun 23, 2019

Is your feature request related to a problem? Please describe.
Delay the printing of warnings as late as possible in io.cif.
Currently, just importing the module io.cif will print the warning if pybtex is not installed:

try:
    from pybtex.database import BibliographyData, Entry
except ImportError:
    warnings.warn("Please install optional dependency pybtex if you"
                  "want to extract references from CIF files.")
    BibliographyData, Entry = None, None

However, the only function requiring it is get_bibtex_string.

Describe the solution you'd like
Since these warnings are not easy to suppress and show up even when not applicable it would be better to just move this warning to within the get_bibtex_string itself. One can simply extend the message of the requires decorator

@shyuep
Copy link
Member

shyuep commented Jun 23, 2019

Thanks. I fixed this. But instead of a warning, I simply make it throw an exception. The idea is that if someone is calling get_bibtex_string, they must actually be interested in a result and a runtime error should ensue if pybtex is not installed.

@sphuber
Copy link
Author

sphuber commented Jun 23, 2019

Thanks for the very quick response and action @shyuep 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants