-
Notifications
You must be signed in to change notification settings - Fork 41
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
Enable lazy imports by the CLI & clear __init__.py files #56
Conversation
Enables manubot CLI to be called without running these files and triggering the imports
I'm unsure which option is better. The Is there anyone in the else in the greenelab we could ping to ask about these organizational questions? |
Maybe @Miserlou or @kurtwheeler has some wisdom here. |
The stuff currently in |
I don't think you could solve this through organizational changes. While
and then set IS_SCRIPT to true from your management commands. I think this is an uglier solution than |
Creates slightly more aesthetic import statements such as `import manubot.cite.util` rather than `import manubot.cite.cite`.
Submodules are now lazily imported, when using the manubot CLI.
Okay, thanks @Miserlou and @kurtwheeler for weighing in. Both comments were helpful:
|
@agitter do you think we should restore anyimports to |
Enables lazy import of citation_retreiver functions.
Define __all__ in manubot.cite.__init__.py to silence flake8 warning as per https://stackoverflow.com/a/49266468/4651668.
61d402a
to
4f11fd9
Compare
In 4f11fd9, I exposed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Organizationally, these changes look good to me. I didn't test whether or not the lazy loading is working as expected. The design looks nice though.
I also find manubot.cite.util
preferable to manubot.cite.cite
.
Exposing citation_to_citeproc
and standardize_citation
should be sufficient for now. If we see other Manubot use cases emerge we can revisit that later.
I am pretty sure our test coverage should be sufficient here. |
Enables manubot CLI to be called without running these files and triggering the imports. #53 and #54 also aimed partially to do this but were incomplete.
How I noticed the issue was that when running
manubot --version
, I got the following output:Basically, when we did
from manubot.cite.cite_command import add_subparser_cite
, this was executingmanubot.cite.__init__.py
. Formanubot.process.__init__.py
, this was importing pandas and other heavy dependencies, which:This PR is one approach to fix this. However, it has the aesthetically unfortunate consequence of changing the API to now need to specify another submodule, e.g.
import manubot.cite.cite
. However, it will also allow importing single functions from saymanubot.cite.doi
without having to run the entire init.py file.An alternative solution would be to move
add_subparser_cite
andadd_subparser_process
tomanubot.command.py
and change the lineparser.set_defaults(function=cli_cite)
to use a string to specify the submodule/function, which would then be imported at runtime via importlib.@agitter what do you think