Name | ipython-autoimport JSON |
Version |
0.5
JSON |
| download |
home_page | None |
Summary | Automagically import missing modules in IPython. |
upload_time | 2024-08-20 09:15:34 |
maintainer | None |
docs_url | None |
author | Antony Lee |
requires_python | >=3.7 |
license | zlib |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
ipython-autoimport
==================
| |GitHub| |PyPI| |Build|
.. |GitHub|
image:: https://img.shields.io/badge/github-anntzer%2Fdefopt-brightgreen
:target: https://github.com/anntzer/ipython-autoimport
.. |PyPI|
image:: https://img.shields.io/pypi/v/ipython-autoimport.svg?color=brightgreen
:target: https://pypi.python.org/pypi/ipython-autoimport
.. |Build|
image:: https://img.shields.io/github/actions/workflow/status/anntzer/ipython-autoimport/build.yml?branch=main
:target: https://github.com/anntzer/ipython-autoimport/actions
Automagically import missing modules in IPython: instead of ::
In [1]: plt.plot([1, 2], [3, 4])
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-1-994ba2bf13c0> in <module>()
----> 1 plt.plot([1, 2], [3, 4])
NameError: name 'plt' is not defined
In [2]: from matplotlib import pyplot as plt
In [3]: plt.plot([1, 2], [3, 4])
Out[3]: [<matplotlib.lines.Line2D at 0x7f73f0179198>]
do what I mean::
In [1]: plt.plot([1, 2], [3, 4])
Autoimport: from matplotlib import pyplot as plt
Out[1]: [<matplotlib.lines.Line2D at 0x7f7e253552b0>]
Inspired from @OrangeFlash81's `version
<https://github.com/OrangeFlash81/ipython-auto-import>`_, with many
improvements:
- Does not rely on re-execution, but instead hooks the user namespace; thus,
safe even in the presence of side effects, and works for tab completion and
magics too.
- Learns your preferred aliases from the history -- ``plt`` is not hardcoded to
alias ``matplotlib.pyplot``, just found because you previously imported
``pyplot`` under this alias.
- Suppresses irrelevant chained tracebacks.
- Auto-imports submodules.
- ``pip``-installable.
To see auto imports from the current session: ``%autoimport -l``
To clear the cache for a symbol with multiple possible imports: ``%autoimport -c SYMBOL``
Installation
------------
As usual, install using pip:
.. code-block:: sh
$ pip install ipython-autoimport # from PyPI
$ pip install git+https://github.com/anntzer/ipython-autoimport # from Github
Then, append the output of ``python -m ipython_autoimport`` to the
``ipython_config.py`` file in the directory printed by ``ipython profile
locate`` (typically ``~/.ipython/profile_default/``). If you don't have such a
file at all, first create it with ``ipython profile create``.
When using Spyder, the above registration method will not work; instead, add
``%load_ext ipython_autoimport`` to the
``Preferences → IPython console → Startup → Run code`` option.
Note that upon loading, ``ipython_autoimport`` will register its submodule
auto-importer to IPython's "limited evalutation" completer policy (on IPython
versions that support it).
Run tests with ``pytest``.
Limitations
-----------
Constructs such as ::
class C:
auto_imported_value
will not work, because they are run using the class locals (rather than the
patched locals); patching globals would not work because ``LOAD_NAME`` queries
globals using ``PyDict_GetItem`` exactly (note that it queries locals using
``PyObject_GetItem``; also, ``LOAD_GLOBALS`` queries *both* globals and
builtins using ``PyObject_GetItem`` so we could possibly get away with patching
the builtins dict instead, but that seems a bit too invasive...).
When using Jedi autocompletion (the default if Jedi is installed as of IPython
7.2), trying to tab-complete not-yet-imported global names to trigger an import
failure, because Jedi purposefully converts the global dict to a namespace
object and looks up attributes using ``getattr_static``. Jedi can be disabled
by adding ``c.Completer.use_jedi = False`` to the ``ipython_config.py`` file.
Changelog
---------
v0.5
~~~~
- Avoid erroring when exiting IPython≥8.15.
Raw data
{
"_id": null,
"home_page": null,
"name": "ipython-autoimport",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": null,
"author": "Antony Lee",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/b7/c6/0f2930e198cb67016227cb92be66e9ea888cfba5f13451ead14b26c7e376/ipython_autoimport-0.5.tar.gz",
"platform": null,
"description": "ipython-autoimport\n==================\n\n| |GitHub| |PyPI| |Build|\n\n.. |GitHub|\n image:: https://img.shields.io/badge/github-anntzer%2Fdefopt-brightgreen\n :target: https://github.com/anntzer/ipython-autoimport\n.. |PyPI|\n image:: https://img.shields.io/pypi/v/ipython-autoimport.svg?color=brightgreen\n :target: https://pypi.python.org/pypi/ipython-autoimport\n.. |Build|\n image:: https://img.shields.io/github/actions/workflow/status/anntzer/ipython-autoimport/build.yml?branch=main\n :target: https://github.com/anntzer/ipython-autoimport/actions\n\nAutomagically import missing modules in IPython: instead of ::\n\n In [1]: plt.plot([1, 2], [3, 4])\n ---------------------------------------------------------------------------\n NameError Traceback (most recent call last)\n <ipython-input-1-994ba2bf13c0> in <module>()\n ----> 1 plt.plot([1, 2], [3, 4])\n\n NameError: name 'plt' is not defined\n\n In [2]: from matplotlib import pyplot as plt\n\n In [3]: plt.plot([1, 2], [3, 4])\n Out[3]: [<matplotlib.lines.Line2D at 0x7f73f0179198>]\n\ndo what I mean::\n\n In [1]: plt.plot([1, 2], [3, 4])\n Autoimport: from matplotlib import pyplot as plt\n Out[1]: [<matplotlib.lines.Line2D at 0x7f7e253552b0>]\n\nInspired from @OrangeFlash81's `version\n<https://github.com/OrangeFlash81/ipython-auto-import>`_, with many\nimprovements:\n\n- Does not rely on re-execution, but instead hooks the user namespace; thus,\n safe even in the presence of side effects, and works for tab completion and\n magics too.\n- Learns your preferred aliases from the history -- ``plt`` is not hardcoded to\n alias ``matplotlib.pyplot``, just found because you previously imported\n ``pyplot`` under this alias.\n- Suppresses irrelevant chained tracebacks.\n- Auto-imports submodules.\n- ``pip``-installable.\n\nTo see auto imports from the current session: ``%autoimport -l``\n\nTo clear the cache for a symbol with multiple possible imports: ``%autoimport -c SYMBOL``\n\nInstallation\n------------\n\nAs usual, install using pip:\n\n.. code-block:: sh\n\n $ pip install ipython-autoimport # from PyPI\n $ pip install git+https://github.com/anntzer/ipython-autoimport # from Github\n\nThen, append the output of ``python -m ipython_autoimport`` to the\n``ipython_config.py`` file in the directory printed by ``ipython profile\nlocate`` (typically ``~/.ipython/profile_default/``). If you don't have such a\nfile at all, first create it with ``ipython profile create``.\n\nWhen using Spyder, the above registration method will not work; instead, add\n``%load_ext ipython_autoimport`` to the\n``Preferences \u2192 IPython console \u2192 Startup \u2192 Run code`` option.\n\nNote that upon loading, ``ipython_autoimport`` will register its submodule\nauto-importer to IPython's \"limited evalutation\" completer policy (on IPython\nversions that support it).\n\nRun tests with ``pytest``.\n\nLimitations\n-----------\n\nConstructs such as ::\n\n class C:\n auto_imported_value\n\nwill not work, because they are run using the class locals (rather than the\npatched locals); patching globals would not work because ``LOAD_NAME`` queries\nglobals using ``PyDict_GetItem`` exactly (note that it queries locals using\n``PyObject_GetItem``; also, ``LOAD_GLOBALS`` queries *both* globals and\nbuiltins using ``PyObject_GetItem`` so we could possibly get away with patching\nthe builtins dict instead, but that seems a bit too invasive...).\n\nWhen using Jedi autocompletion (the default if Jedi is installed as of IPython\n7.2), trying to tab-complete not-yet-imported global names to trigger an import\nfailure, because Jedi purposefully converts the global dict to a namespace\nobject and looks up attributes using ``getattr_static``. Jedi can be disabled\nby adding ``c.Completer.use_jedi = False`` to the ``ipython_config.py`` file.\n\nChangelog\n---------\n\nv0.5\n~~~~\n- Avoid erroring when exiting IPython\u22658.15.\n",
"bugtrack_url": null,
"license": "zlib",
"summary": "Automagically import missing modules in IPython.",
"version": "0.5",
"project_urls": {
"Repository": "https://github.com/anntzer/ipython-autoimport"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f0b56af9634b96ec72d0863afa1410841e0f6c1aabdfff2f46e0574bbbce2bb7",
"md5": "b918828981e800856a5e0ad1f25b7f83",
"sha256": "701b41483a85ecf55fb572d4d677f96c80c34f70ae07d18e4f7f26480d52aea0"
},
"downloads": -1,
"filename": "ipython_autoimport-0.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b918828981e800856a5e0ad1f25b7f83",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 7108,
"upload_time": "2024-08-20T09:15:33",
"upload_time_iso_8601": "2024-08-20T09:15:33.043833Z",
"url": "https://files.pythonhosted.org/packages/f0/b5/6af9634b96ec72d0863afa1410841e0f6c1aabdfff2f46e0574bbbce2bb7/ipython_autoimport-0.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "b7c60f2930e198cb67016227cb92be66e9ea888cfba5f13451ead14b26c7e376",
"md5": "19511869b587f665dee0cd9cc351d2d6",
"sha256": "9499ed45b62e047f02e9542d04ec70101b5ef310a22ce310307c1d065fa4be65"
},
"downloads": -1,
"filename": "ipython_autoimport-0.5.tar.gz",
"has_sig": false,
"md5_digest": "19511869b587f665dee0cd9cc351d2d6",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 9038,
"upload_time": "2024-08-20T09:15:34",
"upload_time_iso_8601": "2024-08-20T09:15:34.394246Z",
"url": "https://files.pythonhosted.org/packages/b7/c6/0f2930e198cb67016227cb92be66e9ea888cfba5f13451ead14b26c7e376/ipython_autoimport-0.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-20 09:15:34",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "anntzer",
"github_project": "ipython-autoimport",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "ipython-autoimport"
}