././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1720900174.6704602 colored-traceback-0.4.2/0000755000076500000240000000000014644555117014137 5ustar00antonstaff././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1720578682.0 colored-traceback-0.4.2/LICENSE0000644000076500000240000000135614643371172015145 0ustar00antonstaffCopyright (c) 2014, Anton Backer Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1720580813.0 colored-traceback-0.4.2/MANIFEST.in0000644000076500000240000000004314643375315015671 0ustar00antonstaffinclude README.rst include LICENSE ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1720900174.6702724 colored-traceback-0.4.2/PKG-INFO0000644000076500000240000001073114644555117015236 0ustar00antonstaffMetadata-Version: 2.1 Name: colored-traceback Version: 0.4.2 Summary: Automatically color uncaught exception tracebacks Author-email: Anton Backer License: ISC Project-URL: Source, https://www.github.com/staticshock/colored-traceback.py Classifier: Development Status :: 4 - Beta Classifier: Environment :: Console Classifier: Intended Audience :: Developers Classifier: Natural Language :: English Classifier: License :: OSI Approved :: ISC License (ISCL) Classifier: Operating System :: POSIX :: Linux Classifier: Operating System :: MacOS :: MacOS X Classifier: Operating System :: Microsoft :: Windows Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3.3 Description-Content-Type: text/x-rst License-File: LICENSE Colored Traceback ================= Automatically color Python's uncaught exception tracebacks. This one's for anybody who's ever struggled to read python's stacktraces on the terminal. Something about the two-lines-per-frame approach really just makes them tough to scan visually. Compare this: :: Traceback (most recent call last): File "./workflowy.py", line 525, in main() File "./workflowy.py", line 37, in main projects = cli.load_json(args, input_is_pipe) File "./workflowy.py", line 153, in load_json return json.load(sys.stdin) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 290, in load **kw) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 338, in loads return _default_decoder.decode(s) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 365, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 383, in raw_decode raise ValueError("No JSON object could be decoded") ValueError: No JSON object could be decoded To this: .. code-block:: python Traceback (most recent call last): File "./workflowy.py", line 525, in main() File "./workflowy.py", line 37, in main projects = cli.load_json(args, input_is_pipe) File "./workflowy.py", line 153, in load_json return json.load(sys.stdin) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 290, in load **kw) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 338, in loads return _default_decoder.decode(s) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 365, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 383, in raw_decode raise ValueError("No JSON object could be decoded") ValueError: No JSON object could be decoded Installation ------------ Through pip: .. code-block:: bash pip install colored-traceback Or directly: .. code-block:: bash git clone http://www.github.com/staticshock/colored-traceback.py cd colored-traceback.py pip install . On Windows, which has no real support for ANSI escape sequences, this will also install `colorama`. Usage ----- Colored Traceback can be executed as a module: .. code-block:: bash python -m colored_traceback somefile.py Colored Traceback also works well within a script or even directly in the interpreter REPL. Standard usage will color the output, unless it's being redirected to a pipe: .. code-block:: python import colored_traceback colored_traceback.add_hook() If want to retain color even when stderr is being piped, tack on an `always=True` argument: .. code-block:: python import colored_traceback colored_traceback.add_hook(always=True) There are also a couple of convenience imports, which get the footprint down to one line: .. code-block:: python # Same as add_hook() import colored_traceback.auto # Same as add_hook(always=True) import colored_traceback.always It goes without saying that you might want to catch `ImportError`, making the presence of the package optional: .. code-block:: python try: import colored_traceback.auto except ImportError: pass ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1720721785.0 colored-traceback-0.4.2/README.rst0000644000076500000240000000723514644020571015624 0ustar00antonstaffColored Traceback ================= Automatically color Python's uncaught exception tracebacks. This one's for anybody who's ever struggled to read python's stacktraces on the terminal. Something about the two-lines-per-frame approach really just makes them tough to scan visually. Compare this: :: Traceback (most recent call last): File "./workflowy.py", line 525, in main() File "./workflowy.py", line 37, in main projects = cli.load_json(args, input_is_pipe) File "./workflowy.py", line 153, in load_json return json.load(sys.stdin) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 290, in load **kw) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 338, in loads return _default_decoder.decode(s) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 365, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 383, in raw_decode raise ValueError("No JSON object could be decoded") ValueError: No JSON object could be decoded To this: .. code-block:: python Traceback (most recent call last): File "./workflowy.py", line 525, in main() File "./workflowy.py", line 37, in main projects = cli.load_json(args, input_is_pipe) File "./workflowy.py", line 153, in load_json return json.load(sys.stdin) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 290, in load **kw) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 338, in loads return _default_decoder.decode(s) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 365, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 383, in raw_decode raise ValueError("No JSON object could be decoded") ValueError: No JSON object could be decoded Installation ------------ Through pip: .. code-block:: bash pip install colored-traceback Or directly: .. code-block:: bash git clone http://www.github.com/staticshock/colored-traceback.py cd colored-traceback.py pip install . On Windows, which has no real support for ANSI escape sequences, this will also install `colorama`. Usage ----- Colored Traceback can be executed as a module: .. code-block:: bash python -m colored_traceback somefile.py Colored Traceback also works well within a script or even directly in the interpreter REPL. Standard usage will color the output, unless it's being redirected to a pipe: .. code-block:: python import colored_traceback colored_traceback.add_hook() If want to retain color even when stderr is being piped, tack on an `always=True` argument: .. code-block:: python import colored_traceback colored_traceback.add_hook(always=True) There are also a couple of convenience imports, which get the footprint down to one line: .. code-block:: python # Same as add_hook() import colored_traceback.auto # Same as add_hook(always=True) import colored_traceback.always It goes without saying that you might want to catch `ImportError`, making the presence of the package optional: .. code-block:: python try: import colored_traceback.auto except ImportError: pass ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1720900174.6687942 colored-traceback-0.4.2/colored_traceback/0000755000076500000240000000000014644555117017565 5ustar00antonstaff././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1720581904.0 colored-traceback-0.4.2/colored_traceback/__init__.py0000644000076500000240000000005014643377420021667 0ustar00antonstafffrom .colored_traceback import add_hook ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1720578682.0 colored-traceback-0.4.2/colored_traceback/__main__.py0000644000076500000240000000130714643371172021654 0ustar00antonstaffimport os import sys import colored_traceback colored_traceback.add_hook() # Check that a script was passed in. if len(sys.argv) <= 1: raise SystemExit("Usage: python -m colored_traceback my_script.py") # Check that the script exists. script_path = sys.argv[1] if not os.path.exists(script_path): raise SystemExit("Error: '%s' does not exist" % script_path) # Replace colored_traceback's dir with script's dir in the module search path. sys.path[0] = os.path.dirname(script_path) # Remove colored_traceback from the arg list. del sys.argv[0] with open(script_path) as script_file: code = compile(script_file.read(), script_path, 'exec') variables = {} exec(code, variables, variables) ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1720900174.6697042 colored-traceback-0.4.2/colored_traceback/always/0000755000076500000240000000000014644555117021065 5ustar00antonstaff././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1720578682.0 colored-traceback-0.4.2/colored_traceback/always/__init__.py0000644000076500000240000000007514643371172023174 0ustar00antonstafffrom colored_traceback import add_hook add_hook(always=True) ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1720900174.6698809 colored-traceback-0.4.2/colored_traceback/auto/0000755000076500000240000000000014644555117020535 5ustar00antonstaff././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1720578682.0 colored-traceback-0.4.2/colored_traceback/auto/__init__.py0000644000076500000240000000006214643371172022640 0ustar00antonstafffrom colored_traceback import add_hook add_hook() ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1720581961.0 colored-traceback-0.4.2/colored_traceback/colored_traceback.py0000644000076500000240000000526214643377511023571 0ustar00antonstaffimport os import sys import traceback try: from pygments import highlight from pygments.lexers import get_lexer_by_name from pygments.formatters import get_formatter_by_name from pygments.util import ClassNotFound PYGMENTS = True except ImportError: PYGMENTS = False if os.environ.get("NO_COLOR", ""): # https://no-color.org def add_hook(debug=False, **kwargs): pass elif PYGMENTS: try: import colorama translate_stream = colorama.AnsiToWin32 except ImportError: def translate_stream(stream): return stream def _get_term_color_support(): try: import curses except ImportError: # Probably Windows, which doesn't have great curses support return 16 curses.setupterm() return curses.tigetnum('colors') def _determine_formatter(style="default", colors=None, debug=False): colors = colors or _get_term_color_support() if debug: sys.stderr.write("Detected support for %s colors\n" % colors) if colors == 256: fmt_options = {'style': style} elif style in ('light', 'dark'): fmt_options = {'bg': style} else: fmt_options = {'bg': 'dark'} fmt_alias = 'terminal256' if colors == 256 else 'terminal' try: return get_formatter_by_name(fmt_alias, **fmt_options) except ClassNotFound as ex: if debug: sys.stderr.write(str(ex) + "\n") return get_formatter_by_name(fmt_alias) LEXER = get_lexer_by_name( "pytb" if sys.version_info.major < 3 else "py3tb" ) class Colorizer(object): def __init__(self, style, colors, debug=False): self.style = style self.debug = debug self.lexer = LEXER self.formatter = _determine_formatter(style, colors, debug) def colorize_traceback(self, type, value, tb): tb_text = "".join(traceback.format_exception(type, value, tb)) tb_colored = highlight(tb_text, self.lexer, self.formatter) self.stream.write(tb_colored) @property def stream(self): return translate_stream(sys.stderr) def add_hook(always=False, style='default', colors=None, debug=False): isatty = getattr(sys.stderr, 'isatty', lambda: False) if always or isatty(): colorizer = Colorizer(style, colors, debug) sys.excepthook = colorizer.colorize_traceback else: def add_hook(debug=False, **kwargs): if debug: sys.stderr.write( "Failed to add coloring hook; pygments not available\n" ) ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1720900174.669581 colored-traceback-0.4.2/colored_traceback.egg-info/0000755000076500000240000000000014644555117021257 5ustar00antonstaff././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1720900174.0 colored-traceback-0.4.2/colored_traceback.egg-info/PKG-INFO0000644000076500000240000001073114644555116022355 0ustar00antonstaffMetadata-Version: 2.1 Name: colored-traceback Version: 0.4.2 Summary: Automatically color uncaught exception tracebacks Author-email: Anton Backer License: ISC Project-URL: Source, https://www.github.com/staticshock/colored-traceback.py Classifier: Development Status :: 4 - Beta Classifier: Environment :: Console Classifier: Intended Audience :: Developers Classifier: Natural Language :: English Classifier: License :: OSI Approved :: ISC License (ISCL) Classifier: Operating System :: POSIX :: Linux Classifier: Operating System :: MacOS :: MacOS X Classifier: Operating System :: Microsoft :: Windows Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3.3 Description-Content-Type: text/x-rst License-File: LICENSE Colored Traceback ================= Automatically color Python's uncaught exception tracebacks. This one's for anybody who's ever struggled to read python's stacktraces on the terminal. Something about the two-lines-per-frame approach really just makes them tough to scan visually. Compare this: :: Traceback (most recent call last): File "./workflowy.py", line 525, in main() File "./workflowy.py", line 37, in main projects = cli.load_json(args, input_is_pipe) File "./workflowy.py", line 153, in load_json return json.load(sys.stdin) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 290, in load **kw) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 338, in loads return _default_decoder.decode(s) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 365, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 383, in raw_decode raise ValueError("No JSON object could be decoded") ValueError: No JSON object could be decoded To this: .. code-block:: python Traceback (most recent call last): File "./workflowy.py", line 525, in main() File "./workflowy.py", line 37, in main projects = cli.load_json(args, input_is_pipe) File "./workflowy.py", line 153, in load_json return json.load(sys.stdin) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 290, in load **kw) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 338, in loads return _default_decoder.decode(s) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 365, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 383, in raw_decode raise ValueError("No JSON object could be decoded") ValueError: No JSON object could be decoded Installation ------------ Through pip: .. code-block:: bash pip install colored-traceback Or directly: .. code-block:: bash git clone http://www.github.com/staticshock/colored-traceback.py cd colored-traceback.py pip install . On Windows, which has no real support for ANSI escape sequences, this will also install `colorama`. Usage ----- Colored Traceback can be executed as a module: .. code-block:: bash python -m colored_traceback somefile.py Colored Traceback also works well within a script or even directly in the interpreter REPL. Standard usage will color the output, unless it's being redirected to a pipe: .. code-block:: python import colored_traceback colored_traceback.add_hook() If want to retain color even when stderr is being piped, tack on an `always=True` argument: .. code-block:: python import colored_traceback colored_traceback.add_hook(always=True) There are also a couple of convenience imports, which get the footprint down to one line: .. code-block:: python # Same as add_hook() import colored_traceback.auto # Same as add_hook(always=True) import colored_traceback.always It goes without saying that you might want to catch `ImportError`, making the presence of the package optional: .. code-block:: python try: import colored_traceback.auto except ImportError: pass ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1720900174.0 colored-traceback-0.4.2/colored_traceback.egg-info/SOURCES.txt0000644000076500000240000000065514644555116023150 0ustar00antonstaffLICENSE MANIFEST.in README.rst pyproject.toml setup.py colored_traceback/__init__.py colored_traceback/__main__.py colored_traceback/colored_traceback.py colored_traceback.egg-info/PKG-INFO colored_traceback.egg-info/SOURCES.txt colored_traceback.egg-info/dependency_links.txt colored_traceback.egg-info/requires.txt colored_traceback.egg-info/top_level.txt colored_traceback/always/__init__.py colored_traceback/auto/__init__.py././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1720900174.0 colored-traceback-0.4.2/colored_traceback.egg-info/dependency_links.txt0000644000076500000240000000000114644555116025324 0ustar00antonstaff ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1720900174.0 colored-traceback-0.4.2/colored_traceback.egg-info/requires.txt0000644000076500000240000000004614644555116023656 0ustar00antonstaffpygments [:os_name == "nt"] colorama ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1720900174.0 colored-traceback-0.4.2/colored_traceback.egg-info/top_level.txt0000644000076500000240000000002214644555116024002 0ustar00antonstaffcolored_traceback ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1720895767.0 colored-traceback-0.4.2/pyproject.toml0000644000076500000240000000207114644544427017055 0ustar00antonstaff[build-system] build-backend = "setuptools.build_meta" requires = ["setuptools >= 61.0"] [project] name = "colored-traceback" version = "0.4.2" description = "Automatically color uncaught exception tracebacks" authors = [ { name = "Anton Backer", email = "olegov@gmail.com" }, ] readme = "README.rst" license = { text = "ISC" } classifiers = [ "Development Status :: 4 - Beta", "Environment :: Console", "Intended Audience :: Developers", "Natural Language :: English", "License :: OSI Approved :: ISC License (ISCL)", "Operating System :: POSIX :: Linux", "Operating System :: MacOS :: MacOS X", "Operating System :: Microsoft :: Windows", "Programming Language :: Python", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3.3", ] dependencies = [ "pygments", "colorama; os_name == 'nt'", ] [project.urls] Source = "https://www.github.com/staticshock/colored-traceback.py" [tool.setuptools] packages = [ "colored_traceback", "colored_traceback.auto", "colored_traceback.always", ] ././@PaxHeader0000000000000000000000000000003300000000000010211 xustar0027 mtime=1720900174.670515 colored-traceback-0.4.2/setup.cfg0000644000076500000240000000004614644555117015760 0ustar00antonstaff[egg_info] tag_build = tag_date = 0 ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1720895748.0 colored-traceback-0.4.2/setup.py0000755000076500000240000000004614644544404015651 0ustar00antonstafffrom setuptools import setup setup()