Skip to content

Commit

Permalink
Merge branch 'main' into fix-relative-to
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Mar 7, 2024
2 parents d3a1333 + 0ae1d24 commit f523cce
Show file tree
Hide file tree
Showing 17 changed files with 78 additions and 83 deletions.
4 changes: 4 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ disable_warnings =

[report]
show_missing = True
exclude_also =
# jaraco/skeleton#97
@overload
if TYPE_CHECKING:
4 changes: 2 additions & 2 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ python:

# required boilerplate readthedocs/readthedocs.org#10401
build:
os: ubuntu-22.04
os: ubuntu-lts-latest
tools:
python: "3"
python: latest
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
.. image:: https://readthedocs.org/projects/importlib-metadata/badge/?version=latest
:target: https://importlib-metadata.readthedocs.io/en/latest/?badge=latest

.. image:: https://img.shields.io/badge/skeleton-2023-informational
.. image:: https://img.shields.io/badge/skeleton-2024-informational
:target: https://blog.jaraco.com/skeleton

.. image:: https://tidelift.com/badges/package/pypi/importlib-metadata
Expand Down
2 changes: 1 addition & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

collect_ignore = [
# this module fails mypy tests because 'setup.py' matches './setup.py'
'prepare/example/setup.py',
'tests/data/sources/example/setup.py',
]


Expand Down
16 changes: 14 additions & 2 deletions importlib_metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,9 @@ def read_text(self, filename) -> Optional[str]:
- METADATA: The distribution metadata including fields
like Name and Version and Description.
- entry_points.txt: A series of entry points as defined in
`this spec <https://packaging.python.org/en/latest/specifications/entry-points/#file-format>`_.
`the entry points spec <https://packaging.python.org/en/latest/specifications/entry-points/#file-format>`_.
- RECORD: A record of files according to
`this spec <https://packaging.python.org/en/latest/specifications/recording-installed-packages/#the-record-file>`_.
`this recording spec <https://packaging.python.org/en/latest/specifications/recording-installed-packages/#the-record-file>`_.
A package may provide any set of files, including those
not listed here or none at all.
Expand Down Expand Up @@ -683,6 +683,17 @@ class Context:
Each DistributionFinder may expect any parameters
and should attempt to honor the canonical
parameters defined below when appropriate.
This mechanism gives a custom provider a means to
solicit additional details from the caller beyond
"name" and "path" when searching distributions.
For example, imagine a provider that exposes suites
of packages in either a "public" or "private" ``realm``.
A caller may wish to query only for distributions in
a particular realm and could call
``distributions(realm="private")`` to signal to the
custom provider to only include distributions from that
realm.
"""

name = None
Expand Down Expand Up @@ -774,6 +785,7 @@ class Lookup:
"""
A micro-optimized class for searching a (fast) path for metadata.
"""

def __init__(self, path: FastPath):
"""
Calculate all of the children representing metadata.
Expand Down
50 changes: 22 additions & 28 deletions importlib_metadata/_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,27 @@


class PackageMetadata(Protocol):
def __len__(self) -> int:
... # pragma: no cover
def __len__(self) -> int: ... # pragma: no cover

def __contains__(self, item: str) -> bool:
... # pragma: no cover
def __contains__(self, item: str) -> bool: ... # pragma: no cover

def __getitem__(self, key: str) -> str:
... # pragma: no cover
def __getitem__(self, key: str) -> str: ... # pragma: no cover

def __iter__(self) -> Iterator[str]:
... # pragma: no cover
def __iter__(self) -> Iterator[str]: ... # pragma: no cover

@overload
def get(self, name: str, failobj: None = None) -> Optional[str]:
... # pragma: no cover
def get(
self, name: str, failobj: None = None
) -> Optional[str]: ... # pragma: no cover

@overload
def get(self, name: str, failobj: _T) -> Union[str, _T]:
... # pragma: no cover
def get(self, name: str, failobj: _T) -> Union[str, _T]: ... # pragma: no cover

# overload per python/importlib_metadata#435
@overload
def get_all(self, name: str, failobj: None = None) -> Optional[List[Any]]:
... # pragma: no cover
def get_all(
self, name: str, failobj: None = None
) -> Optional[List[Any]]: ... # pragma: no cover

@overload
def get_all(self, name: str, failobj: _T) -> Union[List[Any], _T]:
Expand All @@ -52,24 +49,21 @@ class SimplePath(Protocol):
A minimal subset of pathlib.Path required by Distribution.
"""

def joinpath(self, other: Union[str, os.PathLike[str]]) -> SimplePath:
... # pragma: no cover
def joinpath(
self, other: Union[str, os.PathLike[str]]
) -> SimplePath: ... # pragma: no cover

def __truediv__(self, other: Union[str, os.PathLike[str]]) -> SimplePath:
... # pragma: no cover
def __truediv__(
self, other: Union[str, os.PathLike[str]]
) -> SimplePath: ... # pragma: no cover

@property
def parent(self) -> SimplePath:
... # pragma: no cover
def parent(self) -> SimplePath: ... # pragma: no cover

def read_text(self, encoding=None) -> str:
... # pragma: no cover
def read_text(self, encoding=None) -> str: ... # pragma: no cover

def read_bytes(self) -> bytes:
... # pragma: no cover
def read_bytes(self) -> bytes: ... # pragma: no cover

def exists(self) -> bool:
... # pragma: no cover
def exists(self) -> bool: ... # pragma: no cover

def resolve(self) -> bool:
... # pragma: no cover
def resolve(self) -> bool: ... # pragma: no cover
1 change: 1 addition & 0 deletions importlib_metadata/_py39compat.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Compatibility layer with Python 3.8/3.9
"""

