diff --git a/setup.cfg b/setup.cfg index ede5670..2863019 100644 --- a/setup.cfg +++ b/setup.cfg @@ -54,8 +54,6 @@ python_requires = >=3.8 # new major versions. This works if the required packages follow Semantic Versioning. # For more information, check out https://semver.org/. install_requires = - importlib-metadata; python_version<"3.8" - importlib-resources; python_version<"3.7" fastjsonschema>=2.16.2,<=3 diff --git a/src/validate_pyproject/__init__.py b/src/validate_pyproject/__init__.py index fbaff2e..be9fa4e 100644 --- a/src/validate_pyproject/__init__.py +++ b/src/validate_pyproject/__init__.py @@ -1,10 +1,4 @@ -import sys - -if sys.version_info[:2] >= (3, 8): - # TODO: Import directly (no need for conditional) when `python_requires = >= 3.8` - from importlib.metadata import PackageNotFoundError, version # pragma: no cover -else: - from importlib_metadata import PackageNotFoundError, version # pragma: no cover +from importlib.metadata import PackageNotFoundError, version # pragma: no cover try: # Change here if project is renamed and does not equal the package name diff --git a/src/validate_pyproject/api.py b/src/validate_pyproject/api.py index 2c88ef2..f25e035 100644 --- a/src/validate_pyproject/api.py +++ b/src/validate_pyproject/api.py @@ -4,7 +4,6 @@ import json import logging -import sys import typing from enum import Enum from functools import partial, reduce @@ -35,10 +34,7 @@ try: # pragma: no cover - if sys.version_info[:2] < (3, 7) or typing.TYPE_CHECKING: # See #22 - from importlib_resources import files - else: - from importlib.resources import files + from importlib.resources import files def read_text(package: Union[str, ModuleType], resource: str) -> str: """:meta private:""" diff --git a/src/validate_pyproject/plugins/__init__.py b/src/validate_pyproject/plugins/__init__.py index f4a5a76..f39175d 100644 --- a/src/validate_pyproject/plugins/__init__.py +++ b/src/validate_pyproject/plugins/__init__.py @@ -5,26 +5,14 @@ .. _entry point: https://setuptools.readthedocs.io/en/latest/userguide/entry_point.html """ -import sys import typing +from importlib.metadata import EntryPoint, entry_points from string import Template from textwrap import dedent -from typing import Any, Callable, Iterable, List, Optional +from typing import Any, Callable, Iterable, List, Optional, Protocol from .. import __version__ - -if sys.version_info[:2] >= (3, 8): # pragma: no cover - # TODO: Import directly (no need for conditional) when `python_requires = >= 3.8` - from importlib.metadata import EntryPoint, entry_points -else: # pragma: no cover - from importlib_metadata import EntryPoint, entry_points - -if typing.TYPE_CHECKING: - from typing import Protocol - - from ..types import Plugin, Schema -else: - Protocol = object +from ..types import Plugin, Schema ENTRYPOINT_GROUP = "validate_pyproject.tool_schema" @@ -37,7 +25,7 @@ def id(self) -> str: ... def tool(self) -> str: ... @property - def schema(self) -> "Schema": ... + def schema(self) -> Schema: ... @property def help_text(self) -> str: ... @@ -47,7 +35,7 @@ def fragment(self) -> str: ... class PluginWrapper: - def __init__(self, tool: str, load_fn: "Plugin"): + def __init__(self, tool: str, load_fn: Plugin): self._tool = tool self._load_fn = load_fn @@ -60,7 +48,7 @@ def tool(self) -> str: return self._tool @property - def schema(self) -> "Schema": + def schema(self) -> Schema: return self._load_fn(self.tool) @property diff --git a/src/validate_pyproject/pre_compile/__init__.py b/src/validate_pyproject/pre_compile/__init__.py index 9cde18e..efa6d00 100644 --- a/src/validate_pyproject/pre_compile/__init__.py +++ b/src/validate_pyproject/pre_compile/__init__.py @@ -1,6 +1,6 @@ import logging import os -import sys +from importlib import metadata as _M from pathlib import Path from types import MappingProxyType from typing import TYPE_CHECKING, Dict, Mapping, Optional, Sequence, Union @@ -9,11 +9,6 @@ from .. import api, dist_name, types -if sys.version_info[:2] >= (3, 8): # pragma: no cover - from importlib import metadata as _M -else: # pragma: no cover - import importlib_metadata as _M - if TYPE_CHECKING: # pragma: no cover from ..plugins import PluginProtocol diff --git a/tests/test_plugins.py b/tests/test_plugins.py index a5e8d01..1f07dec 100644 --- a/tests/test_plugins.py +++ b/tests/test_plugins.py @@ -1,8 +1,7 @@ # The code in this module is mostly borrowed/adapted from PyScaffold and was originally # published under the MIT license # The original PyScaffold license can be found in 'NOTICE.txt' - -import sys +from importlib.metadata import EntryPoint # pragma: no cover import pytest @@ -15,13 +14,6 @@ ) -if sys.version_info[:2] >= (3, 8): - # TODO: Import directly (no need for conditional) when `python_requires = >= 3.8` - from importlib.metadata import EntryPoint # pragma: no cover -else: - from importlib_metadata import EntryPoint # pragma: no cover - - def test_load_from_entry_point__error(): # This module does not exist, so Python will have some trouble loading it # EntryPoint(name, value, group)