pyflyby


Namepyflyby JSON
Version 1.9.3 PyPI version JSON
download
home_pagehttps://pypi.org/project/pyflyby/
Summarypyflyby - Python development productivity tools, in particular automatic import management
upload_time2024-04-08 05:12:16
maintainerNone
docs_urlNone
authorKarl Chen
requires_python<4,>3.6
licenseMIT
keywords pyflyby py autopython autoipython productivity automatic imports autoimporter tidy-imports
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            #########
 Pyflyby
#########

.. image:: https://badge.fury.io/py/pyflyby.svg
   :target: https://pypi.org/project/pyflyby/

.. image:: https://travis-ci.org/deshaw/pyflyby.png?branch=master
   :target: https://travis-ci.org/deshaw/pyflyby

Pyflyby is a set of Python programming productivity tools for Python 3.7+.

For command-line interaction:
  * ``py``: command-line multitool

For IPython interaction:
  * ``autoimporter``: automatically imports symbols when needed.

For editing python source code:
  * ``tidy-imports``: adds missing 'import's, removes unused 'import's,
    and also reformats import blocks.
  * ``find-import``: prints to stdout how to import a particular symbol.
  * ``reformat-imports``: reformats ``import`` blocks
  * ``collect-imports``: prints out all the imports in a given set of files.
  * ``collect-exports``: prints out definitions in a given set of modules,
    in the form of import statements.
  * ``transform-imports``: renames imported modules/functions.

Installation
============

.. code:: bash

    $ pip install pyflyby

This creates an alias for your `ipython` named `py` which runs the `pyflyby` plug internally.
 `pyflyby` has a dependency on `ipython`, if it isn't already installed do install it with:

.. code:: bash

    $ pip install ipython


Quick start: Autoimporter + IPython
===================================

.. code:: bash

   $ py
   In [1]: re.search("[a-z]+", "....hello...").group(0)
   [PYFLYBY] import re
   Out[1]: 'hello'

   In [2]: chisqprob(arange(5), 2)
   [PYFLYBY] from numpy import arange
   [PYFLYBY] from scipy.stats import chisqprob
   Out[2]: [ 1.      0.6065  0.3679  0.2231  0.1353]

To load pyflyby into an existing IPython session as a 1-off:

.. code:: bash

   $ ipython
   In [1]: %load_ext pyflyby

To configure IPython/Jupyter Notebook to load pyflyby automatically:

.. code:: bash

   $ py pyflyby.install_in_ipython_config_file

or

.. code:: bash

   $ echo 'c.InteractiveShellApp.extensions.append("pyflyby")' \
     >> ~/.ipython/profile_default/ipython_config.py

   $ ipython
   In [1]: b64decode('aGVsbG8=')
   [PYFLYBY] from base64 import b64decode
   Out[1]: 'hello'


Quick start: ``py`` command-line multi-tool
===========================================

.. code:: bash

  $ py b64decode aGVsbG8=
  [PYFLYBY] from base64 import b64decode
  [PYFLYBY] b64decode('aGVsbG8=', altchars=None)
  'hello'

  $ py log2 sys.maxint
  [PYFLYBY] from numpy import log2
  [PYFLYBY] import sys
  [PYFLYBY] log2(9223372036854775807)
  63.0

  $ py 'plot(cos(arange(30)))'
  [PYFLYBY] from numpy import arange
  [PYFLYBY] from numpy import cos
  [PYFLYBY] from matplotlib.pyplot import plot
  [PYFLYBY] plot(cos(arange(30)))
  <plot>

  $ py 38497631 / 13951446
  2.7594007818257693

  $ py foo.py

Quick start: ``tidy-imports``
=============================

To use ``tidy-imports``, just specify the filename(s) to tidy.

For example:

.. code::

   $ echo 're.search("[a-z]+", "....hello..."), chisqprob(arange(5), 2)' > foo.py

   $ tidy-imports foo.py
   --- /tmp/foo.py
   +++ /tmp/foo.py
   @@ -1 +1,9 @@
   +from __future__ import absolute_import, division, with_statement
   +
   +from   numpy                    import arange
   +from   scipy.stats              import chisqprob
   +import re
   +
    re.search("[a-z]+", "....hello..."), chisqprob(arange(5), 2)

   Replace /tmp/foo.py? [y/N]


