pyflyby 1.9.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of pyflyby might be problematic. Click here for more details.
- pyflyby/__init__.py +56 -0
- pyflyby/__main__.py +9 -0
- pyflyby/_autoimp.py +2114 -0
- pyflyby/_cmdline.py +531 -0
- pyflyby/_comms.py +221 -0
- pyflyby/_dbg.py +1339 -0
- pyflyby/_docxref.py +379 -0
- pyflyby/_file.py +738 -0
- pyflyby/_flags.py +230 -0
- pyflyby/_format.py +182 -0
- pyflyby/_idents.py +233 -0
- pyflyby/_import_sorting.py +165 -0
- pyflyby/_importclns.py +642 -0
- pyflyby/_importdb.py +588 -0
- pyflyby/_imports2s.py +639 -0
- pyflyby/_importstmt.py +662 -0
- pyflyby/_interactive.py +2605 -0
- pyflyby/_livepatch.py +793 -0
- pyflyby/_log.py +199 -0
- pyflyby/_modules.py +515 -0
- pyflyby/_parse.py +1441 -0
- pyflyby/_py.py +2078 -0
- pyflyby/_util.py +459 -0
- pyflyby/_version.py +7 -0
- pyflyby/autoimport.py +20 -0
- pyflyby/importdb.py +19 -0
- pyflyby-1.9.4.data/data/etc/pyflyby/canonical.py +10 -0
- pyflyby-1.9.4.data/data/etc/pyflyby/common.py +27 -0
- pyflyby-1.9.4.data/data/etc/pyflyby/forget.py +10 -0
- pyflyby-1.9.4.data/data/etc/pyflyby/mandatory.py +10 -0
- pyflyby-1.9.4.data/data/etc/pyflyby/numpy.py +156 -0
- pyflyby-1.9.4.data/data/etc/pyflyby/std.py +335 -0
- pyflyby-1.9.4.data/data/libexec/pyflyby/colordiff +34 -0
- pyflyby-1.9.4.data/data/libexec/pyflyby/diff-colorize +148 -0
- pyflyby-1.9.4.data/data/share/doc/pyflyby/LICENSE.txt +23 -0
- pyflyby-1.9.4.data/data/share/doc/pyflyby/TODO.txt +115 -0
- pyflyby-1.9.4.data/data/share/doc/pyflyby/testing.txt +13 -0
- pyflyby-1.9.4.data/data/share/emacs/site-lisp/pyflyby.el +108 -0
- pyflyby-1.9.4.data/scripts/collect-exports +76 -0
- pyflyby-1.9.4.data/scripts/collect-imports +58 -0
- pyflyby-1.9.4.data/scripts/find-import +38 -0
- pyflyby-1.9.4.data/scripts/list-bad-xrefs +34 -0
- pyflyby-1.9.4.data/scripts/prune-broken-imports +34 -0
- pyflyby-1.9.4.data/scripts/pyflyby-diff +34 -0
- pyflyby-1.9.4.data/scripts/reformat-imports +27 -0
- pyflyby-1.9.4.data/scripts/replace-star-imports +37 -0
- pyflyby-1.9.4.data/scripts/tidy-imports +191 -0
- pyflyby-1.9.4.data/scripts/transform-imports +47 -0
- pyflyby-1.9.4.dist-info/LICENSE.txt +23 -0
- pyflyby-1.9.4.dist-info/METADATA +507 -0
- pyflyby-1.9.4.dist-info/RECORD +54 -0
- pyflyby-1.9.4.dist-info/WHEEL +5 -0
- pyflyby-1.9.4.dist-info/entry_points.txt +3 -0
- pyflyby-1.9.4.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,507 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: pyflyby
|
|
3
|
+
Version: 1.9.4
|
|
4
|
+
Summary: pyflyby - Python development productivity tools, in particular automatic import management
|
|
5
|
+
Home-page: https://pypi.org/project/pyflyby/
|
|
6
|
+
Author: Karl Chen
|
|
7
|
+
Author-email: quarl@8166.clguba.z.quarl.org
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Documentation, https://deshaw.github.io/pyflyby/
|
|
10
|
+
Project-URL: Source, https://github.com/deshaw/pyflyby
|
|
11
|
+
Keywords: pyflyby py autopython autoipython productivity automatic imports autoimporter tidy-imports
|
|
12
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
13
|
+
Classifier: Topic :: Software Development
|
|
14
|
+
Classifier: Topic :: Software Development :: Code Generators
|
|
15
|
+
Classifier: Topic :: Software Development :: Interpreters
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
18
|
+
Classifier: Programming Language :: Python
|
|
19
|
+
Requires-Python: >3.8, <4
|
|
20
|
+
License-File: LICENSE.txt
|
|
21
|
+
Requires-Dist: six
|
|
22
|
+
Requires-Dist: toml
|
|
23
|
+
Requires-Dist: black
|
|
24
|
+
|
|
25
|
+
#########
|
|
26
|
+
Pyflyby
|
|
27
|
+
#########
|
|
28
|
+
|
|
29
|
+
.. image:: https://badge.fury.io/py/pyflyby.svg
|
|
30
|
+
:target: https://pypi.org/project/pyflyby/
|
|
31
|
+
|
|
32
|
+
.. image:: https://travis-ci.org/deshaw/pyflyby.png?branch=master
|
|
33
|
+
:target: https://travis-ci.org/deshaw/pyflyby
|
|
34
|
+
|
|
35
|
+
Pyflyby is a set of Python programming productivity tools for Python 3.8+.
|
|
36
|
+
|
|
37
|
+
For command-line interaction:
|
|
38
|
+
* ``py``: command-line multitool
|
|
39
|
+
|
|
40
|
+
For IPython interaction:
|
|
41
|
+
* ``autoimporter``: automatically imports symbols when needed.
|
|
42
|
+
|
|
43
|
+
For editing python source code:
|
|
44
|
+
* ``tidy-imports``: adds missing 'import's, removes unused 'import's,
|
|
45
|
+
and also reformats import blocks.
|
|
46
|
+
* ``find-import``: prints to stdout how to import a particular symbol.
|
|
47
|
+
* ``reformat-imports``: reformats ``import`` blocks
|
|
48
|
+
* ``collect-imports``: prints out all the imports in a given set of files.
|
|
49
|
+
* ``collect-exports``: prints out definitions in a given set of modules,
|
|
50
|
+
in the form of import statements.
|
|
51
|
+
* ``transform-imports``: renames imported modules/functions.
|
|
52
|
+
|
|
53
|
+
Installation
|
|
54
|
+
============
|
|
55
|
+
|
|
56
|
+
.. code:: bash
|
|
57
|
+
|
|
58
|
+
$ pip install pyflyby
|
|
59
|
+
|
|
60
|
+
This creates an alias for your `ipython` named `py` which runs the `pyflyby` plug internally.
|
|
61
|
+
`pyflyby` has a dependency on `ipython`, if it isn't already installed do install it with:
|
|
62
|
+
|
|
63
|
+
.. code:: bash
|
|
64
|
+
|
|
65
|
+
$ pip install ipython
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
Quick start: Autoimporter + IPython
|
|
69
|
+
===================================
|
|
70
|
+
|
|
71
|
+
.. code:: bash
|
|
72
|
+
|
|
73
|
+
$ py
|
|
74
|
+
In [1]: re.search("[a-z]+", "....hello...").group(0)
|
|
75
|
+
[PYFLYBY] import re
|
|
76
|
+
Out[1]: 'hello'
|
|
77
|
+
|
|
78
|
+
In [2]: chisqprob(arange(5), 2)
|
|
79
|
+
[PYFLYBY] from numpy import arange
|
|
80
|
+
[PYFLYBY] from scipy.stats import chisqprob
|
|
81
|
+
Out[2]: [ 1. 0.6065 0.3679 0.2231 0.1353]
|
|
82
|
+
|
|
83
|
+
To load pyflyby into an existing IPython session as a 1-off:
|
|
84
|
+
|
|
85
|
+
.. code:: bash
|
|
86
|
+
|
|
87
|
+
$ ipython
|
|
88
|
+
In [1]: %load_ext pyflyby
|
|
89
|
+
|
|
90
|
+
To configure IPython/Jupyter Notebook to load pyflyby automatically:
|
|
91
|
+
|
|
92
|
+
.. code:: bash
|
|
93
|
+
|
|
94
|
+
$ py pyflyby.install_in_ipython_config_file
|
|
95
|
+
|
|
96
|
+
or
|
|
97
|
+
|
|
98
|
+
.. code:: bash
|
|
99
|
+
|
|
100
|
+
$ echo 'c.InteractiveShellApp.extensions.append("pyflyby")' \
|
|
101
|
+
>> ~/.ipython/profile_default/ipython_config.py
|
|
102
|
+
|
|
103
|
+
$ ipython
|
|
104
|
+
In [1]: b64decode('aGVsbG8=')
|
|
105
|
+
[PYFLYBY] from base64 import b64decode
|
|
106
|
+
Out[1]: 'hello'
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
Quick start: ``py`` command-line multi-tool
|
|
110
|
+
===========================================
|
|
111
|
+
|
|
112
|
+
.. code:: bash
|
|
113
|
+
|
|
114
|
+
$ py b64decode aGVsbG8=
|
|
115
|
+
[PYFLYBY] from base64 import b64decode
|
|
116
|
+
[PYFLYBY] b64decode('aGVsbG8=', altchars=None)
|
|
117
|
+
'hello'
|
|
118
|
+
|
|
119
|
+
$ py log2 sys.maxint
|
|
120
|
+
[PYFLYBY] from numpy import log2
|
|
121
|
+
[PYFLYBY] import sys
|
|
122
|
+
[PYFLYBY] log2(9223372036854775807)
|
|
123
|
+
63.0
|
|
124
|
+
|
|
125
|
+
$ py 'plot(cos(arange(30)))'
|
|
126
|
+
[PYFLYBY] from numpy import arange
|
|
127
|
+
[PYFLYBY] from numpy import cos
|
|
128
|
+
[PYFLYBY] from matplotlib.pyplot import plot
|
|
129
|
+
[PYFLYBY] plot(cos(arange(30)))
|
|
130
|
+
<plot>
|
|
131
|
+
|
|
132
|
+
$ py 38497631 / 13951446
|
|
133
|
+
2.7594007818257693
|
|
134
|
+
|
|
135
|
+
$ py foo.py
|
|
136
|
+
|
|
137
|
+
Quick start: ``tidy-imports``
|
|
138
|
+
=============================
|
|
139
|
+
|
|
140
|
+
To use ``tidy-imports``, just specify the filename(s) to tidy.
|
|
141
|
+
|
|
142
|
+
For example:
|
|
143
|
+
|
|
144
|
+
.. code::
|
|
145
|
+
|
|
146
|
+
$ echo 're.search("[a-z]+", "....hello..."), chisqprob(arange(5), 2)' > foo.py
|
|
147
|
+
|
|
148
|
+
$ tidy-imports foo.py
|
|
149
|
+
--- /tmp/foo.py
|
|
150
|
+
+++ /tmp/foo.py
|
|
151
|
+
@@ -1 +1,9 @@
|
|
152
|
+
+from __future__ import absolute_import, division, with_statement
|
|
153
|
+
+
|
|
154
|
+
+from numpy import arange
|
|
155
|
+
+from scipy.stats import chisqprob
|
|
156
|
+
+import re
|
|
157
|
+
+
|
|
158
|
+
re.search("[a-z]+", "....hello..."), chisqprob(arange(5), 2)
|
|
159
|
+
|
|
160
|
+
Replace /tmp/foo.py? [y/N]
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
Quick start: import libraries
|
|
164
|
+
=============================
|
|
165
|
+
|
|
166
|
+
Create a file named .pyflyby with lines such as
|
|
167
|
+
|
|
168
|
+
.. code:: python
|
|
169
|
+
|
|
170
|
+
from mypackage.mymodule import MyClass, my_function
|
|
171
|
+
import anotherpackage.anothermodule
|
|
172
|
+
|
|
173
|
+
You can put this file in your home directory or in the same directory as your
|
|
174
|
+
``*.py`` files.
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
Details: automatic imports
|
|
178
|
+
==========================
|
|
179
|
+
|
|
180
|
+
AUTOMATIC IMPORTS - never type "import" again!
|
|
181
|
+
|
|
182
|
+
This module allows your "known imports" to work automatically in your IPython
|
|
183
|
+
interactive session without having to type the 'import' statements (and also
|
|
184
|
+
without having to slow down your Python startup with imports you only use
|
|
185
|
+
occasionally).
|
|
186
|
+
|
|
187
|
+
Example::
|
|
188
|
+
|
|
189
|
+
In [1]: re.search("[a-z]+", "....hello...").group(0)
|
|
190
|
+
[PYFLYBY] import re
|
|
191
|
+
Out[1]: 'hello'
|
|
192
|
+
|
|
193
|
+
In [2]: chisqprob(arange(5), 2)
|
|
194
|
+
[PYFLYBY] from numpy import arange
|
|
195
|
+
[PYFLYBY] from scipy.stats import chisqprob
|
|
196
|
+
Out[2]: [ 1. 0.6065 0.3679 0.2231 0.1353]
|
|
197
|
+
|
|
198
|
+
In [3]: np.sin(arandom(5))
|
|
199
|
+
[PYFLYBY] from numpy.random import random as arandom
|
|
200
|
+
[PYFLYBY] import numpy as np
|
|
201
|
+
Out[3]: [ 0.0282 0.0603 0.4653 0.8371 0.3347]
|
|
202
|
+
|
|
203
|
+
In [4]: isinstance(42, Number)
|
|
204
|
+
[PYFLYBY] from numbers import Number
|
|
205
|
+
Out[4]: True
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
It just works
|
|
209
|
+
-------------
|
|
210
|
+
|
|
211
|
+
Tab completion works, even on modules that are not yet imported. In the
|
|
212
|
+
following example, notice that numpy is imported when we need to know its
|
|
213
|
+
members, and only then::
|
|
214
|
+
|
|
215
|
+
$ ipython
|
|
216
|
+
In [1]: nump<TAB>
|
|
217
|
+
In [1]: numpy
|
|
218
|
+
In [1]: numpy.arang<TAB>
|
|
219
|
+
[PYFLYBY] import numpy
|
|
220
|
+
In [1]: numpy.arange
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
The IPython "?" magic help (pinfo/pinfo2) automatically imports symbols first
|
|
224
|
+
if necessary::
|
|
225
|
+
|
|
226
|
+
$ ipython
|
|
227
|
+
In [1]: arange?
|
|
228
|
+
[PYFLYBY] from numpy import arange
|
|
229
|
+
... Docstring: arange([start,] stop[, step,], dtype=None) ...
|
|
230
|
+
|
|
231
|
+
Other IPython magic commands work as well::
|
|
232
|
+
|
|
233
|
+
$ ipython
|
|
234
|
+
In [1]: %timeit np.cos(pi)
|
|
235
|
+
[PYFLYBY] import numpy as np
|
|
236
|
+
[PYFLYBY] from numpy import pi
|
|
237
|
+
100000 loops, best of 3: 2.51 us per loop
|
|
238
|
+
|
|
239
|
+
$ echo 'print arange(4)' > foo.py
|
|
240
|
+
$ ipython
|
|
241
|
+
In [1]: %run foo.py
|
|
242
|
+
[PYFLYBY] from numpy import arange
|
|
243
|
+
[0 1 2 3]
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
Implementation details
|
|
247
|
+
----------------------
|
|
248
|
+
|
|
249
|
+
The automatic importing happens at parse time, before code is executed. The
|
|
250
|
+
namespace never contains entries for names that are not yet imported.
|
|
251
|
+
|
|
252
|
+
This method of importing at parse time contrasts with previous implementations
|
|
253
|
+
of automatic importing that use proxy objects. Those implementations using
|
|
254
|
+
proxy objects don't work as well, because it is impossible to make proxy
|
|
255
|
+
objects behave perfectly. For example, instance(x, T) will return the wrong
|
|
256
|
+
answer if either x or T is a proxy object.
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
Compatibility
|
|
260
|
+
-------------
|
|
261
|
+
|
|
262
|
+
Tested with:
|
|
263
|
+
- Python 3.8, 3.9, 3.10
|
|
264
|
+
- 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,
|
|
265
|
+
3.1, 3.2, 4.0., 7.11 (latest)
|
|
266
|
+
- IPython (text console), IPython Notebook, Spyder
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
Details: import libraries
|
|
270
|
+
=========================
|
|
271
|
+
|
|
272
|
+
Pyflyby uses "import libraries" that tell how to import a given symbol.
|
|
273
|
+
|
|
274
|
+
An import library file is simply a python source file containing 'import' (or
|
|
275
|
+
'from ... import ...') lines. These can be generated automatically with
|
|
276
|
+
``collect-imports`` and ``collect-exports``.
|
|
277
|
+
|
|
278
|
+
Known imports
|
|
279
|
+
-------------
|
|
280
|
+
|
|
281
|
+
Find-imports, ``tidy-imports``, and autoimport consult the database of known
|
|
282
|
+
imports to figure out where to get an import. For example, if the
|
|
283
|
+
imports database contains::
|
|
284
|
+
|
|
285
|
+
from numpy import arange, NaN
|
|
286
|
+
|
|
287
|
+
then when you type the following in IPython::
|
|
288
|
+
|
|
289
|
+
print(arange(10))
|
|
290
|
+
|
|
291
|
+
the autoimporter would automatically execute ``from numpy import arange``.
|
|
292
|
+
|
|
293
|
+
The database can be one file or multiple files. This makes it easy to have
|
|
294
|
+
project-specific known_imports along with global and per-user defaults.
|
|
295
|
+
|
|
296
|
+
The ``PYFLYBY_PATH`` environment variable specifies which files to read.
|
|
297
|
+
This is a colon-separated list of filenames or directory names. The default
|
|
298
|
+
is::
|
|
299
|
+
|
|
300
|
+
PYFLYBY_PATH=/etc/pyflyby:~/.pyflyby:.../.pyflyby
|
|
301
|
+
|
|
302
|
+
If you set::
|
|
303
|
+
|
|
304
|
+
PYFLYBY_PATH=/foo1/bar1:/foo2/bar2
|
|
305
|
+
|
|
306
|
+
then this replaces the default.
|
|
307
|
+
|
|
308
|
+
You can use a hyphen to include the default in the path. If you set::
|
|
309
|
+
|
|
310
|
+
PYFLYBY_PATH=/foo1/bar1:-:/foo2/bar2
|
|
311
|
+
|
|
312
|
+
then this reads ``/foo1/bar1``, then the default locations, then ``/foo2/bar2``.
|
|
313
|
+
|
|
314
|
+
In ``$PYFLYBY_PATH``, ``.../.pyflyby`` (with _three_ dots) means that all ancestor
|
|
315
|
+
directories are searched for a member named ".pyflyby".
|
|
316
|
+
|
|
317
|
+
For example, suppose the following files exist::
|
|
318
|
+
|
|
319
|
+
/etc/pyflyby/stuff.py
|
|
320
|
+
/u/quarl/.pyflyby/blah1.py
|
|
321
|
+
/u/quarl/.pyflyby/more/blah2.py
|
|
322
|
+
/proj/share/mypythonstuff/.pyflyby
|
|
323
|
+
/proj/share/mypythonstuff/foo/bar/.pyflyby/baz.py
|
|
324
|
+
/.pyflyby
|
|
325
|
+
|
|
326
|
+
Further, suppose:
|
|
327
|
+
|
|
328
|
+
* ``/proj`` is on a separate file system from ``/``.
|
|
329
|
+
* ``$HOME=/u/quarl``
|
|
330
|
+
|
|
331
|
+
Then ``tidy-imports /proj/share/mypythonstuff/foo/bar/quux/zot.py`` will by
|
|
332
|
+
default use the following::
|
|
333
|
+
|
|
334
|
+
/etc/pyflyby/stuff.py
|
|
335
|
+
/u/quarl/.pyflyby/blah1.py
|
|
336
|
+
/u/quarl/.pyflyby/more/blah2.py
|
|
337
|
+
/proj/share/mypythonstuff/foo/bar/.pyflyby/baz.py
|
|
338
|
+
/proj/share/mypythonstuff/.pyflyby (a file)
|
|
339
|
+
|
|
340
|
+
.. note::
|
|
341
|
+
|
|
342
|
+
* ``/.pyflyby`` is not included, because traversal stops at file system
|
|
343
|
+
boundaries, and in this example, ``/proj`` is on a different file system than
|
|
344
|
+
``/``.
|
|
345
|
+
* ``.pyflyby`` (in ``$HOME`` or near the target file) can be a file or a directory.
|
|
346
|
+
If it is a directory, then it is recursively searched for ``*.py`` files.
|
|
347
|
+
* The order usually doesn't matter, but if there are "forget" instructions
|
|
348
|
+
(see below), then the order matters. In the default ``$PYFLYBY_PATH``,
|
|
349
|
+
.../.pyflyby is placed last so that per-directory configuration can
|
|
350
|
+
override per-user configuration, which can override systemwide
|
|
351
|
+
configuration.
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
Forgetting imports
|
|
355
|
+
------------------
|
|
356
|
+
|
|
357
|
+
Occasionally you may have reason to tell pyflyby to "forget" entries from the
|
|
358
|
+
database of known imports.
|
|
359
|
+
|
|
360
|
+
You can put the following in any file reachable from ``$PYFLYBY_PATH``::
|
|
361
|
+
|
|
362
|
+
__forget_imports__ = ["from numpy import NaN"]
|
|
363
|
+
|
|
364
|
+
This is useful if you want to use a set of imports maintained by someone else
|
|
365
|
+
except for a few particular imports.
|
|
366
|
+
|
|
367
|
+
Entries in ``$PYFLYBY_PATH`` are processed left-to-right in the order specified,
|
|
368
|
+
so put the files containing these at the end of your ``$PYFLYBY_PATH``. By
|
|
369
|
+
default, ``tidy-imports`` and friends process ``/etc/pyflyby``, then ``~/.pyflyby``,
|
|
370
|
+
then the per-directory ``.pyflyby``.
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
Mandatory imports
|
|
374
|
+
-----------------
|
|
375
|
+
|
|
376
|
+
Within a certain project you may have a policy to always include certain
|
|
377
|
+
imports. For example, maybe you always want to do ``from __future__ import
|
|
378
|
+
division`` in all files.
|
|
379
|
+
|
|
380
|
+
You can put the following in any file reachable from ``$PYFLYBY_PATH``::
|
|
381
|
+
|
|
382
|
+
__mandatory_imports__ = ["from __future__ import division"]
|
|
383
|
+
|
|
384
|
+
To undo mandatory imports inherited from other ``.pyflyby`` files, use
|
|
385
|
+
``__forget_imports__`` (see above).
|
|
386
|
+
|
|
387
|
+
|
|
388
|
+
Canonicalize imports
|
|
389
|
+
--------------------
|
|
390
|
+
|
|
391
|
+
Sometimes you want every run of ``tidy-imports`` to automatically rename an import
|
|
392
|
+
to a new name.
|
|
393
|
+
|
|
394
|
+
You can put the following in any file reachable from ``$PYFLYBY_PATH``::
|
|
395
|
+
|
|
396
|
+
__canonical_imports__ = {"oldmodule.oldfunction": "newmodule.newfunction"}
|
|
397
|
+
|
|
398
|
+
This is equivalent to running::
|
|
399
|
+
|
|
400
|
+
tidy-imports --transform=oldmodule.oldfunction=newmodule.newfunction
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
Soapbox: avoid "star" imports
|
|
404
|
+
=============================
|
|
405
|
+
|
|
406
|
+
When programming in Python, a good software engineering practice is to avoid
|
|
407
|
+
using ``from foopackage import *`` in production code.
|
|
408
|
+
|
|
409
|
+
This style is a maintenance nightmare:
|
|
410
|
+
|
|
411
|
+
* It becomes difficult to figure out where various symbols
|
|
412
|
+
(functions/classes/etc) come from.
|
|
413
|
+
|
|
414
|
+
* It's hard to tell what gets shadowed by what.
|
|
415
|
+
|
|
416
|
+
* When the package changes in trivial ways, your code will be affected.
|
|
417
|
+
Consider the following example: Suppose ``foopackage.py`` contains ``import
|
|
418
|
+
sys``, and ``myprogram.py`` contains ``from foopackage import *; if
|
|
419
|
+
some_condition: sys.exit(0)``. If ``foopackage.py`` changes so that ``import
|
|
420
|
+
sys`` is removed, ``myprogram.py`` is now broken because it's missing ``import
|
|
421
|
+
sys``.
|
|
422
|
+
|
|
423
|
+
To fix such code, you can run ``tidy-imports --replace-star-imports`` to
|
|
424
|
+
automatically replace star imports with the specific needed imports.
|
|
425
|
+
|
|
426
|
+
Per-Project configuration of tidy-imports
|
|
427
|
+
=========================================
|
|
428
|
+
|
|
429
|
+
You can configure Pyflyby on a per-repository basis by using the
|
|
430
|
+
`[tool.pyflyby]` section of `pyproject.toml` files. Pyflyby will look in current
|
|
431
|
+
working directory and all it's parent until it find a `pyproject.toml` file from
|
|
432
|
+
which it will load the defaults.
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
Most of the long command line flags default values can be configured in this
|
|
436
|
+
section. Simply use the long form option name by replacing dashes `-` by
|
|
437
|
+
underscore `_`. For long option that have the form `--xxx` and `--no-xxx`, you
|
|
438
|
+
can assign a boolean to `xxx`. For example::
|
|
439
|
+
|
|
440
|
+
[tool.pyflyby]
|
|
441
|
+
add_missing=true
|
|
442
|
+
from_spaces=7
|
|
443
|
+
remove_unused=false
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
Emacs support
|
|
447
|
+
=============
|
|
448
|
+
|
|
449
|
+
* To get a ``M-x tidy-imports`` command in GNU Emacs, add to your ``~/.emacs``::
|
|
450
|
+
|
|
451
|
+
(load "/path/to/pyflyby/lib/emacs/pyflyby.el")
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
- Pyflyby.el doesn't yet work with XEmacs; patches welcome.
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
Authorship
|
|
458
|
+
==========
|
|
459
|
+
|
|
460
|
+
This plugin was contributed back to the community by the `D. E. Shaw group
|
|
461
|
+
<https://www.deshaw.com/>`_.
|
|
462
|
+
|
|
463
|
+
.. image:: https://www.deshaw.com/assets/logos/blue_logo_417x125.png
|
|
464
|
+
:target: https://www.deshaw.com
|
|
465
|
+
:height: 75 px
|
|
466
|
+
|
|
467
|
+
Pyflyby is written by Karl Chen <quarl@8166.clguba.z.quarl.org>
|
|
468
|
+
|
|
469
|
+
We love contributions! Before you can contribute, please sign and submit this
|
|
470
|
+
`Contributor License Agreement (CLA) <https://www.deshaw.com/oss/cla>`_.
|
|
471
|
+
This CLA is in place to protect all users of this project.
|
|
472
|
+
|
|
473
|
+
License
|
|
474
|
+
=======
|
|
475
|
+
|
|
476
|
+
Pyflyby is released under a very permissive license, the MIT/X11 license; see
|
|
477
|
+
LICENSE.txt.
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
Release
|
|
481
|
+
=======
|
|
482
|
+
|
|
483
|
+
1. Check version number in `lib/python/pyflyby/_version.py`, maybe increase it.
|
|
484
|
+
2. Commit and tag if necessary, and push tags/commits.
|
|
485
|
+
3. Optional: Set SOURCE_DATE_EPOCH for reproducible build::
|
|
486
|
+
|
|
487
|
+
export SOURCE_DATE_EPOCH=$(git show -s --format=%ct HEAD)
|
|
488
|
+
|
|
489
|
+
4. Build the SDIST::
|
|
490
|
+
|
|
491
|
+
python setup.py sdist
|
|
492
|
+
|
|
493
|
+
5. Optional Repack the Sdist to make sure the ZIP only contain SOURCE_DATE_EPOCH
|
|
494
|
+
date using IPython tools::
|
|
495
|
+
|
|
496
|
+
python ~/dev/ipython/tools/retar.py dist/pyflyby-1.7.8.tar.gz
|
|
497
|
+
shasum -a 256 dist/*
|
|
498
|
+
|
|
499
|
+
6. Optional, redo 4 & 5 to verify checksum is unchanged.
|
|
500
|
+
7. Upload using twine::
|
|
501
|
+
|
|
502
|
+
twine upload dist/*
|
|
503
|
+
|
|
504
|
+
8. Check/update https://github.com/conda-forge/pyflyby-feedstock for new pyflyby
|
|
505
|
+
release on conda-forge
|
|
506
|
+
|
|
507
|
+
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
pyflyby/__init__.py,sha256=VUjYCRGjsd6gLot5aDFucYhAYac1yQ8IXofqRvkFRAg,2669
|
|
2
|
+
pyflyby/__main__.py,sha256=F_so6X2LPdGUrTWjYvRaTOHHXxCmTGPsp5KcX-Vl6Eo,190
|
|
3
|
+
pyflyby/_autoimp.py,sha256=gYJhR6CwV8mAvWRLZnzboEfAsdA5LuqSBlrM_J29Ry8,83741
|
|
4
|
+
pyflyby/_cmdline.py,sha256=2IhoMHr_i8hlg7bPe1vXnBHzr2fhRy7Rj6JEd185jG4,20353
|
|
5
|
+
pyflyby/_comms.py,sha256=Q3JTbNqkHUw49laMQkFbqCs0FxDy6mi9V2glwdbwfEI,8249
|
|
6
|
+
pyflyby/_dbg.py,sha256=G2Y3B-uC8llKN4K5DA_wB2IDjFWYwNCpReJqWGeD0BA,45604
|
|
7
|
+
pyflyby/_docxref.py,sha256=teYGqDJauLrw6g5mVyXRIl9-q6WuyGjjEj4M8RIkTCU,14117
|
|
8
|
+
pyflyby/_file.py,sha256=eku3cBT5m2tsesPppK8t7BWhBvyHpn7ubhZbz2uA73Q,23212
|
|
9
|
+
pyflyby/_flags.py,sha256=ln-jkzTAiImrC6VB9ENlfjtlIAJp-b50wgWexfFAURw,7201
|
|
10
|
+
pyflyby/_format.py,sha256=kfXFzcPkA6aLKPcJ8AFQCBIU46XrnITdv5yxw2Dt2DI,6893
|
|
11
|
+
pyflyby/_idents.py,sha256=fB200Se5rE2mEIJw9jN-Ap_98-XOqhvok2hX5CvTDLM,6849
|
|
12
|
+
pyflyby/_import_sorting.py,sha256=msK8Fp9yew1qpVDXinB2fEcsVTcadE0TEbX8TvwbIV0,5756
|
|
13
|
+
pyflyby/_importclns.py,sha256=xuvVTqXr7lL_tS0oc4Bx7W2mq6GnkMbF66id0EE0-Jw,22244
|
|
14
|
+
pyflyby/_importdb.py,sha256=l1dS4aQWrCv-3JcJNvpq3aRNMJtmcCgSYupD7ihqXC0,23635
|
|
15
|
+
pyflyby/_imports2s.py,sha256=YYV7-5xP--jaDOOG77c2avxlzl651JoTvItuygOLC_I,24439
|
|
16
|
+
pyflyby/_importstmt.py,sha256=pHoAoq87isCasgNsJIsctV52XKj29C6gSO1VtHfMYlA,21730
|
|
17
|
+
pyflyby/_interactive.py,sha256=DLsNATGn4yn7SFC0-3Fq46KzRXd6j5L0wey1T4h8IbA,104055
|
|
18
|
+
pyflyby/_livepatch.py,sha256=4PRwpGwYEKqrwsON-ko7H_skZjcZhHCzepsjjfyOots,29450
|
|
19
|
+
pyflyby/_log.py,sha256=FRNrWqbFrQU3RcKPRAyEnvT9JV7ySjcgR8utF3WeHoo,6515
|
|
20
|
+
pyflyby/_modules.py,sha256=csMjG6pMX43GKPe70x2E2-2gV-6-UM2vh-ueNc969Kc,18918
|
|
21
|
+
pyflyby/_parse.py,sha256=JAdltVNd4-p2hSyUjNyEJCMRoeRrh_J4KUwkf_-Y4-Q,51465
|
|
22
|
+
pyflyby/_py.py,sha256=tyw65k9lPIEbdfllt818IpQG8L3GYQ3AjPmx7Oyp8ac,76789
|
|
23
|
+
pyflyby/_util.py,sha256=DFAOxtGSUoAJTzo1HNfqF5CueHvx5cxqy0xqjbSVPac,13862
|
|
24
|
+
pyflyby/_version.py,sha256=lmZRHIxZDNhEsWvOkqilAXYbf_-CB0y6PDXKhBVszu8,159
|
|
25
|
+
pyflyby/autoimport.py,sha256=GsdvaAmsVepkrR9vHtRkdXVrAqQoCG1OrOxUVOkuFc0,487
|
|
26
|
+
pyflyby/importdb.py,sha256=ClY6LeBuWcPGuia3S05JDlbQQyl79D3QoGy_ciUWSDk,494
|
|
27
|
+
pyflyby-1.9.4.data/data/etc/pyflyby/canonical.py,sha256=AEkiB4K19Pw4eKCns5dhnFXMmOJnRuwmly9RYihUwXM,270
|
|
28
|
+
pyflyby-1.9.4.data/data/etc/pyflyby/common.py,sha256=MQyqrSOVFM9Fj0mj3M87wzTWllkpZYCjDclxghkC0fs,569
|
|
29
|
+
pyflyby-1.9.4.data/data/etc/pyflyby/forget.py,sha256=N0xucS19eeoSS-BKXUI4bgwYrk4yWBOX3cVY0EC4KQE,369
|
|
30
|
+
pyflyby-1.9.4.data/data/etc/pyflyby/mandatory.py,sha256=-E52J_y2-Xu-YOHzoXiGVlCXcZqkEK4abVv7dQSNSgY,352
|
|
31
|
+
pyflyby-1.9.4.data/data/etc/pyflyby/numpy.py,sha256=LtAWlytttnw72IcA20z327rdRi_P3dXnRbb41mWJ0K0,10469
|
|
32
|
+
pyflyby-1.9.4.data/data/etc/pyflyby/std.py,sha256=pDFU6DDwZZLYD4itkimTI0fljsp4C4EO8fj5_wW21Vo,17596
|
|
33
|
+
pyflyby-1.9.4.data/data/libexec/pyflyby/colordiff,sha256=TqnG5jATcv9qU2HTuq2mQmb9m_jAjUfNQ4VIUnu5cK8,949
|
|
34
|
+
pyflyby-1.9.4.data/data/libexec/pyflyby/diff-colorize,sha256=S6wfKHEafQ9DFqiDvnnd70lrS71n1r1Tm9o2-FwxFgQ,5578
|
|
35
|
+
pyflyby-1.9.4.data/data/share/doc/pyflyby/LICENSE.txt,sha256=cSDlWua5QEFNdBRChGEKcS_5ABQ2220A3OkP10Q9RA0,1188
|
|
36
|
+
pyflyby-1.9.4.data/data/share/doc/pyflyby/TODO.txt,sha256=eQpkau8qCLSZcKeYDuI_W-_fXTy_tdDpahsMqyMVSK4,5622
|
|
37
|
+
pyflyby-1.9.4.data/data/share/doc/pyflyby/testing.txt,sha256=3IP6tJjrFjWTju1YZiu6vqn5yokEEb4I5mwJbSBWG-o,186
|
|
38
|
+
pyflyby-1.9.4.data/data/share/emacs/site-lisp/pyflyby.el,sha256=iKXqFc7kAweJ_TwQUhV3G-SxABme_Idk-iCwzLTmbbY,4122
|
|
39
|
+
pyflyby-1.9.4.data/scripts/collect-exports,sha256=g6apEIG_W5nJCQggahU8dAhcQbhG_Y_iPwxnc7GECLs,2849
|
|
40
|
+
pyflyby-1.9.4.data/scripts/collect-imports,sha256=uYGm9NEF_6_S1lgmYO13Aj7oER9xnDpzSM8taS1zwyM,2127
|
|
41
|
+
pyflyby-1.9.4.data/scripts/find-import,sha256=zl0-hKsFhsQHq7rszWxHw2K6MVmxSCCinTwf2PVnUwE,919
|
|
42
|
+
pyflyby-1.9.4.data/scripts/list-bad-xrefs,sha256=xzre8ggkNd2s0hCfAQtVCZdRxrAOwuNTrdqfyDMY2PQ,1013
|
|
43
|
+
pyflyby-1.9.4.data/scripts/prune-broken-imports,sha256=IRNs3Zc91Y-sAG1gkE6l9YNTdVrdNA_QRsWYu5rzeow,847
|
|
44
|
+
pyflyby-1.9.4.data/scripts/pyflyby-diff,sha256=TqnG5jATcv9qU2HTuq2mQmb9m_jAjUfNQ4VIUnu5cK8,949
|
|
45
|
+
pyflyby-1.9.4.data/scripts/reformat-imports,sha256=-3syw4ynxqopTX6BMmIuFAE1o2xYfEVBI6uAaTCJQXg,676
|
|
46
|
+
pyflyby-1.9.4.data/scripts/replace-star-imports,sha256=Fw2sHcmy5I1UhdkK8ouEJuge1y1IHb9Nq2eDIbQaNwY,899
|
|
47
|
+
pyflyby-1.9.4.data/scripts/tidy-imports,sha256=b-1lDNsvNrA4tDS2R8EvHtbeIHXMKdt_ysA4a1Idumg,7169
|
|
48
|
+
pyflyby-1.9.4.data/scripts/transform-imports,sha256=SEI2QPMuTkcWBlAsY4hvRqi5vQXrgEcTMOv4EKvuGvI,1436
|
|
49
|
+
pyflyby-1.9.4.dist-info/LICENSE.txt,sha256=cSDlWua5QEFNdBRChGEKcS_5ABQ2220A3OkP10Q9RA0,1188
|
|
50
|
+
pyflyby-1.9.4.dist-info/METADATA,sha256=m9ciluQFSRa4L0FFvQKr7MN5eECaeZB50szw5orSYN4,14735
|
|
51
|
+
pyflyby-1.9.4.dist-info/WHEEL,sha256=y4mX-SOX4fYIkonsAGA5N0Oy-8_gI4FXw5HNI1xqvWg,91
|
|
52
|
+
pyflyby-1.9.4.dist-info/entry_points.txt,sha256=Z1FokT4JYUoayjsapW47sgXCWT3odVC4_zjm3PcAij0,69
|
|
53
|
+
pyflyby-1.9.4.dist-info/top_level.txt,sha256=8qkns6b7GoPxK3kDelOerfZmj_nJyMB9O4J0quvGgE4,8
|
|
54
|
+
pyflyby-1.9.4.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pyflyby
|