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,23 @@
|
|
|
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.
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
Docxref.py includes code derived from Epydoc, which is also distributed under
|
|
23
|
+
the same MIT license.
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
|
|
2
|
+
- Support removing imports at any level, not just top-level.
|
|
3
|
+
- Support adding imports inside functions. Guess that an import should be
|
|
4
|
+
local if there were any other local imports from the same module.
|
|
5
|
+
- Allow options in .pyflyby files such as __options__ = '--uniform'
|
|
6
|
+
- Allow an option in .pyflyby files that means "stop processing further
|
|
7
|
+
database files"
|
|
8
|
+
- Heuristically guess alignment style from existing code
|
|
9
|
+
- Grouping: Teach tidy-imports to canonicalize import groups. 3 possiblities:
|
|
10
|
+
(1) Follow PEP8 standard library imports, then third-party imports, then
|
|
11
|
+
local app imports. http://legacy.python.org/dev/peps/pep-0008/#imports. Best
|
|
12
|
+
default. (2) The Eclipse way: for each top-level package, if there is more
|
|
13
|
+
than one import statement, then make those a group. (3) User-configured
|
|
14
|
+
grouping.
|
|
15
|
+
- Use rope?
|
|
16
|
+
- Allow comments in a file to specify imports that shouldn't be removed,
|
|
17
|
+
including "*" to mean don't-remove-any.
|
|
18
|
+
- Allow a comment in the file to specify alignment options.
|
|
19
|
+
- Guess the module name for relative imports.
|
|
20
|
+
- Preserve comments on import lines (as much as possible anyway - may need to
|
|
21
|
+
make them standalone comments).
|
|
22
|
+
- Preserve line ending style (\r\n).
|
|
23
|
+
- Merge share/pyflyby/*.py into a single file.
|
|
24
|
+
- Make sure etc/pyflyby works for both systemwide installation and virtualenv
|
|
25
|
+
installation
|
|
26
|
+
- Consider making the default database file more like a sample file that the
|
|
27
|
+
user is instructed to cp to ~/.pyflyby. What about existing users of older
|
|
28
|
+
versions? Perhaps have an auto-upgrade feature
|
|
29
|
+
- Refactor autoimport.py to share more with rest of pyflyby, esp AST parsing.
|
|
30
|
+
- Consider __mandatory_imports -= [...] instead of __forget_imports__=[...].
|
|
31
|
+
- Packaging:
|
|
32
|
+
- Make 'install' put etc in /etc outside egg (but inside virtualenv is
|
|
33
|
+
ok). Or think about the right way to do config files otherwise.
|
|
34
|
+
- Avoid compiling etc files to .pyc.
|
|
35
|
+
- Make bin/tidy-imports work out of the box after sdist+unpack. Currently
|
|
36
|
+
sdist doesn't include the bin/pyflyby symlink.
|
|
37
|
+
- Make zip-safe/PEP308 compliant; use pkg_resources (if possible) instead
|
|
38
|
+
of __file__.
|
|
39
|
+
- If fail to import something, remove it (and children) from known imports.
|
|
40
|
+
- Autopython script
|
|
41
|
+
- Make naming consistent: auto_importer vs autoimporter
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
- Add pretty-printing parameter --groupimports=manual|pep8|java, new default
|
|
45
|
+
pep8.
|
|
46
|
+
- Pep8 grouping:
|
|
47
|
+
- stdlib, then third-party libs, then first-party libs
|
|
48
|
+
- guess whether the current file is in the same package as an
|
|
49
|
+
import by checking if imported_pkg.split(".")[0] in filename.split("/").
|
|
50
|
+
- But how do we distinguish some random local module from third-party
|
|
51
|
+
libraries? Import it and check if path is in sys.path excluding current
|
|
52
|
+
dir? Not satisfying but can't think of anything better.
|
|
53
|
+
- stdlib before third-party libs. Need a list of stdlibs.
|
|
54
|
+
I guess we should include e.g. argparse regardless of the python version,
|
|
55
|
+
since we don't want the grouping to change depending on python version.
|
|
56
|
+
Maybe just use a (cogged) hardcoded list of modules.
|
|
57
|
+
|
|
58
|
+
- pyflyby_path importdb: require that components start with "/" or "./" or
|
|
59
|
+
".../"; i.e. don't allow "foo/bar"; tell user to use "./foo/bar" if that's
|
|
60
|
+
what he wants. Test case.
|
|
61
|
+
- Pyflyby_path: make sure that empty strings are ignored, not treated as ".".
|
|
62
|
+
Test case.
|
|
63
|
+
- py --safe: pyflyby_path=":" (not empty string, because that means "use
|
|
64
|
+
default")
|
|
65
|
+
|
|
66
|
+
- Allow non-imports in import db? Warn or allow silently? Indicate mode
|
|
67
|
+
somehow? We want to allow setting pyflyby_path to the directory of code and
|
|
68
|
+
use it without having to maintain an importdb. But don't make regular
|
|
69
|
+
.pyflyby databases sloppy.
|
|
70
|
+
|
|
71
|
+
- collect-exports: new mode that parses file and enumerates "stores", instead
|
|
72
|
+
of executing code.
|
|
73
|
+
|
|
74
|
+
- Unify collect-imports/collect-exports/collect-exports-from-stores into a
|
|
75
|
+
single script with a mode argument. Also parameters for whether to include
|
|
76
|
+
things imported from submodules (default on) and whether to include things
|
|
77
|
+
imported from other packages (default off).
|
|
78
|
+
|
|
79
|
+
- Add tidy-imports, etc to py
|
|
80
|
+
|
|
81
|
+
- Merge contents of all scripts into modules, and use setup.py entry_points.
|
|
82
|
+
Keep stub scripts in bin directory only for non-installed usage.
|
|
83
|
+
|
|
84
|
+
- Support pypy. It seems to already work fine in casual tests, but tox and
|
|
85
|
+
maybe setup.py need tweaking
|
|
86
|
+
|
|
87
|
+
- Transforms: support 'from a import b' => 'from c import d' (plus global
|
|
88
|
+
replace b=>d) in addition to 'from a import b' => 'from c import d as b'
|
|
89
|
+
|
|
90
|
+
- Make tidy-imports support detecting that print_function is necessary but
|
|
91
|
+
missing, and add it.
|
|
92
|
+
|
|
93
|
+
- Tidy-imports for notebooks: add all necessary imports to cells (either at
|
|
94
|
+
the top or per cell)
|
|
95
|
+
|
|
96
|
+
- Fix issue where properties get evaluated by pyflyby and then again by
|
|
97
|
+
ipython. E.g. repeated print output in test_complete_symbol_nonmodule_1.
|
|
98
|
+
We can't avoid pyflyby evaluating the property. But is there some way to
|
|
99
|
+
intercept ipython's subsequent evaluation and reuse the same result?
|
|
100
|
+
|
|
101
|
+
- Spyder: Fix pyflyby output coming during tab completion messing up the
|
|
102
|
+
display. May need to fix in Spyder itself.
|
|
103
|
+
|
|
104
|
+
- Handle comments between concatenate strings, e.g.: 'myvar =
|
|
105
|
+
("xx"\n#blah\n"yy")', e.g. in test_interactive.py.
|
|
106
|
+
|
|
107
|
+
- Function & interactive command to automatically add interactively-typed
|
|
108
|
+
imports to ~/.pyflyby.
|
|
109
|
+
|
|
110
|
+
- Store all interactively-typed imports to an area that can be consulted to
|
|
111
|
+
print out but don't automatically use
|
|
112
|
+
|
|
113
|
+
- Integration with search pydoc index for where to get import - but don't use
|
|
114
|
+
it automatically, just print it out and ask user if he wants to add it to
|
|
115
|
+
database
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
|
|
2
|
+
(require 'find-func) ;; for find-library-name
|
|
3
|
+
|
|
4
|
+
(defvar pyflyby-bin-path
|
|
5
|
+
;; Try to find the bin path based on where pyflyby.el lives.
|
|
6
|
+
(let* ((pyflyby-el-name
|
|
7
|
+
(or load-file-name
|
|
8
|
+
(ignore-errors (find-library-name "pyflyby"))
|
|
9
|
+
"pyflyby.el"))
|
|
10
|
+
(module-path (file-truename pyflyby-el-name))
|
|
11
|
+
(binpath (file-truename
|
|
12
|
+
(concat (file-name-directory module-path) "../../bin"))))
|
|
13
|
+
(and (file-directory-p binpath) binpath))
|
|
14
|
+
"Path containing pyflyby executables.")
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
(defun pyflyby--pipe-to-command (start end program &rest args)
|
|
18
|
+
"Send text from START to END to process running PROGRAM ARGS.
|
|
19
|
+
|
|
20
|
+
Returns (exit-value stdout stderr)."
|
|
21
|
+
;; Yuck: call-process-region can only redirect stderr to a file, not to a
|
|
22
|
+
;; buffer/string.
|
|
23
|
+
(let* ((stdout-buffer (generate-new-buffer " *pyflyby stdout*"))
|
|
24
|
+
(stderr-buffer (generate-new-buffer " *pyflyby stderr*"))
|
|
25
|
+
(stderr-file (make-temp-file
|
|
26
|
+
(expand-file-name
|
|
27
|
+
"pyflyby-log."
|
|
28
|
+
(or small-temporary-file-directory
|
|
29
|
+
temporary-file-directory))))
|
|
30
|
+
(exec-path (if pyflyby-bin-path
|
|
31
|
+
(cons pyflyby-bin-path exec-path) exec-path))
|
|
32
|
+
(exit-value (apply 'call-process-region
|
|
33
|
+
start end program nil
|
|
34
|
+
(list stdout-buffer stderr-file)
|
|
35
|
+
nil args))
|
|
36
|
+
(stdout-text (with-current-buffer stdout-buffer (buffer-string)))
|
|
37
|
+
(stderr-text (with-current-buffer stderr-buffer
|
|
38
|
+
(format-insert-file stderr-file nil)
|
|
39
|
+
(buffer-string))))
|
|
40
|
+
(delete-file stderr-file)
|
|
41
|
+
(kill-buffer stdout-buffer)
|
|
42
|
+
(kill-buffer stderr-buffer)
|
|
43
|
+
(list exit-value stdout-text stderr-text)))
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
(defun pyflyby--replace-text (text)
|
|
47
|
+
"Replace current buffer with TEXT.
|
|
48
|
+
|
|
49
|
+
Tries to keep point in the same place."
|
|
50
|
+
(let* ((p (point))
|
|
51
|
+
(ptext (buffer-substring-no-properties
|
|
52
|
+
p (min (point-max) (+ p 1000))))
|
|
53
|
+
(size (buffer-size)))
|
|
54
|
+
;; Replace the buffer.
|
|
55
|
+
(erase-buffer)
|
|
56
|
+
(insert text)
|
|
57
|
+
;; Go to previously saved point. We don't use save-excursion
|
|
58
|
+
;; since that doesn't work when the whole buffer is replaced,
|
|
59
|
+
;; destroying markers. First see if the position matches when
|
|
60
|
+
;; counting from end of the buffer.
|
|
61
|
+
(setq p (max 0 (+ p (buffer-size) (- size))))
|
|
62
|
+
(goto-char p)
|
|
63
|
+
(unless (search-forward ptext (+ p 1) t)
|
|
64
|
+
;; Next, try searching for the location based on text near old
|
|
65
|
+
;; point.
|
|
66
|
+
(goto-char (- p 500))
|
|
67
|
+
(if (search-forward ptext (+ p 1000) t)
|
|
68
|
+
(goto-char (match-beginning 0))
|
|
69
|
+
(goto-char p)))
|
|
70
|
+
(recenter)))
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
(defun pyflyby-transform-region-with-command (command &rest args)
|
|
74
|
+
(unless (eq major-mode 'python-mode)
|
|
75
|
+
(error "Pyflyby should only be used on python buffers"))
|
|
76
|
+
(let* ((result
|
|
77
|
+
(apply 'pyflyby--pipe-to-command (point-min) (point-max) command args))
|
|
78
|
+
(exit-value (nth 0 result))
|
|
79
|
+
(newtext (nth 1 result))
|
|
80
|
+
(logtext (nth 2 result))
|
|
81
|
+
(logtext (replace-regexp-in-string "/dev/stdin: ?" "" logtext nil t))
|
|
82
|
+
(nlogtext (if (= 0 (length logtext)) "" (concat "\n" logtext))))
|
|
83
|
+
(if (= exit-value 0)
|
|
84
|
+
;; Process exited successfully.
|
|
85
|
+
(if (string= newtext
|
|
86
|
+
(buffer-substring-no-properties (point-min) (point-max)))
|
|
87
|
+
;; No change.
|
|
88
|
+
(message "No changes by `%s'.%s" command nlogtext)
|
|
89
|
+
;; There were changes.
|
|
90
|
+
(pyflyby--replace-text newtext)
|
|
91
|
+
(message logtext))
|
|
92
|
+
;; Process failed.
|
|
93
|
+
(error "%s failed with exit code %d.%s" command exit-value logtext))))
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
(defun pyflyby-tidy-imports ()
|
|
97
|
+
(interactive "*")
|
|
98
|
+
(pyflyby-transform-region-with-command "tidy-imports"))
|
|
99
|
+
|
|
100
|
+
(defun pyflyby-reformat-imports ()
|
|
101
|
+
(interactive "*")
|
|
102
|
+
(pyflyby-transform-region-with-command "reformat-imports"))
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
(defalias 'tidy-imports 'pyflyby-tidy-imports)
|
|
106
|
+
(defalias 'reformat-imports 'pyflyby-reformat-imports)
|
|
107
|
+
|
|
108
|
+
(provide 'pyflyby)
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
#!python
|
|
2
|
+
"""
|
|
3
|
+
collect-exports module1 module2...
|
|
4
|
+
|
|
5
|
+
Collect all exports in the specified modules and generate "from foo import
|
|
6
|
+
..." lines for public members defined in those modules.
|
|
7
|
+
|
|
8
|
+
Print the result to stdout.
|
|
9
|
+
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
# pyflyby/collect-exports
|
|
13
|
+
# Copyright (C) 2011, 2012, 2013, 2014 Karl Chen.
|
|
14
|
+
# License: MIT http://opensource.org/licenses/MIT
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
import sys
|
|
19
|
+
|
|
20
|
+
from pyflyby._cmdline import hfmt, parse_args
|
|
21
|
+
from pyflyby._importdb import ImportDB
|
|
22
|
+
from pyflyby._log import logger
|
|
23
|
+
from pyflyby._modules import ModuleHandle
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def main():
|
|
27
|
+
def addopts(parser):
|
|
28
|
+
parser.add_option("--ignore-known", default=False, action='store_true',
|
|
29
|
+
help=hfmt('''
|
|
30
|
+
Don't list imports already in the
|
|
31
|
+
known-imports database.'''))
|
|
32
|
+
parser.add_option("--no-ignore-known", dest="ignore_known",
|
|
33
|
+
action='store_false',
|
|
34
|
+
help=hfmt('''
|
|
35
|
+
(Default) List all imports, including those
|
|
36
|
+
already in the known-imports database.'''))
|
|
37
|
+
parser.add_option("--expand-known", default=False, action='store_true',
|
|
38
|
+
help=hfmt('''
|
|
39
|
+
Scan all modules mentioned in known-imports
|
|
40
|
+
database.'''))
|
|
41
|
+
parser.add_option("--no-expand-known", dest="expand_known",
|
|
42
|
+
action='store_false',
|
|
43
|
+
help=hfmt('''
|
|
44
|
+
(Default) Scan only modules listed explicitly
|
|
45
|
+
on the command line.'''))
|
|
46
|
+
options, args = parse_args(addopts, import_format_params=True)
|
|
47
|
+
if options.expand_known:
|
|
48
|
+
db = ImportDB.get_default(".")
|
|
49
|
+
known = db.known_imports.imports
|
|
50
|
+
args += sorted(set(
|
|
51
|
+
[_f for _f in [i.split.module_name for i in known] if _f]))
|
|
52
|
+
bad_module_names = []
|
|
53
|
+
for module_name in args:
|
|
54
|
+
module = ModuleHandle(module_name)
|
|
55
|
+
try:
|
|
56
|
+
imports = module.exports
|
|
57
|
+
except Exception as e:
|
|
58
|
+
logger.warning("couldn't get exports for %s; ignoring: %s: %s",
|
|
59
|
+
module, type(e).__name__, e)
|
|
60
|
+
bad_module_names.append(module_name)
|
|
61
|
+
continue
|
|
62
|
+
if not imports:
|
|
63
|
+
continue
|
|
64
|
+
if options.ignore_known:
|
|
65
|
+
db = ImportDB.get_default(module.__file__)
|
|
66
|
+
imports = imports.without_imports(db)
|
|
67
|
+
sys.stdout.write(imports.pretty_print(
|
|
68
|
+
allow_conflicts=True, params=options.params))
|
|
69
|
+
if bad_module_names:
|
|
70
|
+
print("collect-exports: there were problems with: %s" % (
|
|
71
|
+
' '.join(bad_module_names)), file=sys.stderr)
|
|
72
|
+
sys.exit(1)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
if __name__ == '__main__':
|
|
76
|
+
main()
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
#!python
|
|
2
|
+
"""
|
|
3
|
+
collect-imports *.py
|
|
4
|
+
collect-imports < foo.py
|
|
5
|
+
|
|
6
|
+
Collect all imports from named files or stdin, and combine them into a single
|
|
7
|
+
block of import statements. Print the result to stdout.
|
|
8
|
+
|
|
9
|
+
"""
|
|
10
|
+
# pyflyby/collect-imports
|
|
11
|
+
# Copyright (C) 2011, 2014 Karl Chen.
|
|
12
|
+
# License: MIT http://opensource.org/licenses/MIT
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
import re
|
|
16
|
+
import sys
|
|
17
|
+
|
|
18
|
+
from pyflyby._cmdline import filename_args, hfmt, parse_args
|
|
19
|
+
from pyflyby._importclns import ImportSet
|
|
20
|
+
from pyflyby._importdb import ImportDB
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def main():
|
|
24
|
+
def addopts(parser):
|
|
25
|
+
parser.add_option("--ignore-known", default=False, action='store_true',
|
|
26
|
+
help=hfmt('''
|
|
27
|
+
Don't list imports already in the
|
|
28
|
+
known-imports database.'''))
|
|
29
|
+
parser.add_option("--no-ignore-known", dest="ignore_known",
|
|
30
|
+
action='store_false',
|
|
31
|
+
help=hfmt('''
|
|
32
|
+
(Default) List all imports, including those
|
|
33
|
+
already in the known-imports database.'''))
|
|
34
|
+
parser.add_option("--include",
|
|
35
|
+
default=[], action="append",
|
|
36
|
+
help=hfmt('''
|
|
37
|
+
Include only imports under the given package.'''))
|
|
38
|
+
options, args = parse_args(addopts, import_format_params=True)
|
|
39
|
+
filenames = filename_args(args)
|
|
40
|
+
importset = ImportSet(filenames, ignore_nonimports=True)
|
|
41
|
+
if options.include:
|
|
42
|
+
regexps = [
|
|
43
|
+
re.escape(prefix) if prefix.endswith(".") else
|
|
44
|
+
re.escape(prefix) + "([.]|$)"
|
|
45
|
+
for prefix in options.include
|
|
46
|
+
]
|
|
47
|
+
regexp = re.compile("|".join(regexps))
|
|
48
|
+
match = lambda imp: regexp.match(imp.fullname)
|
|
49
|
+
importset = ImportSet([imp for imp in importset if match(imp)])
|
|
50
|
+
if options.ignore_known:
|
|
51
|
+
db = ImportDB.get_default(".")
|
|
52
|
+
importset = importset.without_imports(db.known_imports)
|
|
53
|
+
sys.stdout.write(importset.pretty_print(
|
|
54
|
+
allow_conflicts=True, params=options.params))
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
if __name__ == '__main__':
|
|
58
|
+
main()
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!python
|
|
2
|
+
"""
|
|
3
|
+
Usage: find-import names...
|
|
4
|
+
|
|
5
|
+
Prints how to import given name(s).
|
|
6
|
+
"""
|
|
7
|
+
# pyflyby/find-import
|
|
8
|
+
# Copyright (C) 2011, 2014 Karl Chen.
|
|
9
|
+
# License: MIT http://opensource.org/licenses/MIT
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
from pyflyby._cmdline import parse_args, syntax
|
|
13
|
+
from pyflyby._importdb import ImportDB
|
|
14
|
+
from pyflyby._log import logger
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def main():
|
|
18
|
+
options, args = parse_args(import_format_params=True)
|
|
19
|
+
if not args:
|
|
20
|
+
syntax()
|
|
21
|
+
db = ImportDB.get_default(".")
|
|
22
|
+
known = db.known_imports.by_import_as
|
|
23
|
+
errors = 0
|
|
24
|
+
for arg in args:
|
|
25
|
+
try:
|
|
26
|
+
imports = known[arg]
|
|
27
|
+
except KeyError:
|
|
28
|
+
errors += 1
|
|
29
|
+
logger.error("Can't find import for %r", arg)
|
|
30
|
+
else:
|
|
31
|
+
for imp in imports:
|
|
32
|
+
print(imp.pretty_print(params=options.params), end=' ')
|
|
33
|
+
if errors:
|
|
34
|
+
raise SystemExit(1)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
if __name__ == '__main__':
|
|
38
|
+
main()
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#!python
|
|
2
|
+
"""
|
|
3
|
+
Usage: list-bad-xrefs modules... filenames...
|
|
4
|
+
|
|
5
|
+
Prints the bad docstring cross-references in the given modules.
|
|
6
|
+
|
|
7
|
+
Similar to running C{epydoc -v}, but:
|
|
8
|
+
- The output is organized so that it is easy to identify the code needing
|
|
9
|
+
fixing.
|
|
10
|
+
- If a cross-reference is to an external module, its references are included
|
|
11
|
+
automatically.
|
|
12
|
+
"""
|
|
13
|
+
# pyflyby/list-bad-xrefs
|
|
14
|
+
# Copyright (C) 2011, 2014 Karl Chen.
|
|
15
|
+
# License: MIT http://opensource.org/licenses/MIT
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
from pyflyby._cmdline import parse_args, syntax
|
|
19
|
+
from pyflyby._docxref import find_bad_doc_cross_references
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def main():
|
|
23
|
+
options, args = parse_args()
|
|
24
|
+
if not args:
|
|
25
|
+
syntax()
|
|
26
|
+
for rec in find_bad_doc_cross_references(args):
|
|
27
|
+
module, linenos, container_name, identifier = rec
|
|
28
|
+
for lineno in linenos or ["?"]:
|
|
29
|
+
print("%s:%s: undefined docstring cross-reference in %s: %s" % (
|
|
30
|
+
module.filename, lineno, container_name, identifier))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
if __name__ == '__main__':
|
|
34
|
+
main()
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#!python
|
|
2
|
+
"""
|
|
3
|
+
prune-broken-imports *.py
|
|
4
|
+
prune-broken-imports < foo.py
|
|
5
|
+
|
|
6
|
+
Removes broken imports.
|
|
7
|
+
|
|
8
|
+
Note: This actually executes imports.
|
|
9
|
+
|
|
10
|
+
If filenames are given on the command line, rewrites them. Otherwise, if
|
|
11
|
+
stdin is not a tty, read from stdin and write to stdout.
|
|
12
|
+
|
|
13
|
+
Only top-level import statements are touched.
|
|
14
|
+
|
|
15
|
+
"""
|
|
16
|
+
# pyflyby/prune-broken-imports
|
|
17
|
+
# Copyright (C) 2012, 2014 Karl Chen.
|
|
18
|
+
# License: MIT http://opensource.org/licenses/MIT
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
from pyflyby._cmdline import parse_args, process_actions
|
|
22
|
+
from pyflyby._imports2s import remove_broken_imports
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def main():
|
|
26
|
+
options, args = parse_args(
|
|
27
|
+
import_format_params=True, modify_action_params=True)
|
|
28
|
+
def modify(x):
|
|
29
|
+
return remove_broken_imports(x, params=options.params)
|
|
30
|
+
process_actions(args, options.actions, modify)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
if __name__ == '__main__':
|
|
34
|
+
main()
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
#!/usr/bin/env -S bash -e
|
|
2
|
+
|
|
3
|
+
# License for THIS FILE ONLY: CC0 Public Domain Dedication
|
|
4
|
+
# http://creativecommons.org/publicdomain/zero/1.0/
|
|
5
|
+
|
|
6
|
+
# Get the directory containing to the symlink target of the script.
|
|
7
|
+
if script=$(readlink -e "$0" 2>/dev/null) && [[ "$script" -ef "$0" ]]; then
|
|
8
|
+
scriptdir=$(dirname "$script")
|
|
9
|
+
elif script=$(realpath "$0" 2>/dev/null) && [[ "$script" -ef "$0" ]]; then
|
|
10
|
+
scriptdir=$(dirname "$script")
|
|
11
|
+
elif script=$(greadlink -e "$0" 2>/dev/null) && [[ "$script" -ef "$0" ]]; then
|
|
12
|
+
scriptdir=$(dirname "$script")
|
|
13
|
+
else
|
|
14
|
+
scriptdir=$(
|
|
15
|
+
d=$(dirname "$0")
|
|
16
|
+
b=$(basename "$0")
|
|
17
|
+
cd "$d"
|
|
18
|
+
if l=$(readlink "$b"); then
|
|
19
|
+
ld=$(dirname "$l")
|
|
20
|
+
cd "$ld"
|
|
21
|
+
fi
|
|
22
|
+
pwd
|
|
23
|
+
)
|
|
24
|
+
fi
|
|
25
|
+
|
|
26
|
+
libexecdir="$scriptdir/../libexec/pyflyby"
|
|
27
|
+
|
|
28
|
+
PATH="$scriptdir:$libexecdir:$PATH"
|
|
29
|
+
|
|
30
|
+
if [[ -t 1 ]] && type -p diff-colorize >/dev/null; then
|
|
31
|
+
diff -u "$@" | diff-colorize
|
|
32
|
+
else
|
|
33
|
+
diff -u "$@"
|
|
34
|
+
fi
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#!python
|
|
2
|
+
"""
|
|
3
|
+
reformat-imports *.py
|
|
4
|
+
reformat-imports < foo.py
|
|
5
|
+
|
|
6
|
+
Reformats the top-level 'import' blocks within the python module/script.
|
|
7
|
+
|
|
8
|
+
"""
|
|
9
|
+
# pyflyby/reformat-imports
|
|
10
|
+
# Copyright (C) 2011, 2014 Karl Chen.
|
|
11
|
+
# License: MIT http://opensource.org/licenses/MIT
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
from pyflyby._cmdline import parse_args, process_actions
|
|
15
|
+
from pyflyby._imports2s import reformat_import_statements
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def main():
|
|
19
|
+
options, args = parse_args(
|
|
20
|
+
import_format_params=True, modify_action_params=True)
|
|
21
|
+
def modify(x):
|
|
22
|
+
return reformat_import_statements(x, params=options.params)
|
|
23
|
+
process_actions(args, options.actions, modify)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
if __name__ == '__main__':
|
|
27
|
+
main()
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
#!python
|
|
2
|
+
"""
|
|
3
|
+
replace-star-imports *.py
|
|
4
|
+
replace-star-imports < foo.py
|
|
5
|
+
|
|
6
|
+
Replaces::
|
|
7
|
+
from foo.bar import *
|
|
8
|
+
with::
|
|
9
|
+
from foo.bar import (f1, f2, ...)
|
|
10
|
+
|
|
11
|
+
Note: This actually executes imports.
|
|
12
|
+
|
|
13
|
+
If filenames are given on the command line, rewrites them. Otherwise, if
|
|
14
|
+
stdin is not a tty, read from stdin and write to stdout.
|
|
15
|
+
|
|
16
|
+
Only top-level import statements are touched.
|
|
17
|
+
|
|
18
|
+
"""
|
|
19
|
+
# pyflyby/replace-star-imports
|
|
20
|
+
# Copyright (C) 2012, 2014 Karl Chen.
|
|
21
|
+
# License: MIT http://opensource.org/licenses/MIT
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
from pyflyby._cmdline import parse_args, process_actions
|
|
25
|
+
from pyflyby._imports2s import replace_star_imports
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def main():
|
|
29
|
+
options, args = parse_args(
|
|
30
|
+
import_format_params=True, modify_action_params=True)
|
|
31
|
+
def modify(x):
|
|
32
|
+
return replace_star_imports(x, params=options.params)
|
|
33
|
+
process_actions(args, options.actions, modify)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
if __name__ == '__main__':
|
|
37
|
+
main()
|