Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace the remaining uses of pkg_resources with packaging and importlib_metadata. #736

Merged
merged 19 commits into from Mar 2, 2021
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 3 additions & 4 deletions mypy.ini
Expand Up @@ -30,6 +30,9 @@ ignore_missing_imports = True
; https://github.com/jaraco/keyring/issues/437
ignore_missing_imports = True

[mypy-packaging]
ignore_missing_imports = True

[mypy-pkginfo]
; https://bugs.launchpad.net/pkginfo/+bug/1876591
ignore_missing_imports = True
Expand All @@ -45,10 +48,6 @@ ignore_missing_imports = True
[mypy-rfc3986]
ignore_missing_imports = True

[mypy-setuptools]
; https://github.com/python/typeshed/issues/2171
ignore_missing_imports = True

[mypy-tqdm]
; https://github.com/tqdm/tqdm/issues/260
ignore_missing_imports = True
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Expand Up @@ -38,7 +38,7 @@ install_requires=
readme_renderer >= 21.0
requests >= 2.20
requests-toolbelt >= 0.8.0, != 0.9.0
setuptools >= 0.7.0
packaging
jaraco marked this conversation as resolved.
Show resolved Hide resolved
tqdm >= 4.14
importlib_metadata >= 3.6
keyring >= 15.1
Expand Down
Binary file added tests/fixtures/twine-3.3.0-py3.9.egg
Binary file not shown.
5 changes: 5 additions & 0 deletions tests/test_package.py
Expand Up @@ -264,3 +264,8 @@ def test_malformed_from_file(monkeypatch):
package_file.PackageFile.from_filename(filename, comment=None)

assert "Invalid distribution file" in err.value.args[0]


def test_package_from_egg():
filename = "tests/fixtures/twine-3.3.0-py3.9.egg"
package_file.PackageFile.from_filename(filename, comment=None)
2 changes: 1 addition & 1 deletion tests/test_repository.py
Expand Up @@ -89,7 +89,7 @@ def test_make_user_agent_string(default_repo):
assert "User-Agent" in default_repo.session.headers

user_agent = default_repo.session.headers["User-Agent"]
packages = ("twine/", "requests/", "requests-toolbelt/", "pkginfo/", "setuptools/")
packages = ("twine/", "requests/", "requests-toolbelt/", "pkginfo/")
assert all(p in user_agent for p in packages)


Expand Down
2 changes: 0 additions & 2 deletions twine/cli.py
Expand Up @@ -17,7 +17,6 @@
import pkginfo
import requests
import requests_toolbelt
import setuptools
import tqdm
from importlib_metadata import entry_points

Expand All @@ -31,7 +30,6 @@ def list_dependencies_and_versions() -> List[Tuple[str, str]]:
return [
("pkginfo", _installed.Installed(pkginfo).version),
("requests", requests.__version__),
("setuptools", setuptools.__version__),
jaraco marked this conversation as resolved.
Show resolved Hide resolved
("requests-toolbelt", requests_toolbelt.__version__),
("tqdm", tqdm.__version__),
]
Expand Down
9 changes: 5 additions & 4 deletions twine/package.py
Expand Up @@ -17,7 +17,8 @@
import subprocess
from typing import Dict, NamedTuple, Optional, Sequence, Tuple, Union

import pkg_resources
import importlib_metadata
import packaging.utils # type: ignore
import pkginfo

from twine import exceptions
Expand Down Expand Up @@ -58,7 +59,7 @@ def __init__(
self.metadata = metadata
self.python_version = python_version
self.filetype = filetype
self.safe_name = pkg_resources.safe_name(metadata.name)
self.safe_name = packaging.utils.canonicalize_name(metadata.name)
self.signed_filename = self.filename + ".asc"
self.signed_basefilename = self.basefilename + ".asc"
self.gpg_signature: Optional[Tuple[str, bytes]] = None
Expand Down Expand Up @@ -99,8 +100,8 @@ def from_filename(cls, filename: str, comment: Optional[str]) -> "PackageFile":

py_version: Optional[str]
if dtype == "bdist_egg":
pkgd = pkg_resources.Distribution.from_filename(filename)
py_version = pkgd.py_version
(dist,) = importlib_metadata.Distribution.discover(path=[filename])
py_version = dist.metadata["Version"]
elif dtype == "bdist_wheel":
py_version = meta.py_version
elif dtype == "bdist_wininst":
Expand Down