Skip to content

Commit

Permalink
Handle missing optional dependencies in dep_versions()
Browse files Browse the repository at this point in the history
PR #1159 made keyring optional on some (non-Desktop) architectures.
However the CLI attempts to determine dependency versions, in failure
codepaths. Rather than blow up entirely, report the dependency as
missing.

Part of: #1158
  • Loading branch information
stefanor committed Dec 3, 2024
1 parent a723876 commit d96eb5d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions twine/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,24 @@ def configure_output() -> None:

def list_dependencies_and_versions() -> List[Tuple[str, str]]:
deps = [
"keyring",
"keyring", # optional for non-desktop use
"pkginfo",
"requests",
"requests-toolbelt",
"urllib3",
]
if sys.version_info < (3, 10):
deps.append("importlib-metadata")
return [(dep, importlib_metadata.version(dep)) for dep in deps]

result: List[Tuple[str, str]] = []
for dep in deps:
try:
version = importlib_metadata.version(dep)
except importlib_metadata.PackageNotFoundError:
version = "NOT INSTALLED"
result.append((dep, version))

return result


def dep_versions() -> str:
Expand Down

0 comments on commit d96eb5d

Please sign in to comment.