Quick start: import libraries
=============================

Create a file named .pyflyby with lines such as

.. code:: python

   from mypackage.mymodule import MyClass, my_function
   import anotherpackage.anothermodule

You can put this file in your home directory or in the same directory as your
``*.py`` files.


Details: automatic imports
==========================

AUTOMATIC IMPORTS - never type "import" again!

This module allows your "known imports" to work automatically in your IPython
interactive session without having to type the 'import' statements (and also
without having to slow down your Python startup with imports you only use
occasionally).

Example::

  In [1]: re.search("[a-z]+", "....hello...").group(0)
  [PYFLYBY] import re
  Out[1]: 'hello'

  In [2]: chisqprob(arange(5), 2)
  [PYFLYBY] from numpy import arange
  [PYFLYBY] from scipy.stats import chisqprob
  Out[2]: [ 1.      0.6065  0.3679  0.2231  0.1353]

  In [3]: np.sin(arandom(5))
  [PYFLYBY] from numpy.random import random as arandom
  [PYFLYBY] import numpy as np
  Out[3]: [ 0.0282  0.0603  0.4653  0.8371  0.3347]

  In [4]: isinstance(42, Number)
  [PYFLYBY] from numbers import Number
  Out[4]: True


It just works
-------------

Tab completion works, even on modules that are not yet imported.  In the
following example, notice that numpy is imported when we need to know its
members, and only then::

  $ ipython
  In [1]: nump<TAB>
  In [1]: numpy
  In [1]: numpy.arang<TAB>
  [PYFLYBY] import numpy
  In [1]: numpy.arange


The IPython "?" magic help (pinfo/pinfo2) automatically imports symbols first
if necessary::

  $ ipython
  In [1]: arange?
  [PYFLYBY] from numpy import arange
  ... Docstring: arange([start,] stop[, step,], dtype=None) ...

Other IPython magic commands work as well::

  $ ipython
  In [1]: %timeit np.cos(pi)
  [PYFLYBY] import numpy as np
  [PYFLYBY] from numpy import pi
  100000 loops, best of 3: 2.51 us per loop

  $ echo 'print arange(4)' > foo.py
  $ ipython
  In [1]: %run foo.py
  [PYFLYBY] from numpy import arange
  [0 1 2 3]


Implementation details
----------------------

The automatic importing happens at parse time, before code is executed.  The
namespace never contains entries for names that are not yet imported.

This method of importing at parse time contrasts with previous implementations
of automatic importing that use proxy objects.  Those implementations using
proxy objects don't work as well, because it is impossible to make proxy
objects behave perfectly.  For example, instance(x, T) will return the wrong
answer if either x or T is a proxy object.


Compatibility
-------------

Tested with:
  - Python 3.8, 3.9, 3.10
  - IPython 0.10, 0.11, 0.12, 0.13, 1.0, 1.2, 2.0, 2.1, 2.2, 2.3, 2.4, 3.0,
    3.1, 3.2, 4.0., 7.11 (latest)
  - IPython (text console), IPython Notebook, Spyder


Details: import libraries
=========================

Pyflyby uses "import libraries" that tell how to import a given symbol.

An import library file is simply a python source file containing 'import' (or
'from ... import ...') lines.  These can be generated automatically with
``collect-imports`` and ``collect-exports``.

Known imports
-------------

Find-imports, ``tidy-imports``, and autoimport consult the database of known
imports to figure out where to get an import.  For example, if the
imports database contains::

    from numpy import arange, NaN

then when you type the following in IPython::

    print(arange(10))

the autoimporter would automatically execute ``from numpy import arange``.

The database can be one file or multiple files.  This makes it easy to have
project-specific known_imports along with global and per-user defaults.

The ``PYFLYBY_PATH`` environment variable specifies which files to read.
This is a colon-separated list of filenames or directory names.  The default
is::

  PYFLYBY_PATH=/etc/pyflyby:~/.pyflyby:.../.pyflyby

If you set::

  PYFLYBY_PATH=/foo1/bar1:/foo2/bar2

then this replaces the default.

