From 1172e81db7a05742e6f9a3db1ccec16045565b2c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 23 May 2023 16:06:17 +0100 Subject: [PATCH 01/12] Bump requests from 2.28.2 to 2.31.0 in /requirements (#130) Bumps [requests](https://github.com/psf/requests) from 2.28.2 to 2.31.0. - [Release notes](https://github.com/psf/requests/releases) - [Changelog](https://github.com/psf/requests/blob/main/HISTORY.md) - [Commits](https://github.com/psf/requests/compare/v2.28.2...v2.31.0) --- updated-dependencies: - dependency-name: requests dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- requirements/docs.txt | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/requirements/docs.txt b/requirements/docs.txt index 2d242be..c7e43ac 100644 --- a/requirements/docs.txt +++ b/requirements/docs.txt @@ -5,7 +5,7 @@ # pip-compile --output-file=requirements/docs.txt --resolver=backtracking requirements/docs.in # ansi2html==1.8.0 - # via -r requirements/docs.in + # via -r docs.in certifi==2022.12.7 # via requests charset-normalizer==3.1.0 @@ -29,32 +29,32 @@ markdown==3.3.7 # mkdocs-material # pymdown-extensions markdown-include==0.8.1 - # via -r requirements/docs.in + # via -r docs.in markupsafe==2.1.2 # via jinja2 mergedeep==1.3.4 # via mkdocs mkdocs==1.4.2 # via - # -r requirements/docs.in + # -r docs.in # mkdocs-exclude # mkdocs-material # mkdocs-simple-hooks mkdocs-exclude==1.0.2 - # via -r requirements/docs.in + # via -r docs.in mkdocs-material==9.1.5 - # via -r requirements/docs.in + # via -r docs.in mkdocs-material-extensions==1.1.1 # via mkdocs-material mkdocs-simple-hooks==0.1.5 - # via -r requirements/docs.in + # via -r docs.in numpy==1.24.2 - # via -r requirements/docs.in + # via -r docs.in packaging==23.0 # via mkdocs pygments==2.14.0 # via - # -r requirements/docs.in + # -r docs.in # mkdocs-material pymdown-extensions==9.10 # via mkdocs-material @@ -69,10 +69,10 @@ pyyaml-env-tag==0.1 # via mkdocs regex==2023.3.23 # via mkdocs-material -requests==2.28.2 +requests==2.31.0 # via mkdocs-material ruff==0.0.261 - # via -r requirements/docs.in + # via -r docs.in six==1.16.0 # via python-dateutil urllib3==1.26.15 From 2341ef37359b7d42a2c307207c50253343539d13 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 17 Aug 2023 12:00:48 +0100 Subject: [PATCH 02/12] Bump pygments from 2.13.0 to 2.15.0 in /docs (#133) Bumps [pygments](https://github.com/pygments/pygments) from 2.13.0 to 2.15.0. - [Release notes](https://github.com/pygments/pygments/releases) - [Changelog](https://github.com/pygments/pygments/blob/master/CHANGES) - [Commits](https://github.com/pygments/pygments/compare/2.13.0...2.15.0) --- updated-dependencies: - dependency-name: pygments dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- docs/requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index 3a7c1d2..d091120 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -4,4 +4,4 @@ mkdocs-exclude==1.0.2 mkdocs-material==8.3.9 mkdocs-simple-hooks==0.1.5 markdown-include==0.7.0 -pygments==2.13.0 +pygments==2.15.0 From 967121ff0b847756ef813c3ba80b4ab6d5ecde1c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 17 Aug 2023 12:01:07 +0100 Subject: [PATCH 03/12] Bump pygments from 2.14.0 to 2.15.0 in /requirements (#134) Bumps [pygments](https://github.com/pygments/pygments) from 2.14.0 to 2.15.0. - [Release notes](https://github.com/pygments/pygments/releases) - [Changelog](https://github.com/pygments/pygments/blob/master/CHANGES) - [Commits](https://github.com/pygments/pygments/compare/2.14.0...2.15.0) --- updated-dependencies: - dependency-name: pygments dependency-type: direct:production ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- requirements/docs.txt | 2 +- requirements/testing.txt | 33 ++++++++++++++------------------- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/requirements/docs.txt b/requirements/docs.txt index c7e43ac..dc0af30 100644 --- a/requirements/docs.txt +++ b/requirements/docs.txt @@ -52,7 +52,7 @@ numpy==1.24.2 # via -r docs.in packaging==23.0 # via mkdocs -pygments==2.14.0 +pygments==2.15.0 # via # -r docs.in # mkdocs-material diff --git a/requirements/testing.txt b/requirements/testing.txt index 9fb1f82..ace238f 100644 --- a/requirements/testing.txt +++ b/requirements/testing.txt @@ -5,17 +5,17 @@ # pip-compile --output-file=requirements/testing.txt --resolver=backtracking requirements/testing.in # asyncpg==0.27.0 ; python_version >= "3.8" - # via -r requirements/testing.in + # via -r testing.in attrs==22.2.0 # via pytest black==23.3.0 - # via -r requirements/testing.in + # via -r testing.in click==8.1.3 # via black coverage[toml]==7.2.2 - # via -r requirements/testing.in -exceptiongroup==1.1.1 - # via pytest + # via -r testing.in +greenlet==2.0.2 + # via sqlalchemy iniconfig==2.0.0 # via pytest markdown-it-py==2.2.0 @@ -23,11 +23,11 @@ markdown-it-py==2.2.0 mdurl==0.1.2 # via markdown-it-py multidict==6.0.4 ; python_version >= "3.8" - # via -r requirements/testing.in + # via -r testing.in mypy-extensions==1.0.0 # via black numpy==1.24.2 ; python_version >= "3.8" - # via -r requirements/testing.in + # via -r testing.in packaging==23.0 # via # black @@ -39,29 +39,24 @@ platformdirs==3.2.0 pluggy==1.0.0 # via pytest pydantic==1.10.7 - # via -r requirements/testing.in -pygments==2.14.0 + # via -r testing.in +pygments==2.15.0 # via - # -r requirements/testing.in + # -r testing.in # rich pytest==7.2.2 # via - # -r requirements/testing.in + # -r testing.in # pytest-mock # pytest-pretty pytest-mock==3.10.0 - # via -r requirements/testing.in + # via -r testing.in pytest-pretty==1.2.0 - # via -r requirements/testing.in + # via -r testing.in rich==13.3.3 # via pytest-pretty sqlalchemy==2.0.8 - # via -r requirements/testing.in -tomli==2.0.1 - # via - # black - # coverage - # pytest + # via -r testing.in typing-extensions==4.5.0 # via # pydantic From 3a6f5b991f4f1d5726f0308a92fc14554e2cef67 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 17 Aug 2023 12:01:21 +0100 Subject: [PATCH 04/12] Bump pymdown-extensions from 9.10 to 10.0 in /requirements (#129) Bumps [pymdown-extensions](https://github.com/facelessuser/pymdown-extensions) from 9.10 to 10.0. - [Release notes](https://github.com/facelessuser/pymdown-extensions/releases) - [Commits](https://github.com/facelessuser/pymdown-extensions/compare/9.10...10.0) --- updated-dependencies: - dependency-name: pymdown-extensions dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- requirements/docs.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/docs.txt b/requirements/docs.txt index dc0af30..2782252 100644 --- a/requirements/docs.txt +++ b/requirements/docs.txt @@ -56,7 +56,7 @@ pygments==2.15.0 # via # -r docs.in # mkdocs-material -pymdown-extensions==9.10 +pymdown-extensions==10.0 # via mkdocs-material python-dateutil==2.8.2 # via ghp-import From c17c31021143f4d3feac0c47b897ae22b1aefb06 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 17 Aug 2023 12:01:29 +0100 Subject: [PATCH 05/12] Bump certifi from 2022.12.7 to 2023.7.22 in /requirements (#135) Bumps [certifi](https://github.com/certifi/python-certifi) from 2022.12.7 to 2023.7.22. - [Commits](https://github.com/certifi/python-certifi/compare/2022.12.07...2023.07.22) --- updated-dependencies: - dependency-name: certifi dependency-type: indirect ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- requirements/docs.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/docs.txt b/requirements/docs.txt index 2782252..85ac479 100644 --- a/requirements/docs.txt +++ b/requirements/docs.txt @@ -6,7 +6,7 @@ # ansi2html==1.8.0 # via -r docs.in -certifi==2022.12.7 +certifi==2023.7.22 # via requests charset-normalizer==3.1.0 # via requests From 00047cb12c3b5245d9ad569e41b8b0d4c06bc8e5 Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Thu, 17 Aug 2023 12:02:57 +0100 Subject: [PATCH 06/12] support dataclasses with slots (#136) --- devtools/prettier.py | 7 ++++++- tests/test_prettier.py | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/devtools/prettier.py b/devtools/prettier.py index 4f274de..c45bc6a 100644 --- a/devtools/prettier.py +++ b/devtools/prettier.py @@ -254,7 +254,12 @@ def _format_ast_expression(self, value: ast.AST, _: str, indent_current: int, in self._stream.write(indent_current * self._c + line) def _format_dataclass(self, value: 'Any', _: str, indent_current: int, indent_new: int) -> None: - self._format_fields(value, value.__dict__.items(), indent_current, indent_new) + try: + field_items = value.__dict__.items() + except AttributeError: + # slots + field_items = ((f, getattr(value, f)) for f in value.__slots__) + self._format_fields(value, field_items, indent_current, indent_new) def _format_sqlalchemy_class(self, value: 'Any', _: str, indent_current: int, indent_new: int) -> None: if sa_inspect is not None: diff --git a/tests/test_prettier.py b/tests/test_prettier.py index 6a0247c..298dc58 100644 --- a/tests/test_prettier.py +++ b/tests/test_prettier.py @@ -255,6 +255,30 @@ class BarDataclass: ) +def test_dataclass_slots(): + try: + dec = dataclass(slots=True) + except TypeError: + pytest.skip('dataclasses.slots not available') + + @dec + class FooDataclass: + x: int + y: str + + f = FooDataclass(123, 'bar') + v = pformat(f) + print(v) + assert ( + v + == """\ +FooDataclass( + x=123, + y='bar', +)""" + ) + + @pytest.mark.skipif(numpy is None, reason='numpy not installed') def test_indent_numpy(): v = pformat({'numpy test': numpy.array(range(20))}) From 6eac2ca7e63114d4bb44f6e1366673d16b0eaef6 Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Thu, 17 Aug 2023 12:18:53 +0100 Subject: [PATCH 07/12] Make `Pygments` required (#137) --- README.md | 5 +---- docs/install.md | 6 ++---- pyproject.toml | 4 +++- requirements/docs.in | 1 - requirements/docs.txt | 20 +++++++++----------- requirements/testing.in | 1 - requirements/testing.txt | 33 ++++++++++++++++++--------------- 7 files changed, 33 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index 55e69e0..c660d28 100644 --- a/README.md +++ b/README.md @@ -15,12 +15,9 @@ For more information, see [documentation](https://python-devtools.helpmanual.io/ Just ```bash -pip install devtools[pygments] +pip install devtools ``` -`pygments` is not required but if it's installed, output will be highlighted and easier to read. - -`devtools` has no other required dependencies except python 3.7, 3.8, 3.9, 3.10 or 3.11. If you've got python 3.7+ and `pip` installed, you're good to go. ## Usage diff --git a/docs/install.md b/docs/install.md index 94630bb..a1ceba7 100644 --- a/docs/install.md +++ b/docs/install.md @@ -1,10 +1,8 @@ Installation is as simple as: ```bash -pip install devtools[pygments] +pip install devtools ``` -`pygments` is not required but if it's installed, output will be highlighted and easier to read. - -`devtools` has no other required dependencies except python 3.7, 3.8, 3.9, 3.10 or 3.11. +`devtools` has [very few dependencies](https://github.com/samuelcolvin/python-devtools/blob/main/pyproject.toml#L37). If you've got python 3.7+ and `pip` installed, you're good to go. diff --git a/pyproject.toml b/pyproject.toml index 7e7c87f..28a9ecf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -37,8 +37,10 @@ requires-python = '>=3.7' dependencies = [ 'executing>=1.1.1', 'asttokens>=2.0.0,<3.0.0', + 'Pygments>=2.15.0', ] -optional-dependencies = {pygments = ['Pygments>=2.2.0'] } +# keep this meaningless group around to avoid breaking installs using `pip install devtools[pygments]` +optional-dependencies = {pygments = [] } dynamic = ['version'] [project.urls] diff --git a/requirements/docs.in b/requirements/docs.in index be48235..caf159b 100644 --- a/requirements/docs.in +++ b/requirements/docs.in @@ -4,6 +4,5 @@ mkdocs-exclude mkdocs-material mkdocs-simple-hooks markdown-include -pygments ruff numpy diff --git a/requirements/docs.txt b/requirements/docs.txt index 85ac479..b2d5b9f 100644 --- a/requirements/docs.txt +++ b/requirements/docs.txt @@ -5,7 +5,7 @@ # pip-compile --output-file=requirements/docs.txt --resolver=backtracking requirements/docs.in # ansi2html==1.8.0 - # via -r docs.in + # via -r requirements/docs.in certifi==2023.7.22 # via requests charset-normalizer==3.1.0 @@ -29,33 +29,31 @@ markdown==3.3.7 # mkdocs-material # pymdown-extensions markdown-include==0.8.1 - # via -r docs.in + # via -r requirements/docs.in markupsafe==2.1.2 # via jinja2 mergedeep==1.3.4 # via mkdocs mkdocs==1.4.2 # via - # -r docs.in + # -r requirements/docs.in # mkdocs-exclude # mkdocs-material # mkdocs-simple-hooks mkdocs-exclude==1.0.2 - # via -r docs.in + # via -r requirements/docs.in mkdocs-material==9.1.5 - # via -r docs.in + # via -r requirements/docs.in mkdocs-material-extensions==1.1.1 # via mkdocs-material mkdocs-simple-hooks==0.1.5 - # via -r docs.in + # via -r requirements/docs.in numpy==1.24.2 - # via -r docs.in + # via -r requirements/docs.in packaging==23.0 # via mkdocs pygments==2.15.0 - # via - # -r docs.in - # mkdocs-material + # via mkdocs-material pymdown-extensions==10.0 # via mkdocs-material python-dateutil==2.8.2 @@ -72,7 +70,7 @@ regex==2023.3.23 requests==2.31.0 # via mkdocs-material ruff==0.0.261 - # via -r docs.in + # via -r requirements/docs.in six==1.16.0 # via python-dateutil urllib3==1.26.15 diff --git a/requirements/testing.in b/requirements/testing.in index 0543021..6a3232a 100644 --- a/requirements/testing.in +++ b/requirements/testing.in @@ -1,5 +1,4 @@ coverage[toml] -pygments pytest pytest-mock pytest-pretty diff --git a/requirements/testing.txt b/requirements/testing.txt index ace238f..a3b4099 100644 --- a/requirements/testing.txt +++ b/requirements/testing.txt @@ -5,17 +5,17 @@ # pip-compile --output-file=requirements/testing.txt --resolver=backtracking requirements/testing.in # asyncpg==0.27.0 ; python_version >= "3.8" - # via -r testing.in + # via -r requirements/testing.in attrs==22.2.0 # via pytest black==23.3.0 - # via -r testing.in + # via -r requirements/testing.in click==8.1.3 # via black coverage[toml]==7.2.2 - # via -r testing.in -greenlet==2.0.2 - # via sqlalchemy + # via -r requirements/testing.in +exceptiongroup==1.1.3 + # via pytest iniconfig==2.0.0 # via pytest markdown-it-py==2.2.0 @@ -23,11 +23,11 @@ markdown-it-py==2.2.0 mdurl==0.1.2 # via markdown-it-py multidict==6.0.4 ; python_version >= "3.8" - # via -r testing.in + # via -r requirements/testing.in mypy-extensions==1.0.0 # via black numpy==1.24.2 ; python_version >= "3.8" - # via -r testing.in + # via -r requirements/testing.in packaging==23.0 # via # black @@ -39,24 +39,27 @@ platformdirs==3.2.0 pluggy==1.0.0 # via pytest pydantic==1.10.7 - # via -r testing.in + # via -r requirements/testing.in pygments==2.15.0 - # via - # -r testing.in - # rich + # via rich pytest==7.2.2 # via - # -r testing.in + # -r requirements/testing.in # pytest-mock # pytest-pretty pytest-mock==3.10.0 - # via -r testing.in + # via -r requirements/testing.in pytest-pretty==1.2.0 - # via -r testing.in + # via -r requirements/testing.in rich==13.3.3 # via pytest-pretty sqlalchemy==2.0.8 - # via -r testing.in + # via -r requirements/testing.in +tomli==2.0.1 + # via + # black + # coverage + # pytest typing-extensions==4.5.0 # via # pydantic From e4937c984d516827577f4a909174d36339414a9a Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Thu, 17 Aug 2023 12:20:46 +0100 Subject: [PATCH 08/12] Uprev 0.12.0 (#138) --- HISTORY.md | 14 ++++++++++++++ devtools/version.py | 2 +- runtime.txt | 1 - 3 files changed, 15 insertions(+), 2 deletions(-) delete mode 100644 runtime.txt diff --git a/HISTORY.md b/HISTORY.md index 1aa231e..8cf5103 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,17 @@ +## v0.12.0 (2023-08-17) + +* build docs on CI by @samuelcolvin in #127 +* Update usage to reflect the recent addition of the pytest plugin by @tomhamiltonstubber in #128 +* support dataclasses with slots by @samuelcolvin in #136 +* Make `Pygments` required #137 + +## v0.11.0 (2023-04-05) + +* added support for sqlalchemy2 by @the-vty in #120 +* switch to ruff by @samuelcolvin in #124 +* support displaying ast types by @samuelcolvin in #125 +* Insert assert by @samuelcolvin in #126 + ## v0.10.0 (2022-11-28) * Use secure builtins standard module, instead of the `__builtins__` by @0xsirsaif in #109 diff --git a/devtools/version.py b/devtools/version.py index d3c01ed..bf3b89a 100644 --- a/devtools/version.py +++ b/devtools/version.py @@ -1 +1 @@ -VERSION = '0.11.0' +VERSION = '0.12.0' diff --git a/runtime.txt b/runtime.txt deleted file mode 100644 index cc1923a..0000000 --- a/runtime.txt +++ /dev/null @@ -1 +0,0 @@ -3.8 From f080d39dfe8ff86ef3d2483616cd70c2fe8b5cc9 Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Thu, 17 Aug 2023 15:49:53 +0100 Subject: [PATCH 09/12] fix docs publish --- .github/workflows/ci.yml | 3 ++- HISTORY.md | 4 ++++ devtools/version.py | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bcfe8bf..3df53d6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -134,7 +134,8 @@ jobs: path: site - name: check GITHUB_REF matches package version - uses: samuelcolvin/check-python-version@v3 + id: check-tag + uses: samuelcolvin/check-python-version@v4.1 with: version_file_path: devtools/version.py diff --git a/HISTORY.md b/HISTORY.md index 8cf5103..ddf0bda 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,7 @@ +## v0.12.1 (2023-08-17) + +fix docs release + ## v0.12.0 (2023-08-17) * build docs on CI by @samuelcolvin in #127 diff --git a/devtools/version.py b/devtools/version.py index bf3b89a..b0ec321 100644 --- a/devtools/version.py +++ b/devtools/version.py @@ -1 +1 @@ -VERSION = '0.12.0' +VERSION = '0.12.1' From ec406ffdd841f65b132e81f3d715321d3cfb5efa Mon Sep 17 00:00:00 2001 From: Samuel Colvin Date: Sun, 3 Sep 2023 17:50:32 +0100 Subject: [PATCH 10/12] install debug into `builtins` via `DebugProxy` (#139) --- Makefile | 2 +- devtools/__main__.py | 51 +++++++++++++++++++++++++++----------------- devtools/debug.py | 21 ++++++++++++------ devtools/version.py | 2 +- 4 files changed, 48 insertions(+), 28 deletions(-) diff --git a/Makefile b/Makefile index eecc748..51b877c 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ update-lockfiles: .PHONY: format format: black $(sources) - ruff $(sources) --fix --exit-zero + ruff $(sources) --fix-only .PHONY: lint lint: diff --git a/devtools/__main__.py b/devtools/__main__.py index bfc6155..2fbc79a 100644 --- a/devtools/__main__.py +++ b/devtools/__main__.py @@ -7,17 +7,32 @@ # language=python install_code = """ # add devtools `debug` function to builtins -import sys -# we don't install here for pytest as it breaks pytest, it is -# installed later by a pytest fixture -if not sys.argv[0].endswith('pytest'): - import builtins - try: - from devtools import debug - except ImportError: - pass - else: - setattr(builtins, 'debug', debug) +# we don't want to import devtools until it's required since it breaks pytest, hence this proxy +class DebugProxy: + def __init__(self): + self._debug = None + + def _import_debug(self): + if self._debug is None: + from devtools import debug + self._debug = debug + + def __call__(self, *args, **kwargs): + self._import_debug() + kwargs['frame_depth_'] = 3 + return self._debug(*args, **kwargs) + + def format(self, *args, **kwargs): + self._import_debug() + kwargs['frame_depth_'] = 3 + return self._debug.format(*args, **kwargs) + + def __getattr__(self, item): + self._import_debug() + return getattr(self._debug, item) + +import builtins +setattr(builtins, 'debug', DebugProxy()) """ @@ -27,12 +42,6 @@ def print_code() -> int: def install() -> int: - print('[WARNING: this command is experimental, report issues at github.com/samuelcolvin/python-devtools]\n') - - if hasattr(builtins, 'debug'): - print('Looks like devtools is already installed.') - return 0 - try: import sitecustomize # type: ignore except ImportError: @@ -48,7 +57,11 @@ def install() -> int: else: install_path = Path(sitecustomize.__file__) - print(f'Found path "{install_path}" to install devtools into __builtins__') + if hasattr(builtins, 'debug'): + print(f'Looks like devtools is already installed, probably in `{install_path}`.') + return 0 + + print(f'Found path `{install_path}` to install devtools into `builtins`') print('To install devtools, run the following command:\n') print(f' python -m devtools print-code >> {install_path}\n') if not install_path.is_relative_to(Path.home()): @@ -65,5 +78,5 @@ def install() -> int: elif 'print-code' in sys.argv: sys.exit(print_code()) else: - print(f'python-devtools v{VERSION}, CLI usage: python -m devtools [install|print-code]') + print(f'python-devtools v{VERSION}, CLI usage: `python -m devtools install|print-code`') sys.exit(1) diff --git a/devtools/debug.py b/devtools/debug.py index 5ea836a..89cda24 100644 --- a/devtools/debug.py +++ b/devtools/debug.py @@ -112,8 +112,15 @@ def __init__(self, *, warnings: 'Optional[bool]' = None, highlight: 'Optional[bo self._show_warnings = env_bool(warnings, 'PY_DEVTOOLS_WARNINGS', True) self._highlight = highlight - def __call__(self, *args: 'Any', file_: 'Any' = None, flush_: bool = True, **kwargs: 'Any') -> 'Any': - d_out = self._process(args, kwargs) + def __call__( + self, + *args: 'Any', + file_: 'Any' = None, + flush_: bool = True, + frame_depth_: int = 2, + **kwargs: 'Any', + ) -> 'Any': + d_out = self._process(args, kwargs, frame_depth_) s = d_out.str(use_highlight(self._highlight, file_)) print(s, file=file_, flush=flush_) if kwargs: @@ -123,8 +130,8 @@ def __call__(self, *args: 'Any', file_: 'Any' = None, flush_: bool = True, **kwa else: return args - def format(self, *args: 'Any', **kwargs: 'Any') -> DebugOutput: - return self._process(args, kwargs) + def format(self, *args: 'Any', frame_depth_: int = 2, **kwargs: 'Any') -> DebugOutput: + return self._process(args, kwargs, frame_depth_) def breakpoint(self) -> None: import pdb @@ -134,13 +141,13 @@ def breakpoint(self) -> None: def timer(self, name: 'Optional[str]' = None, *, verbose: bool = True, file: 'Any' = None, dp: int = 3) -> Timer: return Timer(name=name, verbose=verbose, file=file, dp=dp) - def _process(self, args: 'Any', kwargs: 'Any') -> DebugOutput: + def _process(self, args: 'Any', kwargs: 'Any', frame_depth: int) -> DebugOutput: """ - BEWARE: this must be called from a function exactly 2 levels below the top of the stack. + BEWARE: this must be called from a function exactly `frame_depth` levels below the top of the stack. """ # HELP: any errors other than ValueError from _getframe? If so please submit an issue try: - call_frame: 'FrameType' = sys._getframe(2) + call_frame: 'FrameType' = sys._getframe(frame_depth) except ValueError: # "If [ValueError] is deeper than the call stack, ValueError is raised" return self.output_class( diff --git a/devtools/version.py b/devtools/version.py index b0ec321..a4ba93b 100644 --- a/devtools/version.py +++ b/devtools/version.py @@ -1 +1 @@ -VERSION = '0.12.1' +VERSION = '0.12.2' From 2aea99d95f4766fbca86139f72a1e4985d10a30e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartosz=20S=C5=82awecki?= Date: Fri, 26 Jan 2024 20:10:51 +0100 Subject: [PATCH 11/12] BUG FIX: Use `Path.relative_to()` for Python 3.8 compatibility (#150) --- devtools/__main__.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/devtools/__main__.py b/devtools/__main__.py index 2fbc79a..a5fa2f5 100644 --- a/devtools/__main__.py +++ b/devtools/__main__.py @@ -64,7 +64,9 @@ def install() -> int: print(f'Found path `{install_path}` to install devtools into `builtins`') print('To install devtools, run the following command:\n') print(f' python -m devtools print-code >> {install_path}\n') - if not install_path.is_relative_to(Path.home()): + try: + install_path.relative_to(Path.home()) + except ValueError: print('or maybe\n') print(f' python -m devtools print-code | sudo tee -a {install_path} > /dev/null\n') print('Note: "sudo" might be required because the path is in your home directory.') From 5022f1f6f1c55d871b1db208c9c1b2ab0df488fe Mon Sep 17 00:00:00 2001 From: Kinuax Date: Fri, 24 Jan 2025 20:11:42 +0100 Subject: [PATCH 12/12] Fix macos-latest and 3.7 tests (#155) --- .github/workflows/ci.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3df53d6..e131174 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -55,15 +55,21 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu, macos, windows] + os: [ubuntu-latest, macos-latest, windows-latest] python-version: ['3.7', '3.8', '3.9', '3.10', '3.11'] + exclude: + - os: macos-latest + python-version: '3.7' + include: + - os: macos-13 + python-version: '3.7' env: PYTHON: ${{ matrix.python-version }} OS: ${{ matrix.os }} EXTRAS: yes - runs-on: ${{ matrix.os }}-latest + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v3