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

Allow types-foo to depend on foo #159

Merged
merged 3 commits into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions stub_uploader/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
import os
import re
import tarfile
import tempfile
import urllib.parse
from collections.abc import Generator, Iterable
from glob import glob
from pathlib import Path
import tempfile
from typing import Any, Optional

import requests
import tomli
from packaging.requirements import Requirement
from packaging.specifiers import Specifier, InvalidSpecifier
from packaging.specifiers import InvalidSpecifier, Specifier

from .const import META, THIRD_PARTY_NAMESPACE, TYPES_PREFIX, UPLOADED_PATH

Expand Down Expand Up @@ -348,11 +348,12 @@ def verify_external_req_stubs_require_its_runtime(
# broken by new releases of upstream packages, even if they do not match the version spec we
# have for the upstream distribution.

runtime_req_name = EXTERNAL_RUNTIME_REQ_MAP.get(req.name, req.name)

if not runtime_in_upstream_requires(
req, data
) and not runtime_in_upstream_sdist_requires(req, data):
if not (
req.name == upstream_distribution # Allow `types-foo` to require `foo`
or runtime_in_upstream_requires(req, data)
or runtime_in_upstream_sdist_requires(req, data)
):
runtime_req_name = EXTERNAL_RUNTIME_REQ_MAP.get(req.name, req.name)
raise InvalidRequires(
f"Expected dependency {runtime_req_name} to be listed in {upstream_distribution}'s "
+ "requires_dist or the sdist's *.egg-info/requires.txt"
Expand Down
2 changes: 2 additions & 0 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ def test_verify_external_req() -> None:
verify_external_req(
Requirement("mypy-extensions"), "mypy", _unsafe_ignore_allowlist=True
)
# Check that types-foo can depend on foo
verify_external_req(Requirement("setuptools"), "setuptools")

with pytest.raises(
InvalidRequires, match="to be present in the stub_uploader allowlist"
Expand Down