Script 'mail_helper' called by obssrc Hello community, here is the log from the commit of package python-referencing for openSUSE:Factory checked in at 2023-06-01 17:21:12 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/python-referencing (Old) and /work/SRC/openSUSE:Factory/.python-referencing.new.2531 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "python-referencing" Thu Jun 1 17:21:12 2023 rev:13 rq:1090261 version:0.29.0 Changes: -------- --- /work/SRC/openSUSE:Factory/python-referencing/python-referencing.changes 2023-05-26 20:15:50.068391766 +0200 +++ /work/SRC/openSUSE:Factory/.python-referencing.new.2531/python-referencing.changes 2023-06-01 17:21:13.378765940 +0200 @@ -1,0 +2,17 @@ +Thu Jun 01 05:26:32 UTC 2023 - ka...@b1-systems.de + +- Update to version 0.29.0: + * Implement referencing.retrieval.to_cached_resource + * Ensure more things raise non-subclassable exceptions. + +------------------------------------------------------------------- +Thu Jun 01 05:24:45 UTC 2023 - ka...@b1-systems.de + +- Update to version 0.28.6: + * Move to using Trusted Publishers. + * Ensure twine checks the README in strict mode. + * [pre-commit.ci] pre-commit autoupdate + * Enable markdown coverage in CI. + * Try again with the extra coverage job in CI. + +------------------------------------------------------------------- Old: ---- referencing-0.28.5.tar.gz New: ---- referencing-0.29.0.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ python-referencing.spec ++++++ --- /var/tmp/diff_new_pack.MwW7qs/_old 2023-06-01 17:21:13.870768857 +0200 +++ /var/tmp/diff_new_pack.MwW7qs/_new 2023-06-01 17:21:13.874768880 +0200 @@ -26,7 +26,7 @@ %endif %{?sle15_python_module_pythons} Name: python-referencing%{psuffix} -Version: 0.28.5 +Version: 0.29.0 Release: 0 Summary: JSON Referencing + Python License: MIT ++++++ _service ++++++ --- /var/tmp/diff_new_pack.MwW7qs/_old 2023-06-01 17:21:13.922769165 +0200 +++ /var/tmp/diff_new_pack.MwW7qs/_new 2023-06-01 17:21:13.926769189 +0200 @@ -2,7 +2,7 @@ <service name="tar_scm" mode="disabled"> <param name="url">https://github.com/python-jsonschema/referencing</param> <param name="scm">git</param> - <param name="revision">v0.28.5</param> + <param name="revision">v0.29.0</param> <param name="versionformat">@PARENT_TAG@</param> <param name="changesgenerate">enable</param> <param name="versionrewrite-pattern">v(.*)</param> ++++++ _servicedata ++++++ --- /var/tmp/diff_new_pack.MwW7qs/_old 2023-06-01 17:21:13.954769355 +0200 +++ /var/tmp/diff_new_pack.MwW7qs/_new 2023-06-01 17:21:13.958769379 +0200 @@ -1,6 +1,6 @@ <servicedata> <service name="tar_scm"> <param name="url">https://github.com/python-jsonschema/referencing</param> - <param name="changesrevision">c22e9213bb9390cfdfef9e06efb987979531a4b7</param></service></servicedata> + <param name="changesrevision">70beea99924cd2ed29a1ffec153e278953b29e4c</param></service></servicedata> (No newline at EOF) ++++++ referencing-0.28.5.tar.gz -> referencing-0.29.0.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/referencing-0.28.5/.git/FETCH_HEAD new/referencing-0.29.0/.git/FETCH_HEAD --- old/referencing-0.28.5/.git/FETCH_HEAD 2023-05-24 21:33:11.000000000 +0200 +++ new/referencing-0.29.0/.git/FETCH_HEAD 2023-06-01 00:42:33.000000000 +0200 @@ -1,2 +1,2 @@ -fb511b359283c2543b3e6972b849b1c7edae5703 not-for-merge branch 'main' of https://github.com/python-jsonschema/referencing +70beea99924cd2ed29a1ffec153e278953b29e4c not-for-merge branch 'main' of https://github.com/python-jsonschema/referencing 29f587735daddcf3fde3318382227e6d1f561e6a not-for-merge branch 'retrieval' of https://github.com/python-jsonschema/referencing diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/referencing-0.28.5/.git/HEAD new/referencing-0.29.0/.git/HEAD --- old/referencing-0.28.5/.git/HEAD 2023-05-24 21:33:11.000000000 +0200 +++ new/referencing-0.29.0/.git/HEAD 2023-06-01 00:42:33.000000000 +0200 @@ -1 +1 @@ -c22e9213bb9390cfdfef9e06efb987979531a4b7 +70beea99924cd2ed29a1ffec153e278953b29e4c diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/referencing-0.28.5/.git/ORIG_HEAD new/referencing-0.29.0/.git/ORIG_HEAD --- old/referencing-0.28.5/.git/ORIG_HEAD 2023-05-24 21:33:11.000000000 +0200 +++ new/referencing-0.29.0/.git/ORIG_HEAD 2023-06-01 00:42:33.000000000 +0200 @@ -1 +1 @@ -1cbc3eed952d93f32405d602d45c061e122f7dc8 +d96c797dc64aa869c8819aff5f41d0f398bcad1b Binary files old/referencing-0.28.5/.git/index and new/referencing-0.29.0/.git/index differ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/referencing-0.28.5/.git/logs/HEAD new/referencing-0.29.0/.git/logs/HEAD --- old/referencing-0.28.5/.git/logs/HEAD 2023-05-24 21:33:11.000000000 +0200 +++ new/referencing-0.29.0/.git/logs/HEAD 2023-06-01 00:42:33.000000000 +0200 @@ -22,3 +22,8 @@ 10376f502c5ae5f56a4e7e3c46ca06443e81cdc3 de0d25830a19539d8b0bb31c8661ad65f80011cc Johannes Kastl <ka...@b1-systems.de> 1684904505 +0200 reset: moving to v0.28.4 de0d25830a19539d8b0bb31c8661ad65f80011cc 1cbc3eed952d93f32405d602d45c061e122f7dc8 Johannes Kastl <ka...@b1-systems.de> 1684995842 +0200 merge v0.28.5: Merge made by the 'ort' strategy. 1cbc3eed952d93f32405d602d45c061e122f7dc8 c22e9213bb9390cfdfef9e06efb987979531a4b7 Johannes Kastl <ka...@b1-systems.de> 1684995843 +0200 reset: moving to v0.28.5 +c22e9213bb9390cfdfef9e06efb987979531a4b7 75cc858e35b3e6953a2b4240e57a53565966c9cd Johannes Kastl <ka...@b1-systems.de> 1685597053 +0200 merge v0.29.0: Merge made by the 'ort' strategy. +75cc858e35b3e6953a2b4240e57a53565966c9cd 70beea99924cd2ed29a1ffec153e278953b29e4c Johannes Kastl <ka...@b1-systems.de> 1685597053 +0200 reset: moving to v0.29.0 +70beea99924cd2ed29a1ffec153e278953b29e4c cfe47262c5f9956601b3fa59c86638d003669d7c Johannes Kastl <ka...@b1-systems.de> 1685597084 +0200 reset: moving to v0.28.6 +cfe47262c5f9956601b3fa59c86638d003669d7c d96c797dc64aa869c8819aff5f41d0f398bcad1b Johannes Kastl <ka...@b1-systems.de> 1685597191 +0200 merge v0.29.0: Merge made by the 'ort' strategy. +d96c797dc64aa869c8819aff5f41d0f398bcad1b 70beea99924cd2ed29a1ffec153e278953b29e4c Johannes Kastl <ka...@b1-systems.de> 1685597191 +0200 reset: moving to v0.29.0 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/referencing-0.28.5/.git/logs/refs/remotes/origin/main new/referencing-0.29.0/.git/logs/refs/remotes/origin/main --- old/referencing-0.28.5/.git/logs/refs/remotes/origin/main 2023-05-24 21:33:11.000000000 +0200 +++ new/referencing-0.29.0/.git/logs/refs/remotes/origin/main 2023-06-01 00:42:33.000000000 +0200 @@ -12,3 +12,4 @@ a22cd842aa769fd06c7d3ad256015fead9e71d10 381a7310b8b88abc65c46ec3ec905faf0fbd02db Johannes Kastl <ka...@b1-systems.de> 1684828523 +0200 fetch --filter=tree:0 --tags: fast-forward 381a7310b8b88abc65c46ec3ec905faf0fbd02db de0d25830a19539d8b0bb31c8661ad65f80011cc Johannes Kastl <ka...@b1-systems.de> 1684904499 +0200 fetch --filter=tree:0 --tags: fast-forward de0d25830a19539d8b0bb31c8661ad65f80011cc fb511b359283c2543b3e6972b849b1c7edae5703 Johannes Kastl <ka...@b1-systems.de> 1684995839 +0200 fetch --filter=tree:0 --tags: fast-forward +fb511b359283c2543b3e6972b849b1c7edae5703 70beea99924cd2ed29a1ffec153e278953b29e4c Johannes Kastl <ka...@b1-systems.de> 1685597049 +0200 fetch --filter=tree:0 --tags: fast-forward Binary files old/referencing-0.28.5/.git/objects/75/cc858e35b3e6953a2b4240e57a53565966c9cd and new/referencing-0.29.0/.git/objects/75/cc858e35b3e6953a2b4240e57a53565966c9cd differ Binary files old/referencing-0.28.5/.git/objects/d9/6c797dc64aa869c8819aff5f41d0f398bcad1b and new/referencing-0.29.0/.git/objects/d9/6c797dc64aa869c8819aff5f41d0f398bcad1b differ Binary files old/referencing-0.28.5/.git/objects/pack/pack-197d2e590900ec130224673d07c1bfa1b2d3812e.idx and new/referencing-0.29.0/.git/objects/pack/pack-197d2e590900ec130224673d07c1bfa1b2d3812e.idx differ Binary files old/referencing-0.28.5/.git/objects/pack/pack-197d2e590900ec130224673d07c1bfa1b2d3812e.pack and new/referencing-0.29.0/.git/objects/pack/pack-197d2e590900ec130224673d07c1bfa1b2d3812e.pack differ Binary files old/referencing-0.28.5/.git/objects/pack/pack-203243277bfa58a30fd60e10e48b3207be4efeb1.idx and new/referencing-0.29.0/.git/objects/pack/pack-203243277bfa58a30fd60e10e48b3207be4efeb1.idx differ Binary files old/referencing-0.28.5/.git/objects/pack/pack-203243277bfa58a30fd60e10e48b3207be4efeb1.pack and new/referencing-0.29.0/.git/objects/pack/pack-203243277bfa58a30fd60e10e48b3207be4efeb1.pack differ Binary files old/referencing-0.28.5/.git/objects/pack/pack-21a918cfc90aec1fa1dbec48b2fe293e685ddc39.idx and new/referencing-0.29.0/.git/objects/pack/pack-21a918cfc90aec1fa1dbec48b2fe293e685ddc39.idx differ Binary files old/referencing-0.28.5/.git/objects/pack/pack-21a918cfc90aec1fa1dbec48b2fe293e685ddc39.pack and new/referencing-0.29.0/.git/objects/pack/pack-21a918cfc90aec1fa1dbec48b2fe293e685ddc39.pack differ Binary files old/referencing-0.28.5/.git/objects/pack/pack-4f64e0b1754f46dab7e2180b335dc08150173184.idx and new/referencing-0.29.0/.git/objects/pack/pack-4f64e0b1754f46dab7e2180b335dc08150173184.idx differ Binary files old/referencing-0.28.5/.git/objects/pack/pack-4f64e0b1754f46dab7e2180b335dc08150173184.pack and new/referencing-0.29.0/.git/objects/pack/pack-4f64e0b1754f46dab7e2180b335dc08150173184.pack differ Binary files old/referencing-0.28.5/.git/objects/pack/pack-732f9e37cfc8e67202615a5568f9368f8e98212b.idx and new/referencing-0.29.0/.git/objects/pack/pack-732f9e37cfc8e67202615a5568f9368f8e98212b.idx differ Binary files old/referencing-0.28.5/.git/objects/pack/pack-732f9e37cfc8e67202615a5568f9368f8e98212b.pack and new/referencing-0.29.0/.git/objects/pack/pack-732f9e37cfc8e67202615a5568f9368f8e98212b.pack differ Binary files old/referencing-0.28.5/.git/objects/pack/pack-7884c3ddfe9a301931c7a3408af6eb19f80ef2ff.idx and new/referencing-0.29.0/.git/objects/pack/pack-7884c3ddfe9a301931c7a3408af6eb19f80ef2ff.idx differ Binary files old/referencing-0.28.5/.git/objects/pack/pack-7884c3ddfe9a301931c7a3408af6eb19f80ef2ff.pack and new/referencing-0.29.0/.git/objects/pack/pack-7884c3ddfe9a301931c7a3408af6eb19f80ef2ff.pack differ Binary files old/referencing-0.28.5/.git/objects/pack/pack-838a754ce3dece66eff1c50e0e3d1663b3d6dc2b.idx and new/referencing-0.29.0/.git/objects/pack/pack-838a754ce3dece66eff1c50e0e3d1663b3d6dc2b.idx differ Binary files old/referencing-0.28.5/.git/objects/pack/pack-838a754ce3dece66eff1c50e0e3d1663b3d6dc2b.pack and new/referencing-0.29.0/.git/objects/pack/pack-838a754ce3dece66eff1c50e0e3d1663b3d6dc2b.pack differ Binary files old/referencing-0.28.5/.git/objects/pack/pack-9a135a62bfbd2cf5dd2fd2d47418dd3b210263e8.idx and new/referencing-0.29.0/.git/objects/pack/pack-9a135a62bfbd2cf5dd2fd2d47418dd3b210263e8.idx differ Binary files old/referencing-0.28.5/.git/objects/pack/pack-9a135a62bfbd2cf5dd2fd2d47418dd3b210263e8.pack and new/referencing-0.29.0/.git/objects/pack/pack-9a135a62bfbd2cf5dd2fd2d47418dd3b210263e8.pack differ Binary files old/referencing-0.28.5/.git/objects/pack/pack-b6e42b8c848ff517233178ef5c0302a5f85dac96.idx and new/referencing-0.29.0/.git/objects/pack/pack-b6e42b8c848ff517233178ef5c0302a5f85dac96.idx differ Binary files old/referencing-0.28.5/.git/objects/pack/pack-b6e42b8c848ff517233178ef5c0302a5f85dac96.pack and new/referencing-0.29.0/.git/objects/pack/pack-b6e42b8c848ff517233178ef5c0302a5f85dac96.pack differ Binary files old/referencing-0.28.5/.git/objects/pack/pack-f2bb08f10f6f64396d66a5a667652626a23cbc90.idx and new/referencing-0.29.0/.git/objects/pack/pack-f2bb08f10f6f64396d66a5a667652626a23cbc90.idx differ Binary files old/referencing-0.28.5/.git/objects/pack/pack-f2bb08f10f6f64396d66a5a667652626a23cbc90.pack and new/referencing-0.29.0/.git/objects/pack/pack-f2bb08f10f6f64396d66a5a667652626a23cbc90.pack differ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/referencing-0.28.5/.git/refs/remotes/origin/main new/referencing-0.29.0/.git/refs/remotes/origin/main --- old/referencing-0.28.5/.git/refs/remotes/origin/main 2023-05-24 21:33:11.000000000 +0200 +++ new/referencing-0.29.0/.git/refs/remotes/origin/main 2023-06-01 00:42:33.000000000 +0200 @@ -1 +1 @@ -fb511b359283c2543b3e6972b849b1c7edae5703 +70beea99924cd2ed29a1ffec153e278953b29e4c diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/referencing-0.28.5/.git/refs/tags/v0.28.6 new/referencing-0.29.0/.git/refs/tags/v0.28.6 --- old/referencing-0.28.5/.git/refs/tags/v0.28.6 1970-01-01 01:00:00.000000000 +0100 +++ new/referencing-0.29.0/.git/refs/tags/v0.28.6 2023-06-01 00:42:33.000000000 +0200 @@ -0,0 +1 @@ +ee5e721b018710aa3545889618794d645a6defb0 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/referencing-0.28.5/.git/refs/tags/v0.29.0 new/referencing-0.29.0/.git/refs/tags/v0.29.0 --- old/referencing-0.28.5/.git/refs/tags/v0.29.0 1970-01-01 01:00:00.000000000 +0100 +++ new/referencing-0.29.0/.git/refs/tags/v0.29.0 2023-06-01 00:42:33.000000000 +0200 @@ -0,0 +1 @@ +7b23d79bf649889eee94900929174a132abe7dfb diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/referencing-0.28.5/.github/workflows/ci.yml new/referencing-0.29.0/.github/workflows/ci.yml --- old/referencing-0.28.5/.github/workflows/ci.yml 2023-05-24 21:33:11.000000000 +0200 +++ new/referencing-0.29.0/.github/workflows/ci.yml 2023-06-01 00:42:33.000000000 +0200 @@ -47,10 +47,10 @@ fail-fast: false matrix: noxenv: ${{ fromJson(needs.list.outputs.noxenvs) }} + posargs: [""] include: - - os: ubuntu-latest - noxenv: "tests-3.11" - posargs: ghcoverage + - noxenv: tests-3.11 + posargs: coverage github steps: - uses: actions/checkout@v3 @@ -74,6 +74,12 @@ packaging: needs: ci runs-on: ubuntu-latest + environment: + name: PyPI + url: https://pypi.org/p/referencing + permissions: + contents: write + id-token: write steps: - uses: actions/checkout@v3 @@ -88,8 +94,6 @@ - name: Publish to PyPI if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags') uses: pypa/gh-action-pypi-publish@release/v1 - with: - password: ${{ secrets.pypi_password }} - name: Create a Release if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags') uses: softprops/action-gh-release@v1 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/referencing-0.28.5/.pre-commit-config.yaml new/referencing-0.29.0/.pre-commit-config.yaml --- old/referencing-0.28.5/.pre-commit-config.yaml 2023-05-24 21:33:11.000000000 +0200 +++ new/referencing-0.29.0/.pre-commit-config.yaml 2023-06-01 00:42:33.000000000 +0200 @@ -13,7 +13,7 @@ args: [--fix, lf] - id: trailing-whitespace - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: "v0.0.269" + rev: "v0.0.270" hooks: - id: ruff - repo: https://github.com/PyCQA/isort diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/referencing-0.28.5/docs/api.rst new/referencing-0.29.0/docs/api.rst --- old/referencing-0.28.5/docs/api.rst 2023-05-24 21:33:11.000000000 +0200 +++ new/referencing-0.29.0/docs/api.rst 2023-06-01 00:42:33.000000000 +0200 @@ -18,7 +18,7 @@ :undoc-members: -.. autoclass:: referencing._core.T +.. autoclass:: referencing._core.AnchorOrResource .. autoclass:: referencing._core.Resolver @@ -51,6 +51,17 @@ :undoc-members: +referencing.retrieval +^^^^^^^^^^^^^^^^^^^^^ + +.. automodule:: referencing.retrieval + :members: + :undoc-members: + + +.. autoclass:: referencing.retrieval._T + + referencing.typing ^^^^^^^^^^^^^^^^^^ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/referencing-0.28.5/docs/changes.rst new/referencing-0.29.0/docs/changes.rst --- old/referencing-0.28.5/docs/changes.rst 2023-05-24 21:33:11.000000000 +0200 +++ new/referencing-0.29.0/docs/changes.rst 2023-06-01 00:42:33.000000000 +0200 @@ -2,6 +2,31 @@ Changelog ========= +v0.29.0 +------- + +* Add ``referencing.retrieval.to_cached_resource``, a simple caching decorator useful when writing a retrieval function turning JSON text into resources without repeatedly hitting the network, filesystem, etc. + +v0.28.6 +------- + +* No user-facing changes. + +v0.28.5 +------- + +* Fix a type annotation and fill in some missing test coverage. + +v0.28.4 +------- + +* Fix a type annotation. + +v0.28.3 +------- + +* No user-facing changes. + v0.28.2 ------- diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/referencing-0.28.5/docs/intro.rst new/referencing-0.29.0/docs/intro.rst --- old/referencing-0.28.5/docs/intro.rst 2023-05-24 21:33:11.000000000 +0200 +++ new/referencing-0.29.0/docs/intro.rst 2023-06-01 00:42:33.000000000 +0200 @@ -236,3 +236,31 @@ See :kw:`schema-references` in particular. `referencing` will of course therefore not do any such thing automatically, and this section generally assumes that you have personally considered the security implications for your own use case. + +A common concern in these situations is also to *cache* the resulting resource such that repeated lookups of the same URI do not repeatedly make network calls, or hit the filesystem, etc. + +You are of course free to use whatever caching mechanism is convenient (e.g. one specific to ``httpx`` in the above example). + +Because of how common it is to retrieve a JSON string and construct a resource from it however, a decorator which specifically does so is also provided called `referencing.retrieval.to_cached_resource`. +If you use it, note that your retrieval callable should return `str`, not a `Resource`, as the decorator will handle deserializing your response (this is mostly because otherwise, deserialized JSON is generally not hashable). + +The above example would be written: + + +.. code:: python + + from referencing import Registry, Resource + import httpx + import referencing.retrieval + + + @referencing.retrieval.to_cached_resource() + def cached_retrieve_via_httpx(uri): + return httpx.get(uri).text + + + registry = Registry(retrieve=cached_retrieve_via_httpx) + resolver = registry.resolver() + print(resolver.lookup("https://json-schema.org/draft/2020-12/schema")) + +and besides than that it will cache responses and not repeatedly call the retrieval function, it is otherwise functionally equivalent. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/referencing-0.28.5/docs/spelling-wordlist.txt new/referencing-0.29.0/docs/spelling-wordlist.txt --- old/referencing-0.28.5/docs/spelling-wordlist.txt 2023-05-24 21:33:11.000000000 +0200 +++ new/referencing-0.29.0/docs/spelling-wordlist.txt 2023-06-01 00:42:33.000000000 +0200 @@ -5,13 +5,16 @@ deduplication dereferenced deserialized +deserializing discoverability docstrings filesystem +hashable implementers instantiable instantiation iterable +lookups metaschemas referenceable resolvers diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/referencing-0.28.5/noxfile.py new/referencing-0.29.0/noxfile.py --- old/referencing-0.28.5/noxfile.py 2023-05-24 21:33:11.000000000 +0200 +++ new/referencing-0.29.0/noxfile.py 2023-06-01 00:42:33.000000000 +0200 @@ -1,4 +1,5 @@ from pathlib import Path +import os import nox @@ -24,10 +25,26 @@ def tests(session): session.install("-r", ROOT / "test-requirements.txt") - if session.posargs and session.posargs[0] in {"coverage", "ghcoverage"}: + if session.posargs and session.posargs[0] == "coverage": + if len(session.posargs) > 1 and session.posargs[1] == "github": + github = os.environ["GITHUB_STEP_SUMMARY"] + else: + github = None + session.install("coverage[toml]") session.run("coverage", "run", "-m", "pytest", REFERENCING) - session.run("coverage", "report") + if github is None: + session.run("coverage", "report") + else: + with open(github, "a") as summary: + summary.write("### Coverage\n\n") + summary.flush() # without a flush, output seems out of order. + session.run( + "coverage", + "report", + "--format=markdown", + stdout=summary, + ) else: session.run("pytest", *session.posargs, REFERENCING) @@ -50,7 +67,7 @@ session.install("build", "twine") tmpdir = session.create_tmp() session.run("python", "-m", "build", ROOT, "--outdir", tmpdir) - session.run("python", "-m", "twine", "check", tmpdir + "/*") + session.run("python", "-m", "twine", "check", "--strict", tmpdir + "/*") @session(tags=["style"]) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/referencing-0.28.5/referencing/_core.py new/referencing-0.29.0/referencing/_core.py --- old/referencing-0.28.5/referencing/_core.py 2023-05-24 21:33:11.000000000 +0200 +++ new/referencing-0.29.0/referencing/_core.py 2023-06-01 00:42:33.000000000 +0200 @@ -505,16 +505,16 @@ #: An anchor or resource. -T = TypeVar("T", AnchorType[Any], Resource[Any]) +AnchorOrResource = TypeVar("AnchorOrResource", AnchorType[Any], Resource[Any]) @frozen -class Retrieved(Generic[D, T]): +class Retrieved(Generic[D, AnchorOrResource]): """ A value retrieved from a `Registry`. """ - value: T + value: AnchorOrResource registry: Registry[D] diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/referencing-0.28.5/referencing/retrieval.py new/referencing-0.29.0/referencing/retrieval.py --- old/referencing-0.28.5/referencing/retrieval.py 1970-01-01 01:00:00.000000000 +0100 +++ new/referencing-0.29.0/referencing/retrieval.py 2023-06-01 00:42:33.000000000 +0200 @@ -0,0 +1,83 @@ +""" +Helpers related to (dynamic) resource retrieval. +""" +from __future__ import annotations + +from functools import lru_cache +from typing import Callable, TypeVar +import json + +from referencing import Resource +from referencing.typing import URI, D, Retrieve + +#: A serialized document (e.g. a JSON string) +_T = TypeVar("_T") + + +def to_cached_resource( + cache: Callable[[Retrieve[D]], Retrieve[D]] | None = None, + loads: Callable[[_T], D] = json.loads, + from_contents: Callable[[D], Resource[D]] = Resource.from_contents, +) -> Callable[[Callable[[URI], _T]], Retrieve[D]]: + """ + Create a retriever which caches its return values from a simpler callable. + + Takes a function which returns things like serialized JSON (strings) and + returns something suitable for passing to `Registry` as a retrieve + function. + + This decorator both reduces a small bit of boilerplate for a common case + (deserializing JSON from strings and creating `Resource` objects from the + result) as well as makes the probable need for caching a bit easier. + Retrievers which otherwise do expensive operations (like hitting the + network) might otherwise be called repeatedly. + + Examples + -------- + + .. testcode:: + + from referencing import Registry + import referencing.retrieval + + + @referencing.retrieval.to_cached_resource() + def retrieve(uri: str): + print(f"Retrieved {uri}") + + # Normally, go get some expensive JSON from the network, a file ... + return ''' + { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "foo": "bar" + } + ''' + + one = Registry(retrieve=retrieve).get_or_retrieve("urn:example:foo") + print(one.value.contents["foo"]) + + # Retrieving the same URI again reuses the same value (and thus doesn't + # print another retrieval message here) + two = Registry(retrieve=retrieve).get_or_retrieve("urn:example:foo") + print(two.value.contents["foo"]) + + .. testoutput:: + + Retrieved urn:example:foo + bar + bar + + """ + if cache is None: + cache = lru_cache(maxsize=None) + + def decorator(retrieve: Callable[[URI], _T]): + @cache + def cached_retrieve(uri: URI): + response = retrieve(uri) + contents = loads(response) + return from_contents(contents) + + return cached_retrieve + + return decorator diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/referencing-0.28.5/referencing/tests/test_core.py new/referencing-0.29.0/referencing/tests/test_core.py --- old/referencing-0.28.5/referencing/tests/test_core.py 2023-05-24 21:33:11.000000000 +0200 +++ new/referencing-0.29.0/referencing/tests/test_core.py 2023-06-01 00:42:33.000000000 +0200 @@ -357,7 +357,7 @@ two = ID_AND_CHILDREN.create_resource({"foo": "bar"}) three = ID_AND_CHILDREN.create_resource({"baz": "quux"}) - def retrieve(uri): # pragma: no cover + def retrieve(uri): # pragma: no cover pass first = Registry(retrieve=retrieve).with_resource( @@ -992,7 +992,7 @@ @pytest.mark.parametrize( "cls", - [Registry, Resource, Specification], + [Anchor, Registry, Resource, Specification, exceptions.PointerToNowhere], ) def test_nonsubclassable(cls): with pytest.raises(Exception, match="(?i)subclassing"): # noqa: B017 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/referencing-0.28.5/referencing/tests/test_retrieval.py new/referencing-0.29.0/referencing/tests/test_retrieval.py --- old/referencing-0.28.5/referencing/tests/test_retrieval.py 1970-01-01 01:00:00.000000000 +0100 +++ new/referencing-0.29.0/referencing/tests/test_retrieval.py 2023-06-01 00:42:33.000000000 +0200 @@ -0,0 +1,106 @@ +from functools import lru_cache +import json + +import pytest + +from referencing import Registry, Resource, exceptions +from referencing.jsonschema import DRAFT202012 +from referencing.retrieval import to_cached_resource + + +class TestToCachedResource: + def test_it_caches_retrieved_resources(self): + contents = {"$schema": "https://json-schema.org/draft/2020-12/schema"} + stack = [json.dumps(contents)] + + @to_cached_resource() + def retrieve(uri): + return stack.pop() + + registry = Registry(retrieve=retrieve) + + expected = Resource.from_contents(contents) + + got = registry.get_or_retrieve("urn:example:schema") + assert got.value == expected + + # And a second time we get the same value. + again = registry.get_or_retrieve("urn:example:schema") + assert again.value is got.value + + def test_custom_loader(self): + contents = {"$schema": "https://json-schema.org/draft/2020-12/schema"} + stack = [json.dumps(contents)[::-1]] + + @to_cached_resource(loads=lambda s: json.loads(s[::-1])) + def retrieve(uri): + return stack.pop() + + registry = Registry(retrieve=retrieve) + + expected = Resource.from_contents(contents) + + got = registry.get_or_retrieve("urn:example:schema") + assert got.value == expected + + # And a second time we get the same value. + again = registry.get_or_retrieve("urn:example:schema") + assert again.value is got.value + + def test_custom_from_contents(self): + contents = {} + stack = [json.dumps(contents)] + + @to_cached_resource(from_contents=DRAFT202012.create_resource) + def retrieve(uri): + return stack.pop() + + registry = Registry(retrieve=retrieve) + + expected = DRAFT202012.create_resource(contents) + + got = registry.get_or_retrieve("urn:example:schema") + assert got.value == expected + + # And a second time we get the same value. + again = registry.get_or_retrieve("urn:example:schema") + assert again.value is got.value + + def test_custom_cache(self): + schema = {"$schema": "https://json-schema.org/draft/2020-12/schema"} + mapping = { + "urn:example:1": dict(schema, foo=1), + "urn:example:2": dict(schema, foo=2), + "urn:example:3": dict(schema, foo=3), + } + + resources = { + uri: Resource.from_contents(contents) + for uri, contents in mapping.items() + } + + @to_cached_resource(cache=lru_cache(maxsize=2)) + def retrieve(uri): + return json.dumps(mapping.pop(uri)) + + registry = Registry(retrieve=retrieve) + + got = registry.get_or_retrieve("urn:example:1") + assert got.value == resources["urn:example:1"] + assert registry.get_or_retrieve("urn:example:1").value is got.value + assert registry.get_or_retrieve("urn:example:1").value is got.value + + got = registry.get_or_retrieve("urn:example:2") + assert got.value == resources["urn:example:2"] + assert registry.get_or_retrieve("urn:example:2").value is got.value + assert registry.get_or_retrieve("urn:example:2").value is got.value + + # This still succeeds, but evicts the first URI + got = registry.get_or_retrieve("urn:example:3") + assert got.value == resources["urn:example:3"] + assert registry.get_or_retrieve("urn:example:3").value is got.value + assert registry.get_or_retrieve("urn:example:3").value is got.value + + # And now this fails (as we popped the value out of `mapping`) + with pytest.raises(exceptions.Unretrievable): + registry.get_or_retrieve("urn:example:1")