-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Remove IPython
dependency from fire.Fire
or improve load times some other way
#7
Comments
I agree that this is an important thing to improve, and it deserves some discussion first. As you point out, IPython only used in two places:
The first course of action I'm leaning toward is to lazily import IPython in the two places it's used. If we do this then the lazy import (and the corresponding 0.5 second delay) will only trigger 1) when --interactive mode is used, and 2) when generating usage strings. We'll need to add the appropriate annotations to keep the linter happy since we'll be violating some PEP by lazy importing. The second related thing I think we should do is make IPython an optional dependency for interact.py. If the user doesn't have IPython, then we should fall back to using Thirdly, it would be good to remove inspectutils.py's dependency on IPython altogether. As noted above, we have two options for doing this (rewrite the info function or get permission from IPython to just take it). Once all this is done, we could remove IPython from setup.py altogether or list it as an optional suggested dependency, if such a thing exists. Thoughts? |
My vote is for optional usage of ipython as a subpackage, like As for the borrowing code from other IPython, that's also a good idea (maybe later it can become a share inspection of package) |
Adding IPython devs to ask for their take on it . |
We've made some changes in IPython recently that have slowed down import. We are looking into ways that we can address that. I think it's definitely a good idea to only import IPython if it's actually going to be invoked, rather than unconditionally. I think lazy imports are generally a good idea if you have a fair amount of optional functionality. As for the dependency, if a minority of users actually use it, making it an optional dependency (or no dependency at all) makes sense to me. You can always have the interactive mode do something like: try:
import IPython
except ImportError:
raise ImportError("IPython is required for interactive mode, `pip install ipython` to get it...") |
Thanks for chiming in.
The one piece that remains is our use of |
If copying it out is what you want, that's totally fine under IPython's BSD license. I think it's a nontrivial bit of code, though. |
Part 1 (lazy imports of IPython) is done w/ 3db47f8. |
https://github.com/google/python-fire/tree/z2017-05-21-ipython-optional (e.g. 3950004) would complete this ticket, fully making IPython an optional dependency.
|
Done. (on the z2017-05-21-ipython-optional branch)
Since we're moving this info to only show when the --verbose flag is present (#77), it's not critical that we have perfect parity with IPython's oinspect.info function. We can add in the edge cases in follow up changes. We do want to make sure we do a good job of getting docstrings though, since those will show up even outside of --verbose mode. |
Summary:
|
Currently this takes my machine 0.1 seconds to complete:
This used to take 1.78 seconds (fire-0.1.0), and now takes 0.51 seconds (fire-0.1.1).
Thanks for the improvement folks. Edit - I guess that's still not as fast as it should be. I'll wait for this recent commit to land. |
Here are the times that I see: Python 2, print: 0.022s (1.253s from cold start) Python 2, fire-0.1.0: 0.360s I would sometimes get the "cold start" times just after switching virtualenvs or after creating the test file. Rerunning the program a few times would start giving me consistent times, which I've reported above. |
import IPython
takes about 0.5 seconds on my machine to import and is the longest part of running simplefire
scripts at the moment. Launching a python script and printing something takes 0.15 seconds so the total withimport fire
becomes about 0.65 seconds.It's only used in
_EmbedIPython
andinspectutils.py
so maybe it can be optional for command line apps and the inspection part ported over (or placed in a different smaller package)? Would such a pull request be useful?The text was updated successfully, but these errors were encountered: