pyflyby 1.10.4__cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.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-312-x86_64-linux-gnu.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
pyflyby/_log.py
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
# pyflyby/_log.py.
|
|
2
|
+
# Copyright (C) 2011, 2012, 2013, 2014, 2015, 2018 Karl Chen.
|
|
3
|
+
# License: MIT http://opensource.org/licenses/MIT
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
import builtins
|
|
8
|
+
import logging
|
|
9
|
+
from logging import Handler, Logger
|
|
10
|
+
import os
|
|
11
|
+
import sys
|
|
12
|
+
from prompt_toolkit import patch_stdout
|
|
13
|
+
from contextlib import nullcontext
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class _PyflybyHandler(Handler):
|
|
17
|
+
|
|
18
|
+
_pre_log_function = None
|
|
19
|
+
_logged_anything_during_context = False
|
|
20
|
+
|
|
21
|
+
_interactive_prefix = "\033[0m\033[33m[PYFLYBY]\033[0m "
|
|
22
|
+
_noninteractive_prefix = "[PYFLYBY] "
|
|
23
|
+
|
|
24
|
+
def emit(self, record):
|
|
25
|
+
try:
|
|
26
|
+
if _is_ipython() or _is_interactive(sys.stderr):
|
|
27
|
+
prefix = self._interactive_prefix
|
|
28
|
+
patch_stdout_c = patch_stdout.patch_stdout(raw=True)
|
|
29
|
+
else:
|
|
30
|
+
prefix = self._noninteractive_prefix
|
|
31
|
+
patch_stdout_c = nullcontext()
|
|
32
|
+
|
|
33
|
+
msg = self.format(record)
|
|
34
|
+
msg = ''.join(["%s%s\n" % (prefix, line) for line in msg.splitlines()])
|
|
35
|
+
with patch_stdout_c:
|
|
36
|
+
sys.stderr.write(msg)
|
|
37
|
+
sys.stderr.flush()
|
|
38
|
+
except (KeyboardInterrupt, SystemExit):
|
|
39
|
+
raise
|
|
40
|
+
except Exception:
|
|
41
|
+
self.handleError(record)
|
|
42
|
+
|
|
43
|
+
def _is_interactive(file):
|
|
44
|
+
filemod = type(file).__module__
|
|
45
|
+
if filemod.startswith("IPython.") or filemod.startswith("prompt_toolkit."):
|
|
46
|
+
# Inside IPython notebook/kernel
|
|
47
|
+
return True
|
|
48
|
+
try:
|
|
49
|
+
fileno = file.fileno()
|
|
50
|
+
except Exception:
|
|
51
|
+
return False # dunno
|
|
52
|
+
return os.isatty(fileno)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def _is_ipython():
|
|
56
|
+
"""
|
|
57
|
+
Returns true if we're currently running inside IPython.
|
|
58
|
+
"""
|
|
59
|
+
# This currently only works for versions of IPython that are modern enough
|
|
60
|
+
# to install 'builtins.get_ipython()'.
|
|
61
|
+
if 'IPython' not in sys.modules:
|
|
62
|
+
return False
|
|
63
|
+
if not hasattr(builtins, "get_ipython"):
|
|
64
|
+
return False
|
|
65
|
+
ip = builtins.get_ipython()
|
|
66
|
+
if ip is None:
|
|
67
|
+
return False
|
|
68
|
+
return True
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class PyflybyLogger(Logger):
|
|
72
|
+
|
|
73
|
+
_LEVELS = dict( (k, getattr(logging, k))
|
|
74
|
+
for k in ['DEBUG', 'INFO', 'WARNING', 'ERROR'] )
|
|
75
|
+
|
|
76
|
+
def __init__(self, name, level):
|
|
77
|
+
Logger.__init__(self, name)
|
|
78
|
+
handler = _PyflybyHandler()
|
|
79
|
+
self.addHandler(handler)
|
|
80
|
+
self.set_level(level)
|
|
81
|
+
|
|
82
|
+
def set_level(self, level):
|
|
83
|
+
"""
|
|
84
|
+
Set the pyflyby logger's level to ``level``.
|
|
85
|
+
|
|
86
|
+
:type level:
|
|
87
|
+
``str``
|
|
88
|
+
"""
|
|
89
|
+
if isinstance(level, int):
|
|
90
|
+
level_num = level
|
|
91
|
+
else:
|
|
92
|
+
try:
|
|
93
|
+
level_num = self._LEVELS[level.upper()]
|
|
94
|
+
except KeyError:
|
|
95
|
+
raise ValueError("Bad log level %r" % (level,))
|
|
96
|
+
Logger.setLevel(self, level_num)
|
|
97
|
+
|
|
98
|
+
@property
|
|
99
|
+
def debug_enabled(self):
|
|
100
|
+
return self.level <= logging.DEBUG
|
|
101
|
+
|
|
102
|
+
@property
|
|
103
|
+
def info_enabled(self):
|
|
104
|
+
return self.level <= logging.INFO
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
logger = PyflybyLogger('pyflyby', os.getenv("PYFLYBY_LOG_LEVEL") or "INFO")
|