diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index cf94f7d8..ac0ff69e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -4,8 +4,11 @@ on: merge_group: push: branches-ignore: - # disabled for jaraco/skeleton#103 - # - gh-readonly-queue/** # Temporary merge queue-related GH-made branches + # temporary GH branches relating to merge queues (jaraco/skeleton#93) + - gh-readonly-queue/** + tags: + # required if branches-ignore is supplied (jaraco/skeleton#103) + - '**' pull_request: permissions: @@ -28,10 +31,10 @@ env: jobs: test: strategy: + # https://blog.jaraco.com/efficient-use-of-ci-resources/ matrix: python: - "3.8" - - "3.11" - "3.12" platform: - ubuntu-latest @@ -42,6 +45,8 @@ jobs: platform: ubuntu-latest - python: "3.10" platform: ubuntu-latest + - python: "3.11" + platform: ubuntu-latest - python: pypy3.10 platform: ubuntu-latest runs-on: ${{ matrix.platform }} diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 68489063..dc8516ac 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -3,10 +3,14 @@ python: install: - path: . extra_requirements: - - docs + - doc # required boilerplate readthedocs/readthedocs.org#10401 build: os: ubuntu-lts-latest tools: python: latest + # post-checkout job to ensure the clone isn't shallow jaraco/skeleton#114 + jobs: + post_checkout: + - git fetch --unshallow || true diff --git a/NEWS.rst b/NEWS.rst index 850e8f00..70f1eb38 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -1,3 +1,13 @@ +v7.2.0 +====== + +Features +-------- + +- Deferred select imports in for speedup (python/cpython#109829). +- Updated fixtures for python/cpython#120801. + + v7.1.0 ====== diff --git a/importlib_metadata/__init__.py b/importlib_metadata/__init__.py index 32ee3b4d..f4c75941 100644 --- a/importlib_metadata/__init__.py +++ b/importlib_metadata/__init__.py @@ -18,7 +18,7 @@ import posixpath import collections -from . import _adapters, _meta +from . import _meta from .compat import py39 from ._collections import FreezableDefaultDict, Pair from ._compat import ( @@ -461,6 +461,9 @@ def metadata(self) -> _meta.PackageMetadata: Custom providers may provide the METADATA file or override this property. """ + # deferred for performance (python/cpython#109829) + from . import _adapters + opt_text = ( self.read_text('METADATA') or self.read_text('PKG-INFO') diff --git a/pyproject.toml b/pyproject.toml index a853c578..e85fc4ce 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,62 @@ [build-system] -requires = ["setuptools>=56", "setuptools_scm[toml]>=3.4.1"] +requires = ["setuptools>=61.2", "setuptools_scm[toml]>=3.4.1"] build-backend = "setuptools.build_meta" +[project] +name = "importlib_metadata" +authors = [ + { name = "Jason R. Coombs", email = "jaraco@jaraco.com" }, +] +description = "Read metadata from Python packages" +readme = "README.rst" +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Developers", + "License :: OSI Approved :: Apache Software License", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3 :: Only", +] +requires-python = ">=3.8" +dependencies = [ + "zipp>=0.5", + 'typing-extensions>=3.6.4; python_version < "3.8"', +] +dynamic = ["version"] + +[project.urls] +Homepage = "https://github.com/python/importlib_metadata" + +[project.optional-dependencies] +test = [ + # upstream + "pytest >= 6, != 8.1.*", + "pytest-checkdocs >= 2.4", + "pytest-cov", + "pytest-mypy", + "pytest-enabler >= 2.2", + "pytest-ruff >= 0.2.1", + + # local + 'importlib_resources>=1.3; python_version < "3.9"', + "packaging", + "pyfakefs", + "flufl.flake8", + "pytest-perf >= 0.9.2", + "jaraco.test >= 5.4", +] +doc = [ + # upstream + "sphinx >= 3.5", + "jaraco.packaging >= 9.3", + "rst.linker >= 1.9", + "furo", + "sphinx-lint", + + # tidelift + "jaraco.tidelift >= 1.4", + + # local +] +perf = ["ipython"] + [tool.setuptools_scm] diff --git a/pytest.ini b/pytest.ini index 022a723e..9a0f3bce 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,6 +1,9 @@ [pytest] norecursedirs=dist build .tox .eggs -addopts=--doctest-modules +addopts= + --doctest-modules + --import-mode importlib +consider_namespace_packages=true filterwarnings= ## upstream diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 02d3c7e8..00000000 --- a/setup.cfg +++ /dev/null @@ -1,58 +0,0 @@ -[metadata] -name = importlib_metadata -author = Jason R. Coombs -author_email = jaraco@jaraco.com -description = Read metadata from Python packages -long_description = file:README.rst -url = https://github.com/python/importlib_metadata -classifiers = - Development Status :: 5 - Production/Stable - Intended Audience :: Developers - License :: OSI Approved :: Apache Software License - Programming Language :: Python :: 3 - Programming Language :: Python :: 3 :: Only - -[options] -include_package_data = true -python_requires = >=3.8 -install_requires = - zipp>=0.5 - typing-extensions>=3.6.4; python_version < "3.8" - -[options.extras_require] -testing = - # upstream - pytest >= 6 - pytest-checkdocs >= 2.4 - pytest-cov - pytest-mypy; \ - # workaround for jaraco/skeleton#22 - python_implementation != "PyPy" - pytest-enabler >= 2.2 - pytest-ruff >= 0.2.1 - - # local - importlib_resources>=1.3; python_version < "3.9" - packaging - pyfakefs - flufl.flake8 - pytest-perf >= 0.9.2 - jaraco.test >= 5.4 - -docs = - # upstream - sphinx >= 3.5 - jaraco.packaging >= 9.3 - rst.linker >= 1.9 - furo - sphinx-lint - - # tidelift - jaraco.tidelift >= 1.4 - - # local - -perf = - ipython - -[options.entry_points] diff --git a/tests/compat/py39.py b/tests/compat/py39.py index 16c8b574..9476eb35 100644 --- a/tests/compat/py39.py +++ b/tests/compat/py39.py @@ -2,7 +2,7 @@ os_helper = try_import('os_helper') or from_test_support( - 'FS_NONASCII', 'skip_unless_symlink' + 'FS_NONASCII', 'skip_unless_symlink', 'temp_dir' ) import_helper = try_import('import_helper') or from_test_support( 'modules_setup', 'modules_cleanup' diff --git a/tests/fixtures.py b/tests/fixtures.py index f8082df0..1bf9a803 100644 --- a/tests/fixtures.py +++ b/tests/fixtures.py @@ -1,10 +1,8 @@ -import os import sys import copy import json import shutil import pathlib -import tempfile import textwrap import functools import contextlib @@ -26,29 +24,12 @@ @contextlib.contextmanager -def tempdir(): - tmpdir = tempfile.mkdtemp() - try: - yield pathlib.Path(tmpdir) - finally: - shutil.rmtree(tmpdir) - - -@contextlib.contextmanager -def save_cwd(): - orig = os.getcwd() - try: - yield - finally: - os.chdir(orig) - - -@contextlib.contextmanager -def tempdir_as_cwd(): - with tempdir() as tmp: - with save_cwd(): - os.chdir(str(tmp)) - yield tmp +def tmp_path(): + """ + Like os_helper.temp_dir, but yields a pathlib.Path. + """ + with os_helper.temp_dir() as path: + yield pathlib.Path(path) @contextlib.contextmanager @@ -69,7 +50,7 @@ def setUp(self): class SiteDir(Fixtures): def setUp(self): super().setUp() - self.site_dir = self.fixtures.enter_context(tempdir()) + self.site_dir = self.fixtures.enter_context(tmp_path()) class OnSysPath(Fixtures): diff --git a/tests/test_api.py b/tests/test_api.py index a85c62ad..a93065cb 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -109,7 +109,7 @@ def test_entry_points_unique_packages_normalized(self): Entry points should only be exposed for the first package on sys.path with a given name (even when normalized). """ - alt_site_dir = self.fixtures.enter_context(fixtures.tempdir()) + alt_site_dir = self.fixtures.enter_context(fixtures.tmp_path()) self.fixtures.enter_context(self.add_sys_path(alt_site_dir)) alt_pkg = { "DistInfo_pkg-1.1.0.dist-info": { diff --git a/tests/test_main.py b/tests/test_main.py index af79e698..32241c00 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -135,7 +135,7 @@ def test_unique_distributions(self): fixtures.build_files(self.make_pkg('abc'), self.site_dir) before = list(_unique(distributions())) - alt_site_dir = self.fixtures.enter_context(fixtures.tempdir()) + alt_site_dir = self.fixtures.enter_context(fixtures.tmp_path()) self.fixtures.enter_context(self.add_sys_path(alt_site_dir)) fixtures.build_files(self.make_pkg('ABC'), alt_site_dir) after = list(_unique(distributions())) diff --git a/tox.ini b/tox.ini index 3604f01f..71fd05f6 100644 --- a/tox.ini +++ b/tox.ini @@ -9,7 +9,7 @@ passenv = HOME usedevelop = True extras = - testing + test [testenv:diffcov] description = run tests and check that diff from main is covered @@ -24,8 +24,8 @@ commands = [testenv:docs] description = build the documentation extras = - docs - testing + doc + test changedir = docs commands = python -m sphinx -W --keep-going . {toxinidir}/build/html