from typing import TYPE_CHECKING, Any, Optional

if TYPE_CHECKING: # pragma: no cover
Expand Down
6 changes: 6 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
[lint]
extend-select = [
"C901",
"W",
]
ignore = [
# https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
"W191",
Expand All @@ -18,5 +22,7 @@ ignore = [
]

[format]
# Enable preview, required for quote-style = "preserve"
preview = true
# https://docs.astral.sh/ruff/settings/#format-quote-style
quote-style = "preserve"
11 changes: 0 additions & 11 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,12 @@ classifiers =
Programming Language :: Python :: 3 :: Only

[options]
packages = find_namespace:
include_package_data = true
python_requires = >=3.8
install_requires =
zipp>=0.5
typing-extensions>=3.6.4; python_version < "3.8"

[options.packages.find]
exclude =
build*
dist*
docs*
tests*
prepare*

[options.extras_require]
testing =
# upstream
Expand All @@ -50,8 +41,6 @@ testing =
docs =
# upstream
sphinx >= 3.5
# workaround for sphinx/sphinx-doc#11662
sphinx < 7.2.5
jaraco.packaging >= 9.3
rst.linker >= 1.9
furo
Expand Down
15 changes: 5 additions & 10 deletions tests/_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,15 @@ class Symlink(str):

@runtime_checkable
class TreeMaker(Protocol):
def __truediv__(self, *args, **kwargs):
... # pragma: no cover
def __truediv__(self, *args, **kwargs): ... # pragma: no cover

def mkdir(self, **kwargs):
... # pragma: no cover
def mkdir(self, **kwargs): ... # pragma: no cover

def write_text(self, content, **kwargs):
... # pragma: no cover
def write_text(self, content, **kwargs): ... # pragma: no cover

def write_bytes(self, content):
... # pragma: no cover
def write_bytes(self, content): ... # pragma: no cover

def symlink_to(self, target):
... # pragma: no cover
def symlink_to(self, target): ... # pragma: no cover


def _ensure_tree_maker(obj: Union[str, TreeMaker]) -> TreeMaker:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
17 changes: 7 additions & 10 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,13 @@ class DistInfoPkgEditable(DistInfoPkg):
some_hash = '524127ce937f7cb65665130c695abd18ca386f60bb29687efb976faa1596fdcc'
files: FilesSpec = {
'distinfo_pkg-1.0.0.dist-info': {
'direct_url.json': json.dumps(
{
"archive_info": {
"hash": f"sha256={some_hash}",
"hashes": {"sha256": f"{some_hash}"},
},
"url": "file:///path/to/distinfo_pkg-1.0.0.editable-py3-none-any.whl",
}
)
'direct_url.json': json.dumps({
"archive_info": {
"hash": f"sha256={some_hash}",
"hashes": {"sha256": f"{some_hash}"},
},
"url": "file:///path/to/distinfo_pkg-1.0.0.editable-py3-none-any.whl",
})
},
}

Expand Down Expand Up @@ -286,7 +284,6 @@ def main():
}



class EggInfoPkgPipInstalledNoModules(OnSysPath, SiteBuilder):
files: FilesSpec = {
"egg_with_no_modules_pkg.egg-info": {
Expand Down
32 changes: 14 additions & 18 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,10 @@ def test_sortable(self):
"""
EntryPoint objects are sortable, but result is undefined.
"""
sorted(
[
EntryPoint(name='b', value='val', group='group'),
EntryPoint(name='a', value='val', group='group'),
]
)
sorted([
EntryPoint(name='b', value='val', group='group'),
EntryPoint(name='a', value='val', group='group'),
])


class FileSystem(
Expand Down Expand Up @@ -376,18 +374,16 @@ def test_packages_distributions_all_module_types(self):
'all_distributions-1.0.0.dist-info': metadata,
}
for i, suffix in enumerate(suffixes):
files.update(
{
f'importable-name {i}{suffix}': '',
f'in_namespace_{i}': {
f'mod{suffix}': '',
},
f'in_package_{i}': {
'__init__.py': '',
f'mod{suffix}': '',
},
}
)
files.update({
f'importable-name {i}{suffix}': '',
f'in_namespace_{i}': {
f'mod{suffix}': '',
},
f'in_package_{i}': {
'__init__.py': '',
f'mod{suffix}': '',
},
})
metadata.update(RECORD=fixtures.build_record(files))
fixtures.build_files(files, prefix=self.site_dir)

Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ extras =
[testenv:diffcov]
description = run tests and check that diff from main is covered
deps =
{[testenv]deps}
diff-cover
commands =
pytest {posargs} --cov-report xml
Expand Down

0 comments on commit f523cce

Please sign in to comment.