You can use a hyphen to include the default in the path.  If you set::

  PYFLYBY_PATH=/foo1/bar1:-:/foo2/bar2

then this reads ``/foo1/bar1``, then the default locations, then ``/foo2/bar2``.

In ``$PYFLYBY_PATH``, ``.../.pyflyby`` (with _three_ dots) means that all ancestor
directories are searched for a member named ".pyflyby".

For example, suppose the following files exist::

  /etc/pyflyby/stuff.py
  /u/quarl/.pyflyby/blah1.py
  /u/quarl/.pyflyby/more/blah2.py
  /proj/share/mypythonstuff/.pyflyby
  /proj/share/mypythonstuff/foo/bar/.pyflyby/baz.py
  /.pyflyby

Further, suppose:

  * ``/proj`` is on a separate file system from ``/``.
  * ``$HOME=/u/quarl``

Then ``tidy-imports /proj/share/mypythonstuff/foo/bar/quux/zot.py`` will by
default use the following::

  /etc/pyflyby/stuff.py
  /u/quarl/.pyflyby/blah1.py
  /u/quarl/.pyflyby/more/blah2.py
  /proj/share/mypythonstuff/foo/bar/.pyflyby/baz.py
  /proj/share/mypythonstuff/.pyflyby (a file)

.. note::

  * ``/.pyflyby`` is not included, because traversal stops at file system
    boundaries, and in this example, ``/proj`` is on a different file system than
    ``/``.
  * ``.pyflyby`` (in ``$HOME`` or near the target file) can be a file or a directory.
    If it is a directory, then it is recursively searched for ``*.py`` files.
  * The order usually doesn't matter, but if there are "forget" instructions
    (see below), then the order matters.  In the default ``$PYFLYBY_PATH``,
    .../.pyflyby is placed last so that per-directory configuration can
    override per-user configuration, which can override systemwide
    configuration.


Forgetting imports
------------------

Occasionally you may have reason to tell pyflyby to "forget" entries from the
database of known imports.

You can put the following in any file reachable from ``$PYFLYBY_PATH``::

  __forget_imports__ = ["from numpy import NaN"]

This is useful if you want to use a set of imports maintained by someone else
except for a few particular imports.

Entries in ``$PYFLYBY_PATH`` are processed left-to-right in the order specified,
so put the files containing these at the end of your ``$PYFLYBY_PATH``.  By
default, ``tidy-imports`` and friends process ``/etc/pyflyby``, then ``~/.pyflyby``,
then the per-directory ``.pyflyby``.


Mandatory imports
-----------------

Within a certain project you may have a policy to always include certain
imports.  For example, maybe you always want to do ``from __future__ import
division`` in all files.

You can put the following in any file reachable from ``$PYFLYBY_PATH``::

  __mandatory_imports__ = ["from __future__ import division"]

To undo mandatory imports inherited from other ``.pyflyby`` files, use
``__forget_imports__`` (see above).


Canonicalize imports
--------------------

Sometimes you want every run of ``tidy-imports`` to automatically rename an import
to a new name.

You can put the following in any file reachable from ``$PYFLYBY_PATH``::

  __canonical_imports__ = {"oldmodule.oldfunction": "newmodule.newfunction"}

This is equivalent to running::

  tidy-imports --transform=oldmodule.oldfunction=newmodule.newfunction


Soapbox: avoid "star" imports
=============================

When programming in Python, a good software engineering practice is to avoid
using ``from foopackage import *`` in production code.

This style is a maintenance nightmare:

  * It becomes difficult to figure out where various symbols
    (functions/classes/etc) come from.

  * It's hard to tell what gets shadowed by what.

  * When the package changes in trivial ways, your code will be affected.
    Consider the following example: Suppose ``foopackage.py`` contains ``import
    sys``, and ``myprogram.py`` contains ``from foopackage import *; if
    some_condition: sys.exit(0)``.  If ``foopackage.py`` changes so that ``import
    sys`` is removed, ``myprogram.py`` is now broken because it's missing ``import
    sys``.

To fix such code, you can run ``tidy-imports --replace-star-imports`` to
automatically replace star imports with the specific needed imports.

Per-Project configuration of tidy-imports
=========================================

You can configure Pyflyby on a per-repository basis by using the
`[tool.pyflyby]` section of `pyproject.toml` files. Pyflyby will look in current
working directory and all it's parent until it find a `pyproject.toml` file from
which it will load the defaults.


Most of the long command line flags default values can be configured in this
section. Simply use the long form option name by replacing dashes `-` by
underscore `_`. For long option that have the form `--xxx` and `--no-xxx`, you
can assign a boolean to `xxx`. For example::

    [tool.pyflyby]
    add_missing=true
    from_spaces=7
    remove_unused=false


Emacs support
=============

* To get a ``M-x tidy-imports`` command in GNU Emacs, add to your ``~/.emacs``::

    (load "/path/to/pyflyby/lib/emacs/pyflyby.el")


- Pyflyby.el doesn't yet work with XEmacs; patches welcome.


Authorship
==========

This plugin was contributed back to the community by the `D. E. Shaw group
<https://www.deshaw.com/>`_.

.. image:: https://www.deshaw.com/assets/logos/blue_logo_417x125.png
   :target: https://www.deshaw.com
   :height: 75 px

Pyflyby is written by Karl Chen <quarl@8166.clguba.z.quarl.org>

We love contributions! Before you can contribute, please sign and submit this
`Contributor License Agreement (CLA) <https://www.deshaw.com/oss/cla>`_.
This CLA is in place to protect all users of this project.

License
=======

Pyflyby is released under a very permissive license, the MIT/X11 license; see
LICENSE.txt.


Release
=======

1. Check version number in `lib/python/pyflyby/_version.py`, maybe increase it.
2. Commit and tag if necessary, and push tags/commits.
3. Optional: Set SOURCE_DATE_EPOCH for reproducible build::

    export SOURCE_DATE_EPOCH=$(git show -s --format=%ct HEAD)

4. Build the SDIST::

    python setup.py sdist

5. Optional Repack the Sdist to make sure the ZIP only contain SOURCE_DATE_EPOCH
   date using IPython tools::

    python ~/dev/ipython/tools/retar.py dist/pyflyby-1.7.8.tar.gz
    shasum -a 256 dist/*

6. Optional, redo 4 & 5 to verify checksum is unchanged.
7. Upload using twine::

    twine upload dist/*

8. Check/update https://github.com/conda-forge/pyflyby-feedstock for new pyflyby
   release on conda-forge



            

Raw data

            {
    "_id": null,
    "home_page": "https://pypi.org/project/pyflyby/",
    "name": "pyflyby",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4,>3.6",
    "maintainer_email": null,
    "keywords": "pyflyby py autopython autoipython productivity automatic imports autoimporter tidy-imports",
    "author": "Karl Chen",
    "author_email": "quarl@8166.clguba.z.quarl.org",
    "download_url": "https://files.pythonhosted.org/packages/a8/c1/6401868865f3e5daa8af24b8b308aa6ccb78167c5218a7ad5f3844a7ca8f/pyflyby-1.9.3.tar.gz",
    "platform": null,
    "description": "#########\n Pyflyby\n#########\n\n.. image:: https://badge.fury.io/py/pyflyby.svg\n   :target: https://pypi.org/project/pyflyby/\n\n.. image:: https://travis-ci.org/deshaw/pyflyby.png?branch=master\n   :target: https://travis-ci.org/deshaw/pyflyby\n\nPyflyby is a set of Python programming productivity tools for Python 3.7+.\n\nFor command-line interaction:\n  * ``py``: command-line multitool\n\nFor IPython interaction:\n  * ``autoimporter``: automatically imports symbols when needed.\n\nFor editing python source code:\n  * ``tidy-imports``: adds missing 'import's, removes unused 'import's,\n    and also reformats import blocks.\n  * ``find-import``: prints to stdout how to import a particular symbol.\n  * ``reformat-imports``: reformats ``import`` blocks\n  * ``collect-imports``: prints out all the imports in a given set of files.\n  * ``collect-exports``: prints out definitions in a given set of modules,\n    in the form of import statements.\n  * ``transform-imports``: renames imported modules/functions.\n\nInstallation\n============\n\n.. code:: bash\n\n    $ pip install pyflyby\n\nThis creates an alias for your `ipython` named `py` which runs the `pyflyby` plug internally.\n `pyflyby` has a dependency on `ipython`, if it isn't already installed do install it with:\n\n.. code:: bash\n\n    $ pip install ipython\n\n\nQuick start: Autoimporter + IPython\n===================================\n\n.. code:: bash\n\n   $ py\n   In [1]: re.search(\"[a-z]+\", \"....hello...\").group(0)\n   [PYFLYBY] import re\n   Out[1]: 'hello'\n\n   In [2]: chisqprob(arange(5), 2)\n   [PYFLYBY] from numpy import arange\n   [PYFLYBY] from scipy.stats import chisqprob\n   Out[2]: [ 1.      0.6065  0.3679  0.2231  0.1353]\n\nTo load pyflyby into an existing IPython session as a 1-off:\n\n.. code:: bash\n\n   $ ipython\n   In [1]: %load_ext pyflyby\n\nTo configure IPython/Jupyter Notebook to load pyflyby automatically:\n\n.. code:: bash\n\n   $ py pyflyby.install_in_ipython_config_file\n\nor\n\n.. code:: bash\n\n   $ echo 'c.InteractiveShellApp.extensions.append(\"pyflyby\")' \\\n     >> ~/.ipython/profile_default/ipython_config.py\n\n   $ ipython\n   In [1]: b64decode('aGVsbG8=')\n   [PYFLYBY] from base64 import b64decode\n   Out[1]: 'hello'\n\n\nQuick start: ``py`` command-line multi-tool\n===========================================\n\n.. code:: bash\n\n  $ py b64decode aGVsbG8=\n  [PYFLYBY] from base64 import b64decode\n  [PYFLYBY] b64decode('aGVsbG8=', altchars=None)\n  'hello'\n\n  $ py log2 sys.maxint\n  [PYFLYBY] from numpy import log2\n  [PYFLYBY] import sys\n  [PYFLYBY] log2(9223372036854775807)\n  63.0\n\n  $ py 'plot(cos(arange(30)))'\n  [PYFLYBY] from numpy import arange\n  [PYFLYBY] from numpy import cos\n  [PYFLYBY] from matplotlib.pyplot import plot\n  [PYFLYBY] plot(cos(arange(30)))\n  <plot>\n\n  $ py 38497631 / 13951446\n  2.7594007818257693\n\n  $ py foo.py\n\nQuick start: ``tidy-imports``\n=============================\n\nTo use ``tidy-imports``, just specify the filename(s) to tidy.\n\nFor example:\n\n.. code::\n\n   $ echo 're.search(\"[a-z]+\", \"....hello...\"), chisqprob(arange(5), 2)' > foo.py\n\n   $ tidy-imports foo.py\n   --- /tmp/foo.py\n   +++ /tmp/foo.py\n   @@ -1 +1,9 @@\n   +from __future__ import absolute_import, division, with_statement\n   +\n   +from   numpy                    import arange\n   +from   scipy.stats              import chisqprob\n   +import re\n   +\n    re.search(\"[a-z]+\", \"....hello...\"), chisqprob(arange(5), 2)\n\n   Replace /tmp/foo.py? [y/N]\n\n\nQuick start: import libraries\n=============================\n\nCreate a file named .pyflyby with lines such as\n\n.. code:: python\n\n   from mypackage.mymodule import MyClass, my_function\n   import anotherpackage.anothermodule\n\nYou can put this file in your home directory or in the same directory as your\n``*.py`` files.\n\n\nDetails: automatic imports\n==========================\n\nAUTOMATIC IMPORTS - never type \"import\" again!\n\nThis module allows your \"known imports\" to work automatically in your IPython\ninteractive session without having to type the 'import' statements (and also\nwithout having to slow down your Python startup with imports you only use\noccasionally).\n\nExample::\n\n  In [1]: re.search(\"[a-z]+\", \"....hello...\").group(0)\n  [PYFLYBY] import re\n  Out[1]: 'hello'\n\n  In [2]: chisqprob(arange(5), 2)\n  [PYFLYBY] from numpy import arange\n  [PYFLYBY] from scipy.stats import chisqprob\n  Out[2]: [ 1.      0.6065  0.3679  0.2231  0.1353]\n\n  In [3]: np.sin(arandom(5))\n  [PYFLYBY] from numpy.random import random as arandom\n  [PYFLYBY] import numpy as np\n  Out[3]: [ 0.0282  0.0603  0.4653  0.8371  0.3347]\n\n  In [4]: isinstance(42, Number)\n  [PYFLYBY] from numbers import Number\n  Out[4]: True\n\n\nIt just works\n-------------\n\nTab completion works, even on modules that are not yet imported.  In the\nfollowing example, notice that numpy is imported when we need to know its\nmembers, and only then::\n\n  $ ipython\n  In [1]: nump<TAB>\n  In [1]: numpy\n  In [1]: numpy.arang<TAB>\n  [PYFLYBY] import numpy\n  In [1]: numpy.arange\n\n\nThe IPython \"?\" magic help (pinfo/pinfo2) automatically imports symbols first\nif necessary::\n\n  $ ipython\n  In [1]: arange?\n  [PYFLYBY] from numpy import arange\n  ... Docstring: arange([start,] stop[, step,], dtype=None) ...\n\nOther IPython magic commands work as well::\n\n  $ ipython\n  In [1]: %timeit np.cos(pi)\n  [PYFLYBY] import numpy as np\n  [PYFLYBY] from numpy import pi\n  100000 loops, best of 3: 2.51 us per loop\n\n  $ echo 'print arange(4)' > foo.py\n  $ ipython\n  In [1]: %run foo.py\n  [PYFLYBY] from numpy import arange\n  [0 1 2 3]\n\n\nImplementation details\n----------------------\n\nThe automatic importing happens at parse time, before code is executed.  The\nnamespace never contains entries for names that are not yet imported.\n\nThis method of importing at parse time contrasts with previous implementations\nof automatic importing that use proxy objects.  Those implementations using\nproxy objects don't work as well, because it is impossible to make proxy\nobjects behave perfectly.  For example, instance(x, T) will return the wrong\nanswer if either x or T is a proxy object.\n\n\nCompatibility\n-------------\n\nTested with:\n  - Python 3.8, 3.9, 3.10\n  - IPython 0.10, 0.11, 0.12, 0.13, 1.0, 1.2, 2.0, 2.1, 2.2, 2.3, 2.4, 3.0,\n    3.1, 3.2, 4.0., 7.11 (latest)\n  - IPython (text console), IPython Notebook, Spyder\n\n\nDetails: import libraries\n=========================\n\nPyflyby uses \"import libraries\" that tell how to import a given symbol.\n\nAn import library file is simply a python source file containing 'import' (or\n'from ... import ...') lines.  These can be generated automatically with\n``collect-imports`` and ``collect-exports``.\n\nKnown imports\n-------------\n\nFind-imports, ``tidy-imports``, and autoimport consult the database of known\nimports to figure out where to get an import.  For example, if the\nimports database contains::\n\n    from numpy import arange, NaN\n\nthen when you type the following in IPython::\n\n    print(arange(10))\n\nthe autoimporter would automatically execute ``from numpy import arange``.\n\nThe database can be one file or multiple files.  This makes it easy to have\nproject-specific known_imports along with global and per-user defaults.\n\nThe ``PYFLYBY_PATH`` environment variable specifies which files to read.\nThis is a colon-separated list of filenames or directory names.  The default\nis::\n\n  PYFLYBY_PATH=/etc/pyflyby:~/.pyflyby:.../.pyflyby\n\nIf you set::\n\n  PYFLYBY_PATH=/foo1/bar1:/foo2/bar2\n\nthen this replaces the default.\n\nYou can use a hyphen to include the default in the path.  If you set::\n\n  PYFLYBY_PATH=/foo1/bar1:-:/foo2/bar2\n\nthen this reads ``/foo1/bar1``, then the default locations, then ``/foo2/bar2``.\n\nIn ``$PYFLYBY_PATH``, ``.../.pyflyby`` (with _three_ dots) means that all ancestor\ndirectories are searched for a member named \".pyflyby\".\n\nFor example, suppose the following files exist::\n\n  /etc/pyflyby/stuff.py\n  /u/quarl/.pyflyby/blah1.py\n  /u/quarl/.pyflyby/more/blah2.py\n  /proj/share/mypythonstuff/.pyflyby\n  /proj/share/mypythonstuff/foo/bar/.pyflyby/baz.py\n  /.pyflyby\n\nFurther, suppose:\n\n  * ``/proj`` is on a separate file system from ``/``.\n  * ``$HOME=/u/quarl``\n\nThen ``tidy-imports /proj/share/mypythonstuff/foo/bar/quux/zot.py`` will by\ndefault use the following::\n\n  /etc/pyflyby/stuff.py\n  /u/quarl/.pyflyby/blah1.py\n  /u/quarl/.pyflyby/more/blah2.py\n  /proj/share/mypythonstuff/foo/bar/.pyflyby/baz.py\n  /proj/share/mypythonstuff/.pyflyby (a file)\n\n.. note::\n\n  * ``/.pyflyby`` is not included, because traversal stops at file system\n    boundaries, and in this example, ``/proj`` is on a different file system than\n    ``/``.\n  * ``.pyflyby`` (in ``$HOME`` or near the target file) can be a file or a directory.\n    If it is a directory, then it is recursively searched for ``*.py`` files.\n  * The order usually doesn't matter, but if there are \"forget\" instructions\n    (see below), then the order matters.  In the default ``$PYFLYBY_PATH``,\n    .../.pyflyby is placed last so that per-directory configuration can\n    override per-user configuration, which can override systemwide\n    configuration.\n\n\nForgetting imports\n------------------\n\nOccasionally you may have reason to tell pyflyby to \"forget\" entries from the\ndatabase of known imports.\n\nYou can put the following in any file reachable from ``$PYFLYBY_PATH``::\n\n  __forget_imports__ = [\"from numpy import NaN\"]\n\nThis is useful if you want to use a set of imports maintained by someone else\nexcept for a few particular imports.\n\nEntries in ``$PYFLYBY_PATH`` are processed left-to-right in the order specified,\nso put the files containing these at the end of your ``$PYFLYBY_PATH``.  By\ndefault, ``tidy-imports`` and friends process ``/etc/pyflyby``, then ``~/.pyflyby``,\nthen the per-directory ``.pyflyby``.\n\n\nMandatory imports\n-----------------\n\nWithin a certain project you may have a policy to always include certain\nimports.  For example, maybe you always want to do ``from __future__ import\ndivision`` in all files.\n\nYou can put the following in any file reachable from ``$PYFLYBY_PATH``::\n\n  __mandatory_imports__ = [\"from __future__ import division\"]\n\nTo undo mandatory imports inherited from other ``.pyflyby`` files, use\n``__forget_imports__`` (see above).\n\n\nCanonicalize imports\n--------------------\n\nSometimes you want every run of ``tidy-imports`` to automatically rename an import\nto a new name.\n\nYou can put the following in any file reachable from ``$PYFLYBY_PATH``::\n\n  __canonical_imports__ = {\"oldmodule.oldfunction\": \"newmodule.newfunction\"}\n\nThis is equivalent to running::\n\n  tidy-imports --transform=oldmodule.oldfunction=newmodule.newfunction\n\n\nSoapbox: avoid \"star\" imports\n=============================\n\nWhen programming in Python, a good software engineering practice is to avoid\nusing ``from foopackage import *`` in production code.\n\nThis style is a maintenance nightmare:\n\n  * It becomes difficult to figure out where various symbols\n    (functions/classes/etc) come from.\n\n  * It's hard to tell what gets shadowed by what.\n\n  * When the package changes in trivial ways, your code will be affected.\n    Consider the following example: Suppose ``foopackage.py`` contains ``import\n    sys``, and ``myprogram.py`` contains ``from foopackage import *; if\n    some_condition: sys.exit(0)``.  If ``foopackage.py`` changes so that ``import\n    sys`` is removed, ``myprogram.py`` is now broken because it's missing ``import\n    sys``.\n\nTo fix such code, you can run ``tidy-imports --replace-star-imports`` to\nautomatically replace star imports with the specific needed imports.\n\nPer-Project configuration of tidy-imports\n=========================================\n\nYou can configure Pyflyby on a per-repository basis by using the\n`[tool.pyflyby]` section of `pyproject.toml` files. Pyflyby will look in current\nworking directory and all it's parent until it find a `pyproject.toml` file from\nwhich it will load the defaults.\n\n\nMost of the long command line flags default values can be configured in this\nsection. Simply use the long form option name by replacing dashes `-` by\nunderscore `_`. For long option that have the form `--xxx` and `--no-xxx`, you\ncan assign a boolean to `xxx`. For example::\n\n    [tool.pyflyby]\n    add_missing=true\n    from_spaces=7\n    remove_unused=false\n\n\nEmacs support\n=============\n\n* To get a ``M-x tidy-imports`` command in GNU Emacs, add to your ``~/.emacs``::\n\n    (load \"/path/to/pyflyby/lib/emacs/pyflyby.el\")\n\n\n- Pyflyby.el doesn't yet work with XEmacs; patches welcome.\n\n\nAuthorship\n==========\n\nThis plugin was contributed back to the community by the `D. E. Shaw group\n<https://www.deshaw.com/>`_.\n\n.. image:: https://www.deshaw.com/assets/logos/blue_logo_417x125.png\n   :target: https://www.deshaw.com\n   :height: 75 px\n\nPyflyby is written by Karl Chen <quarl@8166.clguba.z.quarl.org>\n\nWe love contributions! Before you can contribute, please sign and submit this\n`Contributor License Agreement (CLA) <https://www.deshaw.com/oss/cla>`_.\nThis CLA is in place to protect all users of this project.\n\nLicense\n=======\n\nPyflyby is released under a very permissive license, the MIT/X11 license; see\nLICENSE.txt.\n\n\nRelease\n=======\n\n1. Check version number in `lib/python/pyflyby/_version.py`, maybe increase it.\n2. Commit and tag if necessary, and push tags/commits.\n3. Optional: Set SOURCE_DATE_EPOCH for reproducible build::\n\n    export SOURCE_DATE_EPOCH=$(git show -s --format=%ct HEAD)\n\n4. Build the SDIST::\n\n    python setup.py sdist\n\n5. Optional Repack the Sdist to make sure the ZIP only contain SOURCE_DATE_EPOCH\n   date using IPython tools::\n\n    python ~/dev/ipython/tools/retar.py dist/pyflyby-1.7.8.tar.gz\n    shasum -a 256 dist/*\n\n6. Optional, redo 4 & 5 to verify checksum is unchanged.\n7. Upload using twine::\n\n    twine upload dist/*\n\n8. Check/update https://github.com/conda-forge/pyflyby-feedstock for new pyflyby\n   release on conda-forge\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "pyflyby - Python development productivity tools, in particular automatic import management",
    "version": "1.9.3",
    "project_urls": {
        "Documentation": "https://deshaw.github.io/pyflyby/",
        "Homepage": "https://pypi.org/project/pyflyby/",
        "Source": "https://github.com/deshaw/pyflyby"
    },
    "split_keywords": [
        "pyflyby",
        "py",
        "autopython",
        "autoipython",
        "productivity",
        "automatic",
        "imports",
        "autoimporter",
        "tidy-imports"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a8c16401868865f3e5daa8af24b8b308aa6ccb78167c5218a7ad5f3844a7ca8f",
                "md5": "e06cda7cb9d7b088c48faa5d7b364462",
                "sha256": "99f14654b460ca88829d0103de1bfb57e06b3c0fd89f8d87cfc02ba9e604feb6"
            },
            "downloads": -1,
            "filename": "pyflyby-1.9.3.tar.gz",
            "has_sig": false,
            "md5_digest": "e06cda7cb9d7b088c48faa5d7b364462",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4,>3.6",
            "size": 431907,
            "upload_time": "2024-04-08T05:12:16",
            "upload_time_iso_8601": "2024-04-08T05:12:16.322155Z",
            "url": "https://files.pythonhosted.org/packages/a8/c1/6401868865f3e5daa8af24b8b308aa6ccb78167c5218a7ad5f3844a7ca8f/pyflyby-1.9.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-08 05:12:16",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "deshaw",
    "github_project": "pyflyby",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "pyflyby"
}
        
Elapsed time: 0.21984s