From 401df76c0661b03f0c0df4687861f3a80c78fc7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edgar=20Ram=C3=ADrez=20Mondrag=C3=B3n?= <16805946+edgarrmondragon@users.noreply.github.com> Date: Mon, 5 Feb 2024 19:05:33 -0600 Subject: [PATCH] refactor: Make importlib-resources a dev dependency and remove the `SCHEMA_FILE` constant from the public API (#36) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ---- 📚 Documentation preview 📚: https://pep610--36.org.readthedocs.build/en/36/ --- pyproject.toml | 2 +- src/pep610/__init__.py | 8 +------- {src/pep610 => tests/fixtures}/direct_url.schema.json | 0 tests/test_generic.py | 9 ++++++++- 4 files changed, 10 insertions(+), 9 deletions(-) rename {src/pep610 => tests/fixtures}/direct_url.schema.json (100%) diff --git a/pyproject.toml b/pyproject.toml index 2d010ce..31682c5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,12 +34,12 @@ dynamic = [ "version", ] dependencies = [ - 'importlib-resources>=5.3; python_version < "3.9"', ] optional-dependencies.dev = [ "coverage[toml]>=6.5", "hypothesis", "hypothesis-jsonschema", + 'importlib-resources>=5.3; python_version < "3.9"', "pytest", ] optional-dependencies.docs = [ diff --git a/src/pep610/__init__.py b/src/pep610/__init__.py index 5f5d493..dee0a35 100644 --- a/src/pep610/__init__.py +++ b/src/pep610/__init__.py @@ -4,18 +4,13 @@ import hashlib import json -import sys import typing as t from dataclasses import dataclass from functools import singledispatch from importlib.metadata import version -if sys.version_info < (3, 9): - import importlib_resources -else: - import importlib.resources as importlib_resources - if t.TYPE_CHECKING: + import sys from importlib.metadata import Distribution, PathDistribution if sys.version_info <= (3, 10): @@ -46,7 +41,6 @@ "write_to_distribution", ] -SCHEMA_FILE = importlib_resources.files(__package__) / "direct_url.schema.json" __version__ = version(__package__) diff --git a/src/pep610/direct_url.schema.json b/tests/fixtures/direct_url.schema.json similarity index 100% rename from src/pep610/direct_url.schema.json rename to tests/fixtures/direct_url.schema.json diff --git a/tests/test_generic.py b/tests/test_generic.py index 36f5969..95d2d70 100644 --- a/tests/test_generic.py +++ b/tests/test_generic.py @@ -1,12 +1,19 @@ import json +import sys from importlib.metadata import Distribution import pytest from hypothesis import HealthCheck, given, settings from hypothesis_jsonschema import from_schema -from pep610 import SCHEMA_FILE, read_from_distribution, write_to_distribution +from pep610 import read_from_distribution, write_to_distribution +if sys.version_info < (3, 9): + import importlib_resources +else: + import importlib.resources as importlib_resources + +SCHEMA_FILE = importlib_resources.files(__package__) / "fixtures/direct_url.schema.json" SCHEMA = json.loads(SCHEMA_FILE.read_text())