| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 3838cc8 commit cd5d511
25 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -94,13 +94,10 @@ jobs: | |||
| 94 | 94 | python-version: '3.10' | |
| 95 | 95 | ||
| 96 | 96 | - name: install | |
| 97 | - run: make install | ||
| 98 | - | ||
| 99 | - - name: set version | ||
| 100 | - run: VERSION_PATH='devtools/version.py' python <(curl -Ls https://git.io/JT3rm) | ||
| 97 | + run: pip install -U build twine setuptools | ||
| 101 | 98 | ||
| 102 | 99 | - name: build | |
| 103 | - run: python setup.py sdist bdist_wheel | ||
| 100 | + run: python -m build | ||
| 104 | 101 | ||
| 105 | 102 | - run: twine check dist/* | |
| 106 | 103 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -19,3 +19,4 @@ old-version/ | |||
| 19 | 19 | *.swp | |
| 20 | 20 | /site/ | |
| 21 | 21 | /site.zip | |
| 22 | + /build/ | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,11 @@ | |||
| 1 | + ## v0.8.0 (2021-09-29) | ||
| 2 | + | ||
| 3 | + * test with python 3.10 #91 | ||
| 4 | + * display `SQLAlchemy` objects nicely #94 | ||
| 5 | + * fix tests on windows #93 | ||
| 6 | + * show function `qualname` #95 | ||
| 7 | + * cache pygments loading (significant speedup) #96 | ||
| 8 | + | ||
| 1 | 9 | ## v0.7.0 (2021-09-03) | |
| 2 | 10 | ||
| 3 | 11 | * switch to [`executing`](https://pypi.org/project/executing/) and [`asttokens`](https://pypi.org/project/asttokens/) | |
@@ -9,6 +17,10 @@ | |||
| 9 | 17 | * display `dataclasses` properly, #88 | |
| 10 | 18 | * uprev test dependencies, #81, #83, #90 | |
| 11 | 19 | ||
| 20 | + ## v0.6.1 (2020-10-22) | ||
| 21 | + | ||
| 22 | + compatibility with python 3.8.6 | ||
| 23 | + | ||
| 12 | 24 | ## v0.6.0 (2020-07-29) | |
| 13 | 25 | ||
| 14 | 26 | * improve `__pretty__` to work better with pydantic classes, #52 | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,6 @@ | |||
| 1 | 1 | .DEFAULT_GOAL := all | |
| 2 | - isort = isort devtools tests | ||
| 3 | - black = black -S -l 120 --target-version py37 devtools | ||
| 2 | + isort = isort devtools tests docs/plugins.py | ||
| 3 | + black = black -S -l 120 --target-version py37 devtools docs/plugins.py | ||
| 4 | 4 | ||
| 5 | 5 | .PHONY: install | |
| 6 | 6 | install: | |
@@ -15,9 +15,10 @@ format: | |||
| 15 | 15 | ||
| 16 | 16 | .PHONY: lint | |
| 17 | 17 | lint: | |
| 18 | - flake8 devtools/ tests/ | ||
| 18 | + flake8 --max-complexity 10 --max-line-length 120 --ignore E203,W503 devtools tests docs/plugins.py | ||
| 19 | 19 | $(isort) --check-only --df | |
| 20 | 20 | $(black) --check --diff | |
| 21 | + mypy devtools | ||
| 21 | 22 | ||
| 22 | 23 | .PHONY: test | |
| 23 | 24 | test: | |
@@ -50,12 +51,10 @@ clean: | |||
| 50 | 51 | .PHONY: docs | |
| 51 | 52 | docs: | |
| 52 | 53 | flake8 --max-line-length=80 docs/examples/ | |
| 53 | - python docs/build/main.py | ||
| 54 | 54 | mkdocs build | |
| 55 | 55 | ||
| 56 | 56 | .PHONY: docs-serve | |
| 57 | 57 | docs-serve: | |
| 58 | - python docs/build/main.py | ||
| 59 | 58 | mkdocs serve | |
| 60 | 59 | ||
| 61 | 60 | .PHONY: publish-docs | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,3 +4,5 @@ | |||
| 4 | 4 | from .prettier import * | |
| 5 | 5 | from .timer import * | |
| 6 | 6 | from .version import VERSION | |
| 7 | + | ||
| 8 | + __version__ = VERSION | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,10 +6,10 @@ | |||
| 6 | 6 | ||
| 7 | 7 | MYPY = False | |
| 8 | 8 | if MYPY: | |
| 9 | - from typing import Any, Union | ||
| 9 | + from typing import Any, Mapping, Union | ||
| 10 | 10 | ||
| 11 | 11 | ||
| 12 | - def strip_ansi(value): | ||
| 12 | + def strip_ansi(value: str) -> str: | ||
| 13 | 13 | import re | |
| 14 | 14 | ||
| 15 | 15 | return re.sub('\033\\[((?:\\d|;)*)([a-zA-Z])', '', value) | |
@@ -62,7 +62,7 @@ class Style(IntEnum): | |||
| 62 | 62 | # this is a meta value used for the "Style" instance which is the "style" function | |
| 63 | 63 | function = -1 | |
| 64 | 64 | ||
| 65 | - def __call__(self, input: 'Any', *styles: 'Style', reset: bool = True, apply: bool = True) -> str: | ||
| 65 | + def __call__(self, input: 'Any', *styles: 'Union[Style, int, str]', reset: bool = True, apply: bool = True) -> str: | ||
| 66 | 66 | """ | |
| 67 | 67 | Styles text with ANSI styles and returns the new string. | |
| 68 | 68 | ||
@@ -91,7 +91,7 @@ def __call__(self, input: 'Any', *styles: 'Style', reset: bool = True, apply: bo | |||
| 91 | 91 | s = self.styles[s] | |
| 92 | 92 | except KeyError: | |
| 93 | 93 | raise ValueError(f'invalid style "{s}"') | |
| 94 | - codes.append(_style_as_int(s.value)) | ||
| 94 | + codes.append(_style_as_int(s.value)) # type: ignore | ||
| 95 | 95 | ||
| 96 | 96 | if codes: | |
| 97 | 97 | r = _as_ansi(';'.join(codes)) + text | |
@@ -103,16 +103,16 @@ def __call__(self, input: 'Any', *styles: 'Style', reset: bool = True, apply: bo | |||
| 103 | 103 | return r | |
| 104 | 104 | ||
| 105 | 105 | @property | |
| 106 | - def styles(self): | ||
| 106 | + def styles(self) -> 'Mapping[str, Style]': | ||
| 107 | 107 | return self.__class__.__members__ | |
| 108 | 108 | ||
| 109 | - def __repr__(self): | ||
| 109 | + def __repr__(self) -> str: | ||
| 110 | 110 | if self == self.function: | |
| 111 | 111 | return '<pseudo function sformat(text, *styles)>' | |
| 112 | 112 | else: | |
| 113 | 113 | return super().__repr__() | |
| 114 | 114 | ||
| 115 | - def __str__(self): | ||
| 115 | + def __str__(self) -> str: | ||
| 116 | 116 | if self == self.function: | |
| 117 | 117 | return repr(self) | |
| 118 | 118 | else: | |
@@ -139,14 +139,22 @@ class StylePrint: | |||
| 139 | 139 | for that mistake. | |
| 140 | 140 | """ | |
| 141 | 141 | ||
| 142 | - def __call__(self, input, *styles, reset=True, flush=True, file=None, **print_kwargs): | ||
| 142 | + def __call__( | ||
| 143 | + self, | ||
| 144 | + input: str, | ||
| 145 | + *styles: 'Union[Style, int, str]', | ||
| 146 | + reset: bool = True, | ||
| 147 | + flush: bool = True, | ||
| 148 | + file: 'Any' = None, | ||
| 149 | + **print_kwargs: 'Any', | ||
| 150 | + ) -> None: | ||
| 143 | 151 | text = sformat(input, *styles, reset=reset, apply=isatty(file)) | |
| 144 | 152 | print(text, flush=flush, file=file, **print_kwargs) | |
| 145 | 153 | ||
| 146 | - def __getattr__(self, item): | ||
| 154 | + def __getattr__(self, item: str) -> str: | ||
| 147 | 155 | return getattr(sformat, item) | |
| 148 | 156 | ||
| 149 | - def __repr__(self): | ||
| 157 | + def __repr__(self) -> str: | ||
| 150 | 158 | return '<pseudo function sprint(text, *styles)>' | |
| 151 | 159 | ||
| 152 | 160 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,20 +10,22 @@ | |||
| 10 | 10 | MYPY = False | |
| 11 | 11 | if MYPY: | |
| 12 | 12 | from types import FrameType | |
| 13 | - from typing import Any, Generator, List, Optional | ||
| 13 | + from typing import Any, Generator, List, Optional, Union | ||
| 14 | 14 | ||
| 15 | 15 | pformat = PrettyFormat( | |
| 16 | 16 | indent_step=int(os.getenv('PY_DEVTOOLS_INDENT', 4)), | |
| 17 | 17 | simple_cutoff=int(os.getenv('PY_DEVTOOLS_SIMPLE_CUTOFF', 10)), | |
| 18 | 18 | width=int(os.getenv('PY_DEVTOOLS_WIDTH', 120)), | |
| 19 | 19 | yield_from_generators=env_true('PY_DEVTOOLS_YIELD_FROM_GEN', True), | |
| 20 | 20 | ) | |
| 21 | + # required for type hinting because I (stupidly) added methods called `str` | ||
| 22 | + StrType = str | ||
| 21 | 23 | ||
| 22 | 24 | ||
| 23 | 25 | class DebugArgument: | |
| 24 | 26 | __slots__ = 'value', 'name', 'extra' | |
| 25 | 27 | ||
| 26 | - def __init__(self, value, *, name=None, **extra): | ||
| 28 | + def __init__(self, value: 'Any', *, name: 'Optional[str]' = None, **extra: 'Any') -> None: | ||
| 27 | 29 | self.value = value | |
| 28 | 30 | self.name = name | |
| 29 | 31 | self.extra = [] | |
@@ -35,7 +37,7 @@ def __init__(self, value, *, name=None, **extra): | |||
| 35 | 37 | self.extra.append(('len', length)) | |
| 36 | 38 | self.extra += [(k, v) for k, v in extra.items() if v is not None] | |
| 37 | 39 | ||
| 38 | - def str(self, highlight=False) -> str: | ||
| 40 | + def str(self, highlight: bool = False) -> StrType: | ||
| 39 | 41 | s = '' | |
| 40 | 42 | if self.name and not is_literal(self.name): | |
| 41 | 43 | s = f'{sformat(self.name, sformat.blue, apply=highlight)}: ' | |
@@ -54,7 +56,7 @@ def str(self, highlight=False) -> str: | |||
| 54 | 56 | s += suffix | |
| 55 | 57 | return s | |
| 56 | 58 | ||
| 57 | - def __str__(self) -> str: | ||
| 59 | + def __str__(self) -> StrType: | ||
| 58 | 60 | return self.str() | |
| 59 | 61 | ||
| 60 | 62 | ||
@@ -66,14 +68,22 @@ class DebugOutput: | |||
| 66 | 68 | arg_class = DebugArgument | |
| 67 | 69 | __slots__ = 'filename', 'lineno', 'frame', 'arguments', 'warning' | |
| 68 | 70 | ||
| 69 | - def __init__(self, *, filename: str, lineno: int, frame: str, arguments: 'List[DebugArgument]', warning=None): | ||
| 71 | + def __init__( | ||
| 72 | + self, | ||
| 73 | + *, | ||
| 74 | + filename: str, | ||
| 75 | + lineno: int, | ||
| 76 | + frame: str, | ||
| 77 | + arguments: 'List[DebugArgument]', | ||
| 78 | + warning: 'Union[None, str, bool]' = None, | ||
| 79 | + ) -> None: | ||
| 70 | 80 | self.filename = filename | |
| 71 | 81 | self.lineno = lineno | |
| 72 | 82 | self.frame = frame | |
| 73 | 83 | self.arguments = arguments | |
| 74 | 84 | self.warning = warning | |
| 75 | 85 | ||
| 76 | - def str(self, highlight=False) -> str: | ||
| 86 | + def str(self, highlight: bool = False) -> StrType: | ||
| 77 | 87 | if highlight: | |
| 78 | 88 | prefix = ( | |
| 79 | 89 | f'{sformat(self.filename, sformat.magenta)}:{sformat(self.lineno, sformat.green)} ' | |
@@ -87,10 +97,10 @@ def str(self, highlight=False) -> str: | |||
| 87 | 97 | prefix += f' ({self.warning})' | |
| 88 | 98 | return f'{prefix}\n ' + '\n '.join(a.str(highlight) for a in self.arguments) | |
| 89 | 99 | ||
| 90 | - def __str__(self) -> str: | ||
| 100 | + def __str__(self) -> StrType: | ||
| 91 | 101 | return self.str() | |
| 92 | 102 | ||
| 93 | - def __repr__(self) -> str: | ||
| 103 | + def __repr__(self) -> StrType: | ||
| 94 | 104 | arguments = ' '.join(str(a) for a in self.arguments) | |
| 95 | 105 | return f'<DebugOutput {self.filename}:{self.lineno} {self.frame} arguments: {arguments}>' | |
| 96 | 106 | ||
@@ -102,7 +112,7 @@ def __init__(self, *, warnings: 'Optional[bool]' = None, highlight: 'Optional[bo | |||
| 102 | 112 | self._show_warnings = env_bool(warnings, 'PY_DEVTOOLS_WARNINGS', True) | |
| 103 | 113 | self._highlight = highlight | |
| 104 | 114 | ||
| 105 | - def __call__(self, *args, file_=None, flush_=True, **kwargs) -> 'Any': | ||
| 115 | + def __call__(self, *args: 'Any', file_: 'Any' = None, flush_: bool = True, **kwargs: 'Any') -> 'Any': | ||
| 106 | 116 | d_out = self._process(args, kwargs) | |
| 107 | 117 | s = d_out.str(use_highlight(self._highlight, file_)) | |
| 108 | 118 | print(s, file=file_, flush=flush_) | |
@@ -113,18 +123,18 @@ def __call__(self, *args, file_=None, flush_=True, **kwargs) -> 'Any': | |||
| 113 | 123 | else: | |
| 114 | 124 | return args | |
| 115 | 125 | ||
| 116 | - def format(self, *args, **kwargs) -> DebugOutput: | ||
| 126 | + def format(self, *args: 'Any', **kwargs: 'Any') -> DebugOutput: | ||
| 117 | 127 | return self._process(args, kwargs) | |
| 118 | 128 | ||
| 119 | - def breakpoint(self): | ||
| 129 | + def breakpoint(self) -> None: | ||
| 120 | 130 | import pdb | |
| 121 | 131 | ||
| 122 | 132 | pdb.Pdb(skip=['devtools.*']).set_trace() | |
| 123 | 133 | ||
| 124 | - def timer(self, name=None, *, verbose=True, file=None, dp=3) -> Timer: | ||
| 134 | + def timer(self, name: 'Optional[str]' = None, *, verbose: bool = True, file: 'Any' = None, dp: int = 3) -> Timer: | ||
| 125 | 135 | return Timer(name=name, verbose=verbose, file=file, dp=dp) | |
| 126 | 136 | ||
| 127 | - def _process(self, args, kwargs) -> DebugOutput: | ||
| 137 | + def _process(self, args: 'Any', kwargs: 'Any') -> DebugOutput: | ||
| 128 | 138 | """ | |
| 129 | 139 | BEWARE: this must be called from a function exactly 2 levels below the top of the stack. | |
| 130 | 140 | """ | |
@@ -181,13 +191,13 @@ def _process(self, args, kwargs) -> DebugOutput: | |||
| 181 | 191 | warning=self._show_warnings and warning, | |
| 182 | 192 | ) | |
| 183 | 193 | ||
| 184 | - def _args_inspection_failed(self, args, kwargs): | ||
| 194 | + def _args_inspection_failed(self, args: 'Any', kwargs: 'Any') -> 'Generator[DebugArgument, None, None]': | ||
| 185 | 195 | for arg in args: | |
| 186 | 196 | yield self.output_class.arg_class(arg) | |
| 187 | 197 | for name, value in kwargs.items(): | |
| 188 | 198 | yield self.output_class.arg_class(value, name=name) | |
| 189 | 199 | ||
| 190 | - def _process_args(self, ex, args, kwargs) -> 'Generator[DebugArgument, None, None]': | ||
| 200 | + def _process_args(self, ex: 'Any', args: 'Any', kwargs: 'Any') -> 'Generator[DebugArgument, None, None]': | ||
| 191 | 201 | import ast | |
| 192 | 202 | ||
| 193 | 203 | func_ast = ex.node | |
| Back | FazBrowse Home | New Git URL |
0 commit comments