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,148 @@
|
|
|
1
|
+
#!/usr/bin/env python
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import fileinput
|
|
5
|
+
import os
|
|
6
|
+
import re
|
|
7
|
+
import sys
|
|
8
|
+
|
|
9
|
+
# TERM could be e.g. xterm-256color or screen-256color.
|
|
10
|
+
has_256_color = ('-256col' in os.environ.get('TERM', ''))
|
|
11
|
+
|
|
12
|
+
index_color = int(os.environ.get('DIFF_INDEX_COLOR',
|
|
13
|
+
has_256_color and 32 or 36))
|
|
14
|
+
old_mode_color = int(os.environ.get('DIFF_OLD_MODE_COLOR',
|
|
15
|
+
has_256_color and 88 or 31))
|
|
16
|
+
new_mode_color = int(os.environ.get('DIFF_NEW_MODE_COLOR',
|
|
17
|
+
has_256_color and 28 or 32))
|
|
18
|
+
removed_color = int(os.environ.get('DIFF_REMOVED_COLOR',
|
|
19
|
+
has_256_color and 160 or 31))
|
|
20
|
+
added_color = int(os.environ.get('DIFF_ADDED_COLOR',
|
|
21
|
+
has_256_color and 2 or 32))
|
|
22
|
+
hunk_start_color = int(os.environ.get('DIFF_HUNK_START_COLOR',
|
|
23
|
+
has_256_color and 32 or 36))
|
|
24
|
+
trailing_whitespace_color = int(has_256_color and 236 or 8)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
RESET_FORMAT = '\033[0m'
|
|
28
|
+
COLOR_FORMAT_256 = '\033[38;5;%um'
|
|
29
|
+
COLOR_FORMAT_16 = '\033[38;%um'
|
|
30
|
+
BG_COLOR_FORMAT_256 = '\033[48;5;%um'
|
|
31
|
+
BG_COLOR_FORMAT_16 = '\033[48;%um'
|
|
32
|
+
COLOR_FORMAT = has_256_color and COLOR_FORMAT_256 or COLOR_FORMAT_16
|
|
33
|
+
BG_COLOR_FORMAT = has_256_color and BG_COLOR_FORMAT_256 or BG_COLOR_FORMAT_16
|
|
34
|
+
BEGIN_REVERSE_FORMAT = '\033[7m'
|
|
35
|
+
END_REVERSE_FORMAT = '\033[27m'
|
|
36
|
+
|
|
37
|
+
USAGE = """
|
|
38
|
+
Usage: diff ... | diff-colorize
|
|
39
|
+
or: diff-colorize < foo.diff
|
|
40
|
+
|
|
41
|
+
Reads unified or git-style diff data from standard input, colorizes it, and
|
|
42
|
+
writes the result to standard output.
|
|
43
|
+
""".strip()
|
|
44
|
+
|
|
45
|
+
# You can customize the color numbers used by setting these variables in your environment:
|
|
46
|
+
# * DIFF_INDEX_COLOR (lines starting with "Index: " or "diff --git ")
|
|
47
|
+
# * DIFF_OLD_MODE_COLOR (lines starting with "old mode"; these only appear in git-style diffs)
|
|
48
|
+
# * DIFF_NEW_MODE_COLOR (lines starting with "new mode"; these only appear in git-style diffs)
|
|
49
|
+
# * DIFF_REMOVED_COLOR (lines starting with "-")
|
|
50
|
+
# * DIFF_ADDED_COLOR (lines starting with "+")
|
|
51
|
+
# * DIFF_HUNK_START_COLOR (lines starting with "@@")
|
|
52
|
+
|
|
53
|
+
# Everything in the unified diff format is identified by a prefix. The prefixes are:
|
|
54
|
+
# 'Index: ': File marker (unified diff)
|
|
55
|
+
# 'diff --git': File marker (git-style diff)
|
|
56
|
+
# 'old mode': File permissions mode before change
|
|
57
|
+
# 'new mode': File permissions mode after change
|
|
58
|
+
# '---': Defining '-' (giving the name and modification date of the file before change)
|
|
59
|
+
# '+++': Defining '+' (giving the name and modification date of the file after change)
|
|
60
|
+
# '-': Line before change (i.e., removed)
|
|
61
|
+
# '+': Line after change (i.e., added)
|
|
62
|
+
# ' ': Line that hasn't changed
|
|
63
|
+
# '@@': Hunk start (@@ -start,length +start, length @@)
|
|
64
|
+
#
|
|
65
|
+
# We need to look for these prefixes in order, in order to handle '---'/'+++' before '-'/'+'. Hence the OrderedDict.
|
|
66
|
+
class OrderedDict(dict):
|
|
67
|
+
def __init__(self, input=None):
|
|
68
|
+
if input is None:
|
|
69
|
+
self.keys = []
|
|
70
|
+
super(OrderedDict, self).__init__()
|
|
71
|
+
elif isinstance(input, dict):
|
|
72
|
+
self.keys = list(input)
|
|
73
|
+
super(OrderedDict, self).__init__(input)
|
|
74
|
+
else:
|
|
75
|
+
self.keys = [k for k, v in input]
|
|
76
|
+
super(OrderedDict, self).__init__(input)
|
|
77
|
+
def __iter__(self):
|
|
78
|
+
return iter(self.keys)
|
|
79
|
+
def __setitem__(self, k, v):
|
|
80
|
+
if k not in self:
|
|
81
|
+
self.keys.append(k)
|
|
82
|
+
super(OrderedDict, self).__setitem__(k, v)
|
|
83
|
+
def __delitem__(self, k):
|
|
84
|
+
super(OrderedDict, self).__delitem__(k)
|
|
85
|
+
self.keys.remove(k)
|
|
86
|
+
|
|
87
|
+
# Each value includes not only the terminal-config characters, but also the key, somewhere within it (possibly between two terminal-config strings).
|
|
88
|
+
# Theoretically, you could replace the key with some other string or leave it out entirely, if you wanted to, but I wouldn't recommend it.
|
|
89
|
+
prefixes = OrderedDict()
|
|
90
|
+
prefixes['---'] = (
|
|
91
|
+
COLOR_FORMAT % (removed_color,)
|
|
92
|
+
+ BEGIN_REVERSE_FORMAT
|
|
93
|
+
+ '---'
|
|
94
|
+
+ END_REVERSE_FORMAT
|
|
95
|
+
)
|
|
96
|
+
prefixes['+++'] = (
|
|
97
|
+
COLOR_FORMAT % (added_color,)
|
|
98
|
+
+ BEGIN_REVERSE_FORMAT
|
|
99
|
+
+ '+++'
|
|
100
|
+
+ END_REVERSE_FORMAT
|
|
101
|
+
)
|
|
102
|
+
prefixes['-'] = (
|
|
103
|
+
COLOR_FORMAT % (removed_color,)
|
|
104
|
+
+ BEGIN_REVERSE_FORMAT
|
|
105
|
+
+ '-'
|
|
106
|
+
+ END_REVERSE_FORMAT
|
|
107
|
+
)
|
|
108
|
+
prefixes['+'] = (
|
|
109
|
+
COLOR_FORMAT % (added_color,)
|
|
110
|
+
+ BEGIN_REVERSE_FORMAT
|
|
111
|
+
+ '+'
|
|
112
|
+
+ END_REVERSE_FORMAT
|
|
113
|
+
)
|
|
114
|
+
prefixes['old mode'] = ( # Git-style diffs only
|
|
115
|
+
COLOR_FORMAT % (old_mode_color,)
|
|
116
|
+
+ BEGIN_REVERSE_FORMAT
|
|
117
|
+
+ 'old mode'
|
|
118
|
+
+ END_REVERSE_FORMAT
|
|
119
|
+
)
|
|
120
|
+
prefixes['new mode'] = ( # Git-style diffs only
|
|
121
|
+
COLOR_FORMAT % (new_mode_color,)
|
|
122
|
+
+ BEGIN_REVERSE_FORMAT
|
|
123
|
+
+ 'new mode'
|
|
124
|
+
+ END_REVERSE_FORMAT
|
|
125
|
+
)
|
|
126
|
+
prefixes['Index: '] = COLOR_FORMAT % (index_color,) + 'Index: '
|
|
127
|
+
prefixes['diff --git '] = COLOR_FORMAT % (index_color,) + 'diff --git '
|
|
128
|
+
prefixes['@@'] = (
|
|
129
|
+
COLOR_FORMAT % (hunk_start_color,)
|
|
130
|
+
# + BEGIN_REVERSE_FORMAT
|
|
131
|
+
+ '@@'
|
|
132
|
+
)
|
|
133
|
+
trailing_whitespace_repl = r'\1%s\2' % (BG_COLOR_FORMAT % (trailing_whitespace_color,),)
|
|
134
|
+
|
|
135
|
+
if sys.stdin.isatty():
|
|
136
|
+
# Standard input is a TTY, meaning that the user ran 'diff-colorize' at the shell prompt, without redirecting anything into it. Print usage info and exit.
|
|
137
|
+
sys.exit(USAGE)
|
|
138
|
+
|
|
139
|
+
for line in fileinput.input():
|
|
140
|
+
for prefix_to_test in prefixes:
|
|
141
|
+
if line.startswith(prefix_to_test):
|
|
142
|
+
sys.stdout.write(prefixes[prefix_to_test])
|
|
143
|
+
line = line[len(prefix_to_test):]
|
|
144
|
+
line = re.sub('([^ \t])([ \t]+)$', trailing_whitespace_repl, line)
|
|
145
|
+
|
|
146
|
+
sys.stdout.write(line)
|
|
147
|
+
|
|
148
|
+
sys.stdout.write(RESET_FORMAT)
|
|
@@ -0,0 +1,112 @@
|
|
|
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
|
+
;; Only recenter when the buffer is visible in a live window.
|
|
71
|
+
(let ((win (get-buffer-window (current-buffer) t)))
|
|
72
|
+
(when (and win (window-live-p win))
|
|
73
|
+
(with-selected-window win
|
|
74
|
+
(recenter))))))
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
(defun pyflyby-transform-region-with-command (command &rest args)
|
|
78
|
+
(unless (eq major-mode 'python-mode)
|
|
79
|
+
(error "Pyflyby should only be used on python buffers"))
|
|
80
|
+
(let* ((result
|
|
81
|
+
(apply 'pyflyby--pipe-to-command (point-min) (point-max) command args))
|
|
82
|
+
(exit-value (nth 0 result))
|
|
83
|
+
(newtext (nth 1 result))
|
|
84
|
+
(logtext (nth 2 result))
|
|
85
|
+
(logtext (replace-regexp-in-string "/dev/stdin: ?" "" logtext nil t))
|
|
86
|
+
(nlogtext (if (= 0 (length logtext)) "" (concat "\n" logtext))))
|
|
87
|
+
(if (= exit-value 0)
|
|
88
|
+
;; Process exited successfully.
|
|
89
|
+
(if (string= newtext
|
|
90
|
+
(buffer-substring-no-properties (point-min) (point-max)))
|
|
91
|
+
;; No change.
|
|
92
|
+
(message "No changes by `%s'.%s" command nlogtext)
|
|
93
|
+
;; There were changes.
|
|
94
|
+
(pyflyby--replace-text newtext)
|
|
95
|
+
(message logtext))
|
|
96
|
+
;; Process failed.
|
|
97
|
+
(error "%s failed with exit code %d.%s" command exit-value logtext))))
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
(defun pyflyby-tidy-imports ()
|
|
101
|
+
(interactive "*")
|
|
102
|
+
(pyflyby-transform-region-with-command "tidy-imports"))
|
|
103
|
+
|
|
104
|
+
(defun pyflyby-reformat-imports ()
|
|
105
|
+
(interactive "*")
|
|
106
|
+
(pyflyby-transform-region-with-command "reformat-imports"))
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
(defalias 'tidy-imports 'pyflyby-tidy-imports)
|
|
110
|
+
(defalias 'reformat-imports 'pyflyby-reformat-imports)
|
|
111
|
+
|
|
112
|
+
(provide 'pyflyby)
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
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
|
+
#!/usr/bin/env python3
|
|
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
|
+
#!/usr/bin/env 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
|
+
#!/usr/bin/env python3
|
|
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
|
+
#!/usr/bin/env python3
|
|
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
|
+
#!/usr/bin/env python3
|
|
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()
|