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.
Files changed (53) hide show
  1. pyflyby/__init__.py +61 -0
  2. pyflyby/__main__.py +9 -0
  3. pyflyby/_autoimp.py +2228 -0
  4. pyflyby/_cmdline.py +591 -0
  5. pyflyby/_comms.py +221 -0
  6. pyflyby/_dbg.py +1383 -0
  7. pyflyby/_dynimp.py +154 -0
  8. pyflyby/_fast_iter_modules.cpython-312-x86_64-linux-gnu.so +0 -0
  9. pyflyby/_file.py +771 -0
  10. pyflyby/_flags.py +230 -0
  11. pyflyby/_format.py +186 -0
  12. pyflyby/_idents.py +227 -0
  13. pyflyby/_import_sorting.py +165 -0
  14. pyflyby/_importclns.py +658 -0
  15. pyflyby/_importdb.py +535 -0
  16. pyflyby/_imports2s.py +643 -0
  17. pyflyby/_importstmt.py +723 -0
  18. pyflyby/_interactive.py +2113 -0
  19. pyflyby/_livepatch.py +793 -0
  20. pyflyby/_log.py +107 -0
  21. pyflyby/_modules.py +646 -0
  22. pyflyby/_parse.py +1396 -0
  23. pyflyby/_py.py +2165 -0
  24. pyflyby/_saveframe.py +1145 -0
  25. pyflyby/_saveframe_reader.py +471 -0
  26. pyflyby/_util.py +458 -0
  27. pyflyby/_version.py +8 -0
  28. pyflyby/autoimport.py +20 -0
  29. pyflyby/etc/pyflyby/canonical.py +10 -0
  30. pyflyby/etc/pyflyby/common.py +27 -0
  31. pyflyby/etc/pyflyby/forget.py +10 -0
  32. pyflyby/etc/pyflyby/mandatory.py +10 -0
  33. pyflyby/etc/pyflyby/numpy.py +156 -0
  34. pyflyby/etc/pyflyby/std.py +335 -0
  35. pyflyby/importdb.py +19 -0
  36. pyflyby/libexec/pyflyby/colordiff +34 -0
  37. pyflyby/libexec/pyflyby/diff-colorize +148 -0
  38. pyflyby/share/emacs/site-lisp/pyflyby.el +112 -0
  39. pyflyby-1.10.4.data/scripts/collect-exports +76 -0
  40. pyflyby-1.10.4.data/scripts/collect-imports +58 -0
  41. pyflyby-1.10.4.data/scripts/find-import +38 -0
  42. pyflyby-1.10.4.data/scripts/prune-broken-imports +34 -0
  43. pyflyby-1.10.4.data/scripts/pyflyby-diff +34 -0
  44. pyflyby-1.10.4.data/scripts/reformat-imports +27 -0
  45. pyflyby-1.10.4.data/scripts/replace-star-imports +37 -0
  46. pyflyby-1.10.4.data/scripts/saveframe +299 -0
  47. pyflyby-1.10.4.data/scripts/tidy-imports +170 -0
  48. pyflyby-1.10.4.data/scripts/transform-imports +47 -0
  49. pyflyby-1.10.4.dist-info/METADATA +605 -0
  50. pyflyby-1.10.4.dist-info/RECORD +53 -0
  51. pyflyby-1.10.4.dist-info/WHEEL +6 -0
  52. pyflyby-1.10.4.dist-info/entry_points.txt +4 -0
  53. 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")