From d8a66bc593610b37ad55ce94d24e55bb3bf6ed3c Mon Sep 17 00:00:00 2001 From: BUI Van Tuan <buivantuan07@gmail.com> Date: Fri, 8 Dec 2023 12:50:11 +0100 Subject: [PATCH] fix flake8 --- dnadna/utils/config.py | 1 - dnadna/utils/jsonschema_pyref.py | 110 ------------------------------- tests/test_params.py | 1 - 3 files changed, 112 deletions(-) diff --git a/dnadna/utils/config.py b/dnadna/utils/config.py index 62247896..6c8524cb 100644 --- a/dnadna/utils/config.py +++ b/dnadna/utils/config.py @@ -8,7 +8,6 @@ import os.path as pth import pathlib from collections.abc import Mapping, KeysView, ValuesView, ItemsView from itertools import chain -from urllib.parse import urlparse import jsonschema from jsonschema.exceptions import best_match, relevance diff --git a/dnadna/utils/jsonschema_pyref.py b/dnadna/utils/jsonschema_pyref.py index 32a5ea72..88802399 100644 --- a/dnadna/utils/jsonschema_pyref.py +++ b/dnadna/utils/jsonschema_pyref.py @@ -26,99 +26,6 @@ def urljoin(base: str, url: str, allow_fragments: bool = True) -> str: The join semantics for ``py-obj`` and ``py-pkgdata`` URLs differ from those of typical http-like URLs, as well as from each other. - - The rules for ``py-obj`` are as follows: - - * If joined with a "relative" URL, if the URL starts with a Python - identifier, it is simply appended to the current object path: - - >>> from jsonschema_pyref import urljoin - >>> urljoin('py-obj:a.b.c', 'd.e') - 'py-obj:a.b.c.d.e' - - * However, if the "relative" URL starts with one or more ``.``, it - is processed relative to the base path using similar semantics to - Python relative imports. That is, one dot means a different attribute - of the same object, and so on: - - >>> urljoin('py-obj:a.b.c', '.d') - 'py-obj:a.b.d' - >>> urljoin('py-obj:a.b.c', '..d') - 'py-obj:a.d' - >>> urljoin('py-obj:a.b.c', '..d.e') - 'py-obj:a.d.e' - - * When joining an absolute URL with the ``py-obj`` scheme, the new URL - replaces the base: - - >>> urljoin('py-obj:a.b.c', 'py-obj:d.e.f') - 'py-obj:d.e.f' - - * And likewise when joining an absolute URL with an entirely different - scheme: - - >>> urljoin('py-obj:a.b.c', 'https://example.com') - 'https://example.com' - - * Fragments are dropped from the base URL, and retained from the joined - URL: - - >>> urljoin('py-obj:a.b.c#replaced', '.d#fragment') - 'py-obj:a.b.d#fragment' - >>> urljoin('py-obj:a.b.c#replaced', '#fragment') - 'py-obj:a.b.c#fragment' - - The rules for ``py-pkgdata`` are as follows: - - * If joined to a relative URL, it is treated as a different file relative - to the same package/directory as the base URL, very similarly to how - `urllib.parse.urljoin` works for relative paths joined to http(s) URLs: - - >>> urljoin('py-pkgdata:a.b.c/schema1.json', 'schema2.json') - 'py-pkgdata:a.b.c/schema2.json' - >>> urljoin('py-pkgdata:a.b.c/schemas/schema1.json', 'schema2.json') - 'py-pkgdata:a.b.c/schemas/schema2.json' - >>> urljoin('py-pkgdata:a.b.c/schemas/sub/schema1.json', 'schema2.json') - 'py-pkgdata:a.b.c/schemas/sub/schema2.json' - >>> urljoin('py-pkgdata:a.b.c/schemas/schema1.json', '../more_schemas/schema2.json') - 'py-pkgdata:a.b.c/more_schemas/schema2.json' - - .. note:: - - This does not support relative URLs with a package-relative - component, only different paths within the same package. Maybe - support for this could be added in the future, but under the current - format it's too ambiguous. - - * When joining an absolute URL, if the joined URL is in the same package - it works the same as the relative case (effectively the joined URL - replaces the base): - - >>> urljoin('py-pkgdata:a.b.c/schema1.json', 'py-pkgdata:a.b.c/schema2.json') - 'py-pkgdata:a.b.c/schema2.json' - - * Likewise when they are different packages: - - >>> urljoin('py-pkgdata:a.b.c/schema1.json', 'py-pkgdata:d.e.f/schema2.json') - 'py-pkgdata:d.e.f/schema2.json' - - * Or if they are the exact same URL, that URL is returned: - - >>> urljoin('py-pkgdata:a.b.c/sub/schema1.json', 'py-pkgdata:a.b.c/sub/schema1.json') - 'py-pkgdata:a.b.c/sub/schema1.json' - - * And likewise if they are not the same scheme at all: - - >>> urljoin('py-pkgdata:a.b.c/schema1.json', 'http://example.com/schema2.json') - 'http://example.com/schema2.json' - - * The same rules apply for fragments as with ``py-obj``: - - >>> urljoin('py-pkgdata:a.b.c/schema1.json#replaced', 'schema2.json#fragment') - 'py-pkgdata:a.b.c/schema2.json#fragment' - >>> urljoin('py-pkgdata:a.b.c/schema1.json#replaced', '#fragment') - 'py-pkgdata:a.b.c/schema1.json#fragment' - """ parsedb = urlparse(base) if parsedb.scheme in _URL_SCHEME_JOINERS: @@ -362,23 +269,6 @@ URL_SCHEME_RESOLVERS = { 'py-obj': _resolve_url_py_obj, 'py-pkgdata': _resolve_url_py_pkgdata } -""" -Additional URL handlers for the custom URL schemes supported by this package. - -This can be passed to the ``handlers`` argument of `jsonschema.RefResolver`, -but take note: It is also necessary to override the ``urljoin_cache`` argument -to use `jsonschema_pyref.urljoin` as follows:: - - >>> import jonschema - >>> from jsonschema_pyref import URL_SCHEME_RESOLVERS, urljoin - >>> from functools import lru_cache - >>> resolver = RefResolver({}, {}, handlers=URL_SCHEME_RESOLVERS, - ... urljoin_cache=lru_cache(1024)(urljoin)) - -This boilerplate can be avoided entirely by using the supplied -`jsonschema_pyref.RefResolver` which has these enhancements by default (and -is otherwise identical to `jsonschema.RefResolver`). -""" _URL_SCHEME_JOINERS = { diff --git a/tests/test_params.py b/tests/test_params.py index 554cbdee..bbef6f0f 100644 --- a/tests/test_params.py +++ b/tests/test_params.py @@ -5,7 +5,6 @@ import os.path as pth # import jsonschema_pyref as jsonschema from dnadna.utils.config import ConfigValidator -import jsonschema import pandas as pd import dnadna -- GitLab