pyflyby 1.10.4__cp311-cp311-macosx_11_0_arm64.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.
- pyflyby/__init__.py +61 -0
- pyflyby/__main__.py +9 -0
- pyflyby/_autoimp.py +2228 -0
- pyflyby/_cmdline.py +591 -0
- pyflyby/_comms.py +221 -0
- pyflyby/_dbg.py +1383 -0
- pyflyby/_dynimp.py +154 -0
- pyflyby/_fast_iter_modules.cpython-311-darwin.so +0 -0
- pyflyby/_file.py +771 -0
- pyflyby/_flags.py +230 -0
- pyflyby/_format.py +186 -0
- pyflyby/_idents.py +227 -0
- pyflyby/_import_sorting.py +165 -0
- pyflyby/_importclns.py +658 -0
- pyflyby/_importdb.py +535 -0
- pyflyby/_imports2s.py +643 -0
- pyflyby/_importstmt.py +723 -0
- pyflyby/_interactive.py +2113 -0
- pyflyby/_livepatch.py +793 -0
- pyflyby/_log.py +107 -0
- pyflyby/_modules.py +646 -0
- pyflyby/_parse.py +1396 -0
- pyflyby/_py.py +2165 -0
- pyflyby/_saveframe.py +1145 -0
- pyflyby/_saveframe_reader.py +471 -0
- pyflyby/_util.py +458 -0
- pyflyby/_version.py +8 -0
- pyflyby/autoimport.py +20 -0
- pyflyby/etc/pyflyby/canonical.py +10 -0
- pyflyby/etc/pyflyby/common.py +27 -0
- pyflyby/etc/pyflyby/forget.py +10 -0
- pyflyby/etc/pyflyby/mandatory.py +10 -0
- pyflyby/etc/pyflyby/numpy.py +156 -0
- pyflyby/etc/pyflyby/std.py +335 -0
- pyflyby/importdb.py +19 -0
- pyflyby/libexec/pyflyby/colordiff +34 -0
- pyflyby/libexec/pyflyby/diff-colorize +148 -0
- pyflyby/share/emacs/site-lisp/pyflyby.el +112 -0
- pyflyby-1.10.4.data/scripts/collect-exports +76 -0
- pyflyby-1.10.4.data/scripts/collect-imports +58 -0
- pyflyby-1.10.4.data/scripts/find-import +38 -0
- pyflyby-1.10.4.data/scripts/prune-broken-imports +34 -0
- pyflyby-1.10.4.data/scripts/pyflyby-diff +34 -0
- pyflyby-1.10.4.data/scripts/reformat-imports +27 -0
- pyflyby-1.10.4.data/scripts/replace-star-imports +37 -0
- pyflyby-1.10.4.data/scripts/saveframe +299 -0
- pyflyby-1.10.4.data/scripts/tidy-imports +170 -0
- pyflyby-1.10.4.data/scripts/transform-imports +47 -0
- pyflyby-1.10.4.dist-info/METADATA +605 -0
- pyflyby-1.10.4.dist-info/RECORD +53 -0
- pyflyby-1.10.4.dist-info/WHEEL +6 -0
- pyflyby-1.10.4.dist-info/entry_points.txt +4 -0
- pyflyby-1.10.4.dist-info/licenses/LICENSE.txt +19 -0
|
@@ -0,0 +1,605 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pyflyby
|
|
3
|
+
Version: 1.10.4
|
|
4
|
+
Summary: pyflyby - Python development productivity tools, in particular automatic import management
|
|
5
|
+
Author-Email: Karl Chen <quarl@8166.clguba.z.quarl.org>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
License-File: LICENSE.txt
|
|
8
|
+
Classifier: Programming Language :: Python
|
|
9
|
+
Classifier: Topic :: Software Development
|
|
10
|
+
Classifier: Topic :: Software Development :: Code Generators
|
|
11
|
+
Classifier: Topic :: Software Development :: Interpreters
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Project-URL: Homepage, https://pypi.org/project/pyflyby/
|
|
15
|
+
Project-URL: Documentation, https://deshaw.github.io/pyflyby/
|
|
16
|
+
Project-URL: Source, https://github.com/deshaw/pyflyby
|
|
17
|
+
Requires-Python: >=3.9
|
|
18
|
+
Requires-Dist: black
|
|
19
|
+
Requires-Dist: tomli; python_version < "3.11"
|
|
20
|
+
Requires-Dist: typing_extensions>=4.6; python_version < "3.12"
|
|
21
|
+
Requires-Dist: prompt_toolkit
|
|
22
|
+
Requires-Dist: platformdirs
|
|
23
|
+
Provides-Extra: test
|
|
24
|
+
Requires-Dist: beartype; extra == "test"
|
|
25
|
+
Requires-Dist: build; extra == "test"
|
|
26
|
+
Requires-Dist: coverage; extra == "test"
|
|
27
|
+
Requires-Dist: flaky; extra == "test"
|
|
28
|
+
Requires-Dist: hypothesis; extra == "test"
|
|
29
|
+
Requires-Dist: ipykernel>=5.4.3; extra == "test"
|
|
30
|
+
Requires-Dist: ipython; extra == "test"
|
|
31
|
+
Requires-Dist: jupyter; extra == "test"
|
|
32
|
+
Requires-Dist: jupyter_console>=6.2; extra == "test"
|
|
33
|
+
Requires-Dist: notebook<6.1; extra == "test"
|
|
34
|
+
Requires-Dist: pexpect>=3.3; extra == "test"
|
|
35
|
+
Requires-Dist: pytest-cov; extra == "test"
|
|
36
|
+
Requires-Dist: pytest-json-report; extra == "test"
|
|
37
|
+
Requires-Dist: pytest<=8; extra == "test"
|
|
38
|
+
Requires-Dist: requests; extra == "test"
|
|
39
|
+
Description-Content-Type: text/x-rst
|
|
40
|
+
|
|
41
|
+
#########
|
|
42
|
+
Pyflyby
|
|
43
|
+
#########
|
|
44
|
+
|
|
45
|
+
.. image:: https://badge.fury.io/py/pyflyby.svg
|
|
46
|
+
:target: https://pypi.org/project/pyflyby/
|
|
47
|
+
|
|
48
|
+
.. image:: https://travis-ci.org/deshaw/pyflyby.png?branch=master
|
|
49
|
+
:target: https://travis-ci.org/deshaw/pyflyby
|
|
50
|
+
|
|
51
|
+
Pyflyby is a set of Python programming productivity tools for Python 3.9+.
|
|
52
|
+
|
|
53
|
+
For command-line interaction:
|
|
54
|
+
* ``py``: command-line multitool
|
|
55
|
+
|
|
56
|
+
For IPython interaction:
|
|
57
|
+
* ``autoimporter``: automatically imports symbols when needed.
|
|
58
|
+
|
|
59
|
+
For editing python source code:
|
|
60
|
+
* ``tidy-imports``: adds missing 'import's, removes unused 'import's,
|
|
61
|
+
and also reformats import blocks.
|
|
62
|
+
* ``find-import``: prints to stdout how to import a particular symbol.
|
|
63
|
+
* ``reformat-imports``: reformats ``import`` blocks
|
|
64
|
+
* ``collect-imports``: prints out all the imports in a given set of files.
|
|
65
|
+
* ``collect-exports``: prints out definitions in a given set of modules,
|
|
66
|
+
in the form of import statements.
|
|
67
|
+
* ``transform-imports``: renames imported modules/functions.
|
|
68
|
+
|
|
69
|
+
`Learn more about Pyflyby <https://www.deshaw.com/library/desco-quansight-improving-jupyter-efficiency>`_ in this blog post.
|
|
70
|
+
|
|
71
|
+
Installation
|
|
72
|
+
============
|
|
73
|
+
|
|
74
|
+
.. code:: bash
|
|
75
|
+
|
|
76
|
+
$ pip install pyflyby
|
|
77
|
+
|
|
78
|
+
This creates an alias for your `ipython` named `py` which runs the `pyflyby` plug internally.
|
|
79
|
+
`pyflyby` has a dependency on `ipython`, if it isn't already installed do install it with:
|
|
80
|
+
|
|
81
|
+
.. code:: bash
|
|
82
|
+
|
|
83
|
+
$ pip install ipython
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
Quick start: Autoimporter + IPython
|
|
87
|
+
===================================
|
|
88
|
+
|
|
89
|
+
.. code:: bash
|
|
90
|
+
|
|
91
|
+
$ py
|
|
92
|
+
In [1]: re.search("[a-z]+", "....hello...").group(0)
|
|
93
|
+
[PYFLYBY] import re
|
|
94
|
+
Out[1]: 'hello'
|
|
95
|
+
|
|
96
|
+
In [2]: chisqprob(arange(5), 2)
|
|
97
|
+
[PYFLYBY] from numpy import arange
|
|
98
|
+
[PYFLYBY] from scipy.stats import chisqprob
|
|
99
|
+
Out[2]: [ 1. 0.6065 0.3679 0.2231 0.1353]
|
|
100
|
+
|
|
101
|
+
To load pyflyby into an existing IPython session as a 1-off:
|
|
102
|
+
|
|
103
|
+
.. code:: bash
|
|
104
|
+
|
|
105
|
+
$ ipython
|
|
106
|
+
In [1]: %load_ext pyflyby
|
|
107
|
+
|
|
108
|
+
To configure IPython/Jupyter Notebook to load pyflyby automatically:
|
|
109
|
+
|
|
110
|
+
.. code:: bash
|
|
111
|
+
|
|
112
|
+
$ py pyflyby.install_in_ipython_config_file
|
|
113
|
+
|
|
114
|
+
or
|
|
115
|
+
|
|
116
|
+
.. code:: bash
|
|
117
|
+
|
|
118
|
+
$ echo 'c.InteractiveShellApp.extensions.append("pyflyby")' \
|
|
119
|
+
>> ~/.ipython/profile_default/ipython_config.py
|
|
120
|
+
|
|
121
|
+
$ ipython
|
|
122
|
+
In [1]: b64decode('aGVsbG8=')
|
|
123
|
+
[PYFLYBY] from base64 import b64decode
|
|
124
|
+
Out[1]: 'hello'
|
|
125
|
+
|
|
126
|
+
Auto importer lazy variables
|
|
127
|
+
----------------------------
|
|
128
|
+
|
|
129
|
+
It is possible to use the autoimporter to lazily define variables.
|
|
130
|
+
|
|
131
|
+
To use, put the following in your IPython startup files
|
|
132
|
+
(``~/.ipython/profile_default/startup/autoimp.py``), or in your IPython
|
|
133
|
+
configuration file:
|
|
134
|
+
|
|
135
|
+
.. code:: python
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
from pyflyby import add_import
|
|
139
|
+
|
|
140
|
+
add_import("foo", "foo = 1")
|
|
141
|
+
|
|
142
|
+
add_import(
|
|
143
|
+
"df, data as dd",
|
|
144
|
+
'''
|
|
145
|
+
import pandas as pd
|
|
146
|
+
data = [1,2,3]
|
|
147
|
+
df = pd.DataFrame(data)
|
|
148
|
+
''')
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
You can add the keyword ``strict=False`` to not fail if not in IPython or of the
|
|
152
|
+
pyflyby extensions is not loaded.
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
Quick start: ``py`` command-line multi-tool
|
|
158
|
+
===========================================
|
|
159
|
+
|
|
160
|
+
.. code:: bash
|
|
161
|
+
|
|
162
|
+
$ py b64decode aGVsbG8=
|
|
163
|
+
[PYFLYBY] from base64 import b64decode
|
|
164
|
+
[PYFLYBY] b64decode('aGVsbG8=', altchars=None)
|
|
165
|
+
'hello'
|
|
166
|
+
|
|
167
|
+
$ py log2 sys.maxint
|
|
168
|
+
[PYFLYBY] from numpy import log2
|
|
169
|
+
[PYFLYBY] import sys
|
|
170
|
+
[PYFLYBY] log2(9223372036854775807)
|
|
171
|
+
63.0
|
|
172
|
+
|
|
173
|
+
$ py 'plot(cos(arange(30)))'
|
|
174
|
+
[PYFLYBY] from numpy import arange
|
|
175
|
+
[PYFLYBY] from numpy import cos
|
|
176
|
+
[PYFLYBY] from matplotlib.pyplot import plot
|
|
177
|
+
[PYFLYBY] plot(cos(arange(30)))
|
|
178
|
+
<plot>
|
|
179
|
+
|
|
180
|
+
$ py 38497631 / 13951446
|
|
181
|
+
2.7594007818257693
|
|
182
|
+
|
|
183
|
+
$ py foo.py
|
|
184
|
+
|
|
185
|
+
Quick start: ``tidy-imports``
|
|
186
|
+
=============================
|
|
187
|
+
|
|
188
|
+
To use ``tidy-imports``, just specify the filename(s) to tidy.
|
|
189
|
+
|
|
190
|
+
For example:
|
|
191
|
+
|
|
192
|
+
.. code::
|
|
193
|
+
|
|
194
|
+
$ echo 're.search("[a-z]+", "....hello..."), chisqprob(arange(5), 2)' > foo.py
|
|
195
|
+
|
|
196
|
+
$ tidy-imports foo.py
|
|
197
|
+
--- /tmp/foo.py
|
|
198
|
+
+++ /tmp/foo.py
|
|
199
|
+
@@ -1 +1,9 @@
|
|
200
|
+
+from __future__ import absolute_import, division, with_statement
|
|
201
|
+
+
|
|
202
|
+
+from numpy import arange
|
|
203
|
+
+from scipy.stats import chisqprob
|
|
204
|
+
+import re
|
|
205
|
+
+
|
|
206
|
+
re.search("[a-z]+", "....hello..."), chisqprob(arange(5), 2)
|
|
207
|
+
|
|
208
|
+
Replace /tmp/foo.py? [y/N]
|
|
209
|
+
|
|
210
|
+
To exclude a file, use `--exclude <pattern>`.
|
|
211
|
+
|
|
212
|
+
Quick start: import libraries
|
|
213
|
+
=============================
|
|
214
|
+
|
|
215
|
+
Create a file named .pyflyby with lines such as
|
|
216
|
+
|
|
217
|
+
.. code:: python
|
|
218
|
+
|
|
219
|
+
from mypackage.mymodule import MyClass, my_function
|
|
220
|
+
import anotherpackage.anothermodule
|
|
221
|
+
|
|
222
|
+
You can put this file in your home directory or in the same directory as your
|
|
223
|
+
``*.py`` files.
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
Details: automatic imports
|
|
227
|
+
==========================
|
|
228
|
+
|
|
229
|
+
AUTOMATIC IMPORTS - never type "import" again!
|
|
230
|
+
|
|
231
|
+
This module allows your "known imports" to work automatically in your IPython
|
|
232
|
+
interactive session without having to type the 'import' statements (and also
|
|
233
|
+
without having to slow down your Python startup with imports you only use
|
|
234
|
+
occasionally).
|
|
235
|
+
|
|
236
|
+
Example::
|
|
237
|
+
|
|
238
|
+
In [1]: re.search("[a-z]+", "....hello...").group(0)
|
|
239
|
+
[PYFLYBY] import re
|
|
240
|
+
Out[1]: 'hello'
|
|
241
|
+
|
|
242
|
+
In [2]: chisqprob(arange(5), 2)
|
|
243
|
+
[PYFLYBY] from numpy import arange
|
|
244
|
+
[PYFLYBY] from scipy.stats import chisqprob
|
|
245
|
+
Out[2]: [ 1. 0.6065 0.3679 0.2231 0.1353]
|
|
246
|
+
|
|
247
|
+
In [3]: np.sin(arandom(5))
|
|
248
|
+
[PYFLYBY] from numpy.random import random as arandom
|
|
249
|
+
[PYFLYBY] import numpy as np
|
|
250
|
+
Out[3]: [ 0.0282 0.0603 0.4653 0.8371 0.3347]
|
|
251
|
+
|
|
252
|
+
In [4]: isinstance(42, Number)
|
|
253
|
+
[PYFLYBY] from numbers import Number
|
|
254
|
+
Out[4]: True
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
It just works
|
|
258
|
+
-------------
|
|
259
|
+
|
|
260
|
+
Tab completion works, even on modules that are not yet imported. In the
|
|
261
|
+
following example, notice that numpy is imported when we need to know its
|
|
262
|
+
members, and only then::
|
|
263
|
+
|
|
264
|
+
$ ipython
|
|
265
|
+
In [1]: nump<TAB>
|
|
266
|
+
In [1]: numpy
|
|
267
|
+
In [1]: numpy.arang<TAB>
|
|
268
|
+
[PYFLYBY] import numpy
|
|
269
|
+
In [1]: numpy.arange
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
The IPython "?" magic help (pinfo/pinfo2) automatically imports symbols first
|
|
273
|
+
if necessary::
|
|
274
|
+
|
|
275
|
+
$ ipython
|
|
276
|
+
In [1]: arange?
|
|
277
|
+
[PYFLYBY] from numpy import arange
|
|
278
|
+
... Docstring: arange([start,] stop[, step,], dtype=None) ...
|
|
279
|
+
|
|
280
|
+
Other IPython magic commands work as well::
|
|
281
|
+
|
|
282
|
+
$ ipython
|
|
283
|
+
In [1]: %timeit np.cos(pi)
|
|
284
|
+
[PYFLYBY] import numpy as np
|
|
285
|
+
[PYFLYBY] from numpy import pi
|
|
286
|
+
100000 loops, best of 3: 2.51 us per loop
|
|
287
|
+
|
|
288
|
+
$ echo 'print arange(4)' > foo.py
|
|
289
|
+
$ ipython
|
|
290
|
+
In [1]: %run foo.py
|
|
291
|
+
[PYFLYBY] from numpy import arange
|
|
292
|
+
[0 1 2 3]
|
|
293
|
+
|
|
294
|
+
.. warning::
|
|
295
|
+
|
|
296
|
+
Auto-import on ``Tab`` completion requires IPython 9.3 or newer.
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
Implementation details
|
|
300
|
+
----------------------
|
|
301
|
+
|
|
302
|
+
The automatic importing happens at parse time, before code is executed. The
|
|
303
|
+
namespace never contains entries for names that are not yet imported.
|
|
304
|
+
|
|
305
|
+
This method of importing at parse time contrasts with previous implementations
|
|
306
|
+
of automatic importing that use proxy objects. Those implementations using
|
|
307
|
+
proxy objects don't work as well, because it is impossible to make proxy
|
|
308
|
+
objects behave perfectly. For example, ``instance(x, T)`` will return the wrong
|
|
309
|
+
answer if either x or T is a proxy object.
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
Compatibility
|
|
313
|
+
-------------
|
|
314
|
+
|
|
315
|
+
Tested with:
|
|
316
|
+
- Python 3.9, 3.10, 3.11, 3.12, 3.13
|
|
317
|
+
- IPython 8.18, 8.37.0, 9.4.0 (latest)
|
|
318
|
+
- IPython (text console), IPython Notebook, Spyder
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
Details: import libraries
|
|
322
|
+
=========================
|
|
323
|
+
|
|
324
|
+
Pyflyby uses "import libraries" that tell how to import a given symbol.
|
|
325
|
+
|
|
326
|
+
An import library file is simply a python source file containing 'import' (or
|
|
327
|
+
'from ... import ...') lines. These can be generated automatically with
|
|
328
|
+
``collect-imports`` and ``collect-exports``.
|
|
329
|
+
|
|
330
|
+
Known imports
|
|
331
|
+
-------------
|
|
332
|
+
|
|
333
|
+
Find-imports, ``tidy-imports``, and autoimport consult the database of known
|
|
334
|
+
imports to figure out where to get an import. For example, if the
|
|
335
|
+
imports database contains::
|
|
336
|
+
|
|
337
|
+
from numpy import arange, NaN
|
|
338
|
+
|
|
339
|
+
then when you type the following in IPython::
|
|
340
|
+
|
|
341
|
+
print(arange(10))
|
|
342
|
+
|
|
343
|
+
the autoimporter would automatically execute ``from numpy import arange``.
|
|
344
|
+
|
|
345
|
+
The database can be one file or multiple files. This makes it easy to have
|
|
346
|
+
project-specific known_imports along with global and per-user defaults.
|
|
347
|
+
|
|
348
|
+
The ``PYFLYBY_PATH`` environment variable specifies which files to read.
|
|
349
|
+
This is a colon-separated list of filenames or directory names. The default
|
|
350
|
+
is::
|
|
351
|
+
|
|
352
|
+
PYFLYBY_PATH=/etc/pyflyby:~/.pyflyby:.../.pyflyby
|
|
353
|
+
|
|
354
|
+
If you set::
|
|
355
|
+
|
|
356
|
+
PYFLYBY_PATH=/foo1/bar1:/foo2/bar2
|
|
357
|
+
|
|
358
|
+
then this replaces the default.
|
|
359
|
+
|
|
360
|
+
You can use a hyphen to include the default in the path. If you set::
|
|
361
|
+
|
|
362
|
+
PYFLYBY_PATH=/foo1/bar1:-:/foo2/bar2
|
|
363
|
+
|
|
364
|
+
then this reads ``/foo1/bar1``, then the default locations, then ``/foo2/bar2``.
|
|
365
|
+
|
|
366
|
+
In ``$PYFLYBY_PATH``, ``.../.pyflyby`` (with _three_ dots) means that all ancestor
|
|
367
|
+
directories are searched for a member named ".pyflyby".
|
|
368
|
+
|
|
369
|
+
For example, suppose the following files exist::
|
|
370
|
+
|
|
371
|
+
/etc/pyflyby/stuff.py
|
|
372
|
+
/u/quarl/.pyflyby/blah1.py
|
|
373
|
+
/u/quarl/.pyflyby/more/blah2.py
|
|
374
|
+
/proj/share/mypythonstuff/.pyflyby
|
|
375
|
+
/proj/share/mypythonstuff/foo/bar/.pyflyby/baz.py
|
|
376
|
+
/.pyflyby
|
|
377
|
+
|
|
378
|
+
Further, suppose:
|
|
379
|
+
|
|
380
|
+
* ``/proj`` is on a separate file system from ``/``.
|
|
381
|
+
* ``$HOME=/u/quarl``
|
|
382
|
+
|
|
383
|
+
Then ``tidy-imports /proj/share/mypythonstuff/foo/bar/quux/zot.py`` will by
|
|
384
|
+
default use the following::
|
|
385
|
+
|
|
386
|
+
/etc/pyflyby/stuff.py
|
|
387
|
+
/u/quarl/.pyflyby/blah1.py
|
|
388
|
+
/u/quarl/.pyflyby/more/blah2.py
|
|
389
|
+
/proj/share/mypythonstuff/foo/bar/.pyflyby/baz.py
|
|
390
|
+
/proj/share/mypythonstuff/.pyflyby (a file)
|
|
391
|
+
|
|
392
|
+
.. note::
|
|
393
|
+
|
|
394
|
+
* ``/.pyflyby`` is not included, because traversal stops at file system
|
|
395
|
+
boundaries, and in this example, ``/proj`` is on a different file system than
|
|
396
|
+
``/``.
|
|
397
|
+
* ``.pyflyby`` (in ``$HOME`` or near the target file) can be a file or a directory.
|
|
398
|
+
If it is a directory, then it is recursively searched for ``*.py`` files.
|
|
399
|
+
* The order usually doesn't matter, but if there are "forget" instructions
|
|
400
|
+
(see below), then the order matters. In the default ``$PYFLYBY_PATH``,
|
|
401
|
+
.../.pyflyby is placed last so that per-directory configuration can
|
|
402
|
+
override per-user configuration, which can override systemwide
|
|
403
|
+
configuration.
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
Forgetting imports
|
|
407
|
+
------------------
|
|
408
|
+
|
|
409
|
+
Occasionally you may have reason to tell pyflyby to "forget" entries from the
|
|
410
|
+
database of known imports.
|
|
411
|
+
|
|
412
|
+
You can put the following in any file reachable from ``$PYFLYBY_PATH``::
|
|
413
|
+
|
|
414
|
+
__forget_imports__ = ["from numpy import NaN"]
|
|
415
|
+
|
|
416
|
+
This is useful if you want to use a set of imports maintained by someone else
|
|
417
|
+
except for a few particular imports.
|
|
418
|
+
|
|
419
|
+
Entries in ``$PYFLYBY_PATH`` are processed left-to-right in the order specified,
|
|
420
|
+
so put the files containing these at the end of your ``$PYFLYBY_PATH``. By
|
|
421
|
+
default, ``tidy-imports`` and friends process ``/etc/pyflyby``, then ``~/.pyflyby``,
|
|
422
|
+
then the per-directory ``.pyflyby``.
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
Mandatory imports
|
|
426
|
+
-----------------
|
|
427
|
+
|
|
428
|
+
Within a certain project you may have a policy to always include certain
|
|
429
|
+
imports. For example, maybe you always want to do ``from __future__ import
|
|
430
|
+
division`` in all files.
|
|
431
|
+
|
|
432
|
+
You can put the following in any file reachable from ``$PYFLYBY_PATH``::
|
|
433
|
+
|
|
434
|
+
__mandatory_imports__ = ["from __future__ import division"]
|
|
435
|
+
|
|
436
|
+
To undo mandatory imports inherited from other ``.pyflyby`` files, use
|
|
437
|
+
``__forget_imports__`` (see above).
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
Canonicalize imports
|
|
441
|
+
--------------------
|
|
442
|
+
|
|
443
|
+
Sometimes you want every run of ``tidy-imports`` to automatically rename an import
|
|
444
|
+
to a new name.
|
|
445
|
+
|
|
446
|
+
You can put the following in any file reachable from ``$PYFLYBY_PATH``::
|
|
447
|
+
|
|
448
|
+
__canonical_imports__ = {"oldmodule.oldfunction": "newmodule.newfunction"}
|
|
449
|
+
|
|
450
|
+
This is equivalent to running::
|
|
451
|
+
|
|
452
|
+
tidy-imports --transform=oldmodule.oldfunction=newmodule.newfunction
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
Soapbox: avoid "star" imports
|
|
456
|
+
=============================
|
|
457
|
+
|
|
458
|
+
When programming in Python, a good software engineering practice is to avoid
|
|
459
|
+
using ``from foopackage import *`` in production code.
|
|
460
|
+
|
|
461
|
+
This style is a maintenance nightmare:
|
|
462
|
+
|
|
463
|
+
* It becomes difficult to figure out where various symbols
|
|
464
|
+
(functions/classes/etc) come from.
|
|
465
|
+
|
|
466
|
+
* It's hard to tell what gets shadowed by what.
|
|
467
|
+
|
|
468
|
+
* When the package changes in trivial ways, your code will be affected.
|
|
469
|
+
Consider the following example: Suppose ``foopackage.py`` contains ``import
|
|
470
|
+
sys``, and ``myprogram.py`` contains ``from foopackage import *; if
|
|
471
|
+
some_condition: sys.exit(0)``. If ``foopackage.py`` changes so that ``import
|
|
472
|
+
sys`` is removed, ``myprogram.py`` is now broken because it's missing ``import
|
|
473
|
+
sys``.
|
|
474
|
+
|
|
475
|
+
To fix such code, you can run ``tidy-imports --replace-star-imports`` to
|
|
476
|
+
automatically replace star imports with the specific needed imports.
|
|
477
|
+
|
|
478
|
+
Per-Project configuration of tidy-imports
|
|
479
|
+
=========================================
|
|
480
|
+
|
|
481
|
+
You can configure Pyflyby on a per-repository basis by using the
|
|
482
|
+
``[tool.pyflyby]`` section of ``pyproject.toml`` files. Pyflyby will look in current
|
|
483
|
+
working directory and all it's parent until it find a ``pyproject.toml`` file from
|
|
484
|
+
which it will load the defaults.
|
|
485
|
+
|
|
486
|
+
|
|
487
|
+
Most of the long command line flags default values can be configured in this
|
|
488
|
+
section. Simply use the long form option name by replacing dashes ``-`` by
|
|
489
|
+
underscore ``_``. For long option that have the form ``--xxx`` and ``--no-xxx``, you
|
|
490
|
+
can assign a boolean to ``xxx``. For example::
|
|
491
|
+
|
|
492
|
+
.. code:: toml
|
|
493
|
+
|
|
494
|
+
[tool.pyflyby]
|
|
495
|
+
add_missing=true
|
|
496
|
+
from_spaces=7
|
|
497
|
+
remove_unused=false
|
|
498
|
+
|
|
499
|
+
To exclude files from ``tidy-imports``, add an exclusion pattern to
|
|
500
|
+
``tool.pyflyby.tidy-imports.exclude``:
|
|
501
|
+
|
|
502
|
+
.. code:: toml
|
|
503
|
+
|
|
504
|
+
[tool.pyflyby.tidy-imports]
|
|
505
|
+
exclude = [
|
|
506
|
+
"foo.py",
|
|
507
|
+
"baz/*.py"
|
|
508
|
+
]
|
|
509
|
+
|
|
510
|
+
Exclusions are assumed to be relative to the project root if a ``pyproject.toml`` exists, unless an
|
|
511
|
+
absolute path is specified. Consult the documentation for ``pathlib.Path.match`` for information about
|
|
512
|
+
valid exclusion patterns.
|
|
513
|
+
|
|
514
|
+
Emacs support
|
|
515
|
+
=============
|
|
516
|
+
|
|
517
|
+
* To get a ``M-x tidy-imports`` command in GNU Emacs, add to your ``~/.emacs``::
|
|
518
|
+
|
|
519
|
+
(load "/<site-packages>/pyflyby/share/emacs/site-lisp/pyflyby.el")
|
|
520
|
+
|
|
521
|
+
|
|
522
|
+
- Pyflyby.el doesn't yet work with XEmacs; patches welcome.
|
|
523
|
+
|
|
524
|
+
|
|
525
|
+
saveframe: A utility for debugging / reproducing an issue
|
|
526
|
+
=========================================================
|
|
527
|
+
|
|
528
|
+
PyFlyBy provides a utility named **saveframe** which can be used to save
|
|
529
|
+
information for debugging / reproducing an issue.
|
|
530
|
+
|
|
531
|
+
**Usage**: If you have a piece of code or a script that is failing due an issue
|
|
532
|
+
originating from upstream code, and you cannot share your private code as a reproducer,
|
|
533
|
+
use this utility to save relevant information to a file. Share the generated file with
|
|
534
|
+
the upstream team, enabling them to reproduce and diagnose the issue independently.
|
|
535
|
+
|
|
536
|
+
**Information saved in the file**: This utility captures and saves *error stack frames*
|
|
537
|
+
to a file. It includes the values of local variables from each stack frame, as well
|
|
538
|
+
as metadata about each frame and the exception raised by your code.
|
|
539
|
+
|
|
540
|
+
This utility comes with 2 interfaces:
|
|
541
|
+
|
|
542
|
+
1. **A function**: For interactive usages such as IPython, Jupyter Notebook, or a
|
|
543
|
+
debugger (pdb/ipdb), use **pyflyby.saveframe** function. To know how to use this
|
|
544
|
+
function, checkout it's documentation:
|
|
545
|
+
|
|
546
|
+
.. code::
|
|
547
|
+
|
|
548
|
+
In [1]: saveframe?
|
|
549
|
+
|
|
550
|
+
2. **A script**: For cli usages (like a failing script), use **pyflyby/bin/saveframe**
|
|
551
|
+
script. To know how to use this script, checkout its documentation:
|
|
552
|
+
|
|
553
|
+
.. code::
|
|
554
|
+
|
|
555
|
+
$ saveframe --help
|
|
556
|
+
|
|
557
|
+
Authorship
|
|
558
|
+
==========
|
|
559
|
+
|
|
560
|
+
This plugin was contributed back to the community by the `D. E. Shaw group
|
|
561
|
+
<https://www.deshaw.com/>`_.
|
|
562
|
+
|
|
563
|
+
.. image:: https://www.deshaw.com/assets/logos/blue_logo_417x125.png
|
|
564
|
+
:target: https://www.deshaw.com
|
|
565
|
+
:height: 75 px
|
|
566
|
+
|
|
567
|
+
Pyflyby is written by Karl Chen <quarl@8166.clguba.z.quarl.org>
|
|
568
|
+
|
|
569
|
+
We love contributions! Before you can contribute, please sign and submit this
|
|
570
|
+
`Contributor License Agreement (CLA) <https://www.deshaw.com/oss/cla>`_.
|
|
571
|
+
This CLA is in place to protect all users of this project.
|
|
572
|
+
|
|
573
|
+
License
|
|
574
|
+
=======
|
|
575
|
+
|
|
576
|
+
Pyflyby is released under a very permissive license, the MIT/X11 license; see
|
|
577
|
+
LICENSE.txt.
|
|
578
|
+
|
|
579
|
+
|
|
580
|
+
Release
|
|
581
|
+
=======
|
|
582
|
+
|
|
583
|
+
1. Check version number in `lib/python/pyflyby/_version.py`, maybe increase it.
|
|
584
|
+
2. Commit and tag if necessary, and push tags/commits.
|
|
585
|
+
3. Optional: Set SOURCE_DATE_EPOCH for reproducible build::
|
|
586
|
+
|
|
587
|
+
export SOURCE_DATE_EPOCH=$(git show -s --format=%ct HEAD)
|
|
588
|
+
|
|
589
|
+
4. Build the SDIST::
|
|
590
|
+
|
|
591
|
+
python setup.py sdist
|
|
592
|
+
|
|
593
|
+
5. Optional Repack the Sdist to make sure the ZIP only contain SOURCE_DATE_EPOCH
|
|
594
|
+
date using IPython tools::
|
|
595
|
+
|
|
596
|
+
python ~/dev/ipython/tools/retar.py dist/pyflyby-1.7.8.tar.gz
|
|
597
|
+
shasum -a 256 dist/*
|
|
598
|
+
|
|
599
|
+
6. Optional, redo 4 & 5 to verify checksum is unchanged.
|
|
600
|
+
7. Upload using twine::
|
|
601
|
+
|
|
602
|
+
twine upload dist/*
|
|
603
|
+
|
|
604
|
+
8. Check/update https://github.com/conda-forge/pyflyby-feedstock for new pyflyby
|
|
605
|
+
release on conda-forge
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
pyflyby-1.10.4.data/scripts/collect-imports,sha256=8is1rLKRq-1mnyx3pDD7uBKEZt9C1sE1kWlyqpm2YaA,2141
|
|
2
|
+
pyflyby-1.10.4.data/scripts/tidy-imports,sha256=HmODd58QhWn6fap6-S5ohBy-qsLbnDnQa0uyYg5fNws,7035
|
|
3
|
+
pyflyby-1.10.4.data/scripts/transform-imports,sha256=IAMZTrHsZO5aRwF1exXGPhfL6UawUzJZmSl87K65elY,1450
|
|
4
|
+
pyflyby-1.10.4.data/scripts/replace-star-imports,sha256=7P8KbCX4K5cc6F-TT4KfGVeWkI0KWK38be8IRRyZfU8,913
|
|
5
|
+
pyflyby-1.10.4.data/scripts/find-import,sha256=_EmUDFQXCv_2tx79OyWBzdTKm_d8umVW7RY06jspYCE,932
|
|
6
|
+
pyflyby-1.10.4.data/scripts/prune-broken-imports,sha256=Wt2G8jTrVQKexUjqblrL5TXQfgRH3edctYukIBNZUVU,861
|
|
7
|
+
pyflyby-1.10.4.data/scripts/collect-exports,sha256=AqGNj2BuIK8RpqLCZJ5Rokqj1Kk4nJYcw9aKFkb96OI,2863
|
|
8
|
+
pyflyby-1.10.4.data/scripts/reformat-imports,sha256=PIT4kqE_1HenKvtDSpmyH386Ht5HvT1JlWjSb5mja8w,690
|
|
9
|
+
pyflyby-1.10.4.data/scripts/saveframe,sha256=bqU58kNDConm51zTpM3J37c-uhlDo-Uj8fOQ-rnYhwM,12074
|
|
10
|
+
pyflyby-1.10.4.data/scripts/pyflyby-diff,sha256=TqnG5jATcv9qU2HTuq2mQmb9m_jAjUfNQ4VIUnu5cK8,949
|
|
11
|
+
pyflyby-1.10.4.dist-info/RECORD,,
|
|
12
|
+
pyflyby-1.10.4.dist-info/WHEEL,sha256=G_dfdI4VdFFEoV4o13vwbe2p3zT46AbukmXzkfYuyPI,122
|
|
13
|
+
pyflyby-1.10.4.dist-info/entry_points.txt,sha256=aGXu4O2RcVf2hy1daq-edciSegKffMs7GDat7G-2p3k,70
|
|
14
|
+
pyflyby-1.10.4.dist-info/METADATA,sha256=ZIS_bdKYovKDIe55qWgVhUf0XDp_6D76o-Vr5Y5Uxu8,18053
|
|
15
|
+
pyflyby-1.10.4.dist-info/licenses/LICENSE.txt,sha256=mRQa9S9L6iMQQTv26s6u8v6EVPsDZi1YVL7J4Ryz_Z0,1086
|
|
16
|
+
pyflyby/_idents.py,sha256=-P-_n15PAIY05rFQ8wEIwblQrCuF4jpJNWQwZYwJvSI,6639
|
|
17
|
+
pyflyby/_importstmt.py,sha256=GM4TDdgzuikvtOjGeJ8F7cVI-noTjRjbqj0REt642t4,23794
|
|
18
|
+
pyflyby/_livepatch.py,sha256=4PRwpGwYEKqrwsON-ko7H_skZjcZhHCzepsjjfyOots,29450
|
|
19
|
+
pyflyby/_flags.py,sha256=ln-jkzTAiImrC6VB9ENlfjtlIAJp-b50wgWexfFAURw,7201
|
|
20
|
+
pyflyby/_version.py,sha256=RN_AmlJea-OnMbBDaKBcnc5uy6qEyMNeXoqUBqezFos,215
|
|
21
|
+
pyflyby/_importclns.py,sha256=BB8Zf-XIuQhnW1hMYQXreTNHOsDk7aZlQBYYb2x7bWY,22702
|
|
22
|
+
pyflyby/_saveframe_reader.py,sha256=8VDN3W13Tb2D_L7QFdR7u9VwPuNxA8AeRsgzajY-dWI,18548
|
|
23
|
+
pyflyby/_cmdline.py,sha256=r4zoGCu9jPE-ZaHmi5PZZiHWR5W7nwEfWSnH0IzpvDo,22123
|
|
24
|
+
pyflyby/_fast_iter_modules.cpython-311-darwin.so,sha256=f0A4NkFf5E_6MRHwGOoEqR5G9eiFQSRLlWdZBco1Rzg,202312
|
|
25
|
+
pyflyby/_comms.py,sha256=Q3JTbNqkHUw49laMQkFbqCs0FxDy6mi9V2glwdbwfEI,8249
|
|
26
|
+
pyflyby/__init__.py,sha256=sfTZU9wfNQPpgciMJg8lgtu_YagJflnoB-kjnI33css,2918
|
|
27
|
+
pyflyby/_file.py,sha256=ooM0StVzbhcpcvJGcsx-asXfe7QG0xfs_N-xUpTaqrQ,24449
|
|
28
|
+
pyflyby/_dbg.py,sha256=YHDQmRiSa75FhNIczWF7Rzns0qud0pPtzxseOvrrtPw,47510
|
|
29
|
+
pyflyby/_importdb.py,sha256=Nmg34xvImhgwIeCM1rVkL3hC-hoCvThfcyISIH5HRk0,19017
|
|
30
|
+
pyflyby/_py.py,sha256=H4DOHjIG7RJcSaHS74uXqL4lvVAkgqzVw541MRWG0dQ,80414
|
|
31
|
+
pyflyby/_format.py,sha256=GQu6QwFnVJkqEUlru6eZUpEq8Ym14vcwT7KfUrTdXx4,7038
|
|
32
|
+
pyflyby/_autoimp.py,sha256=AdCrlRXXN1P1ZnVOjWSAUDZBtC_m2Ydo0R95bfGOf3E,87662
|
|
33
|
+
pyflyby/_util.py,sha256=I_sYNeJ7buzCAYXTef4nmQ_lWZR5EXZOL3bJoeY6QuQ,13840
|
|
34
|
+
pyflyby/_parse.py,sha256=ObfuMX5piOlOEhwAYhYzPmeERKAVSy3n37senVPKIlk,49837
|
|
35
|
+
pyflyby/_import_sorting.py,sha256=msK8Fp9yew1qpVDXinB2fEcsVTcadE0TEbX8TvwbIV0,5756
|
|
36
|
+
pyflyby/_interactive.py,sha256=nyjsM6QaTqhXJDZ153JoQANmAS2hE5bwMbkrOTFFmg8,83743
|
|
37
|
+
pyflyby/importdb.py,sha256=ClY6LeBuWcPGuia3S05JDlbQQyl79D3QoGy_ciUWSDk,494
|
|
38
|
+
pyflyby/_dynimp.py,sha256=y0_RFYAAXOEr8-DYkGfYyFF6z_jkyHZYQXTm40Z54_s,4319
|
|
39
|
+
pyflyby/_modules.py,sha256=jK_qccF2xOi58NMKozcZvS3Y3WSp6qUxZchc6R12vTQ,22989
|
|
40
|
+
pyflyby/_imports2s.py,sha256=NFQ1njNIxlCaEjiJBY0F5nUdhdoUiYxhqEpZli4QtCo,24675
|
|
41
|
+
pyflyby/__main__.py,sha256=F_so6X2LPdGUrTWjYvRaTOHHXxCmTGPsp5KcX-Vl6Eo,190
|
|
42
|
+
pyflyby/_saveframe.py,sha256=pqWvgAYjIxotNvNxIlSS3hrOOITWkfoz6rifnHUgSUA,45992
|
|
43
|
+
pyflyby/_log.py,sha256=rKzH0imCoqBvj7lhymE2Peym1nxNT5nJFqXaMIX7qiI,2994
|
|
44
|
+
pyflyby/autoimport.py,sha256=GsdvaAmsVepkrR9vHtRkdXVrAqQoCG1OrOxUVOkuFc0,487
|
|
45
|
+
pyflyby/libexec/pyflyby/diff-colorize,sha256=S6wfKHEafQ9DFqiDvnnd70lrS71n1r1Tm9o2-FwxFgQ,5578
|
|
46
|
+
pyflyby/libexec/pyflyby/colordiff,sha256=TqnG5jATcv9qU2HTuq2mQmb9m_jAjUfNQ4VIUnu5cK8,949
|
|
47
|
+
pyflyby/etc/pyflyby/forget.py,sha256=N0xucS19eeoSS-BKXUI4bgwYrk4yWBOX3cVY0EC4KQE,369
|
|
48
|
+
pyflyby/etc/pyflyby/mandatory.py,sha256=-E52J_y2-Xu-YOHzoXiGVlCXcZqkEK4abVv7dQSNSgY,352
|
|
49
|
+
pyflyby/etc/pyflyby/std.py,sha256=pDFU6DDwZZLYD4itkimTI0fljsp4C4EO8fj5_wW21Vo,17596
|
|
50
|
+
pyflyby/etc/pyflyby/numpy.py,sha256=LtAWlytttnw72IcA20z327rdRi_P3dXnRbb41mWJ0K0,10469
|
|
51
|
+
pyflyby/etc/pyflyby/common.py,sha256=N1o3hkdjRH5qcu-HrgseThCF6olu1Yny53wlvZUR54c,597
|
|
52
|
+
pyflyby/etc/pyflyby/canonical.py,sha256=AEkiB4K19Pw4eKCns5dhnFXMmOJnRuwmly9RYihUwXM,270
|
|
53
|
+
pyflyby/share/emacs/site-lisp/pyflyby.el,sha256=dTH_reDok1yOKwN8T5QJFtPGqkMj9aFqxKB_9pWYBiY,4329
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Pyflyby: Copyright (c) 2011, 2012, 2013, 2014, 2015 Karl Chen
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
SOFTWARE.
|