-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Add optional requires_python to third party stubs metadata #10724
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
Merged
Merged
Changes from 15 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
eee2770
WIP
hamdanal db9b3ca
Also check in regr_test
hamdanal 1e1c1dc
mypy
hamdanal 32625b3
check specifier operator
hamdanal be22800
CR
hamdanal 0b34da8
Merge remote-tracking branch 'upstream/main' into requires-python
hamdanal 6fd2dfc
Merge branch 'main' into requires-python
AlexWaygood 549ff52
Alex's suggestion
hamdanal ac949cd
Move to utils
hamdanal ef749c4
Apply suggestions from code review
hamdanal 7b1043e
Fix assertion error, actually skip mypy test when needed, improve mes…
hamdanal 1499be0
Merge remote-tracking branch 'upstream/main' into requires-python
hamdanal 585fc7c
type ignore mypy happiness
hamdanal e61af2c
Apply suggestions from code review
hamdanal e070dc9
Merge remote-tracking branch 'upstream/main' into requires-python
hamdanal 515fe80
CR
hamdanal 9ae5239
Apply suggestions from code review
hamdanal 4a14f42
Simplify
hamdanal b4b6e5c
Update tests/regr_test.py
AlexWaygood File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -98,3 +98,4 @@ select = [ | |
|
|
||
| [tool.typeshed] | ||
| pyright_version = "1.1.328" | ||
| oldest_supported_python = "3.7" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,8 +25,9 @@ | |
|
|
||
| import tomli | ||
|
|
||
| from parse_metadata import PackageDependencies, get_recursive_requirements | ||
| from parse_metadata import PackageDependencies, get_recursive_requirements, read_metadata | ||
| from utils import ( | ||
| PYTHON_VERSION, | ||
| VERSIONS_RE as VERSION_LINE_RE, | ||
| VenvInfo, | ||
| colored, | ||
|
|
@@ -307,6 +308,7 @@ def add_third_party_files( | |
| class TestResults(NamedTuple): | ||
| exit_code: int | ||
| files_checked: int | ||
| packages_skipped: int = 0 | ||
|
|
||
|
|
||
| def test_third_party_distribution( | ||
|
|
@@ -471,6 +473,7 @@ def setup_virtual_environments(distributions: dict[str, PackageDependencies], ar | |
| def test_third_party_stubs(code: int, args: TestConfig, tempdir: Path) -> TestResults: | ||
| print("Testing third-party packages...") | ||
| files_checked = 0 | ||
| packages_skipped = 0 | ||
| gitignore_spec = get_gitignore_spec() | ||
| distributions_to_check: dict[str, PackageDependencies] = {} | ||
|
|
||
|
|
@@ -480,6 +483,21 @@ def test_third_party_stubs(code: int, args: TestConfig, tempdir: Path) -> TestRe | |
| if spec_matches_path(gitignore_spec, distribution_path): | ||
| continue | ||
|
|
||
| metadata = read_metadata(distribution) | ||
| if not metadata.requires_python.contains(PYTHON_VERSION): | ||
| msg = ( | ||
| f"skipping {distribution!r} (requires Python {metadata.requires_python}; " | ||
| f"test is being run using Python {PYTHON_VERSION})" | ||
| ) | ||
| print(colored(msg, "yellow")) | ||
| packages_skipped += 1 | ||
| continue | ||
| if not metadata.requires_python.contains(args.version): | ||
| msg = f"skipping {distribution!r} for target Python {args.version} (requires Python {metadata.requires_python})" | ||
| print(colored(msg, "yellow")) | ||
| packages_skipped += 1 | ||
| continue | ||
|
|
||
| if ( | ||
| distribution_path in args.filter | ||
| or Path("stubs") in args.filter | ||
|
|
@@ -493,34 +511,48 @@ def test_third_party_stubs(code: int, args: TestConfig, tempdir: Path) -> TestRe | |
| if not _DISTRIBUTION_TO_VENV_MAPPING: | ||
| setup_virtual_environments(distributions_to_check, args, tempdir) | ||
|
|
||
| assert _DISTRIBUTION_TO_VENV_MAPPING.keys() == distributions_to_check.keys() | ||
|
|
||
| for distribution, venv_info in _DISTRIBUTION_TO_VENV_MAPPING.items(): | ||
| # Some distributions may have been skipped earlier and therefore don't have a venv. | ||
| distributions_without_venv = { | ||
| distribution: requirements | ||
| for distribution, requirements in distributions_to_check.items() | ||
| if distribution not in _DISTRIBUTION_TO_VENV_MAPPING | ||
| } | ||
| if distributions_without_venv: | ||
| setup_virtual_environments(distributions_without_venv, args, tempdir) | ||
|
|
||
| # Check that there is a venv for every distribution we're testing. | ||
| # Some venvs may exist from previous runs but are skipped in this run. | ||
| assert _DISTRIBUTION_TO_VENV_MAPPING.keys() >= distributions_to_check.keys() | ||
|
|
||
| for distribution in distributions_to_check: | ||
| venv_info = _DISTRIBUTION_TO_VENV_MAPPING[distribution] | ||
|
||
| non_types_dependencies = venv_info.python_exe != sys.executable | ||
| this_code, checked = test_third_party_distribution( | ||
| this_code, checked, _ = test_third_party_distribution( | ||
| distribution, args, venv_info=venv_info, non_types_dependencies=non_types_dependencies | ||
| ) | ||
| code = max(code, this_code) | ||
| files_checked += checked | ||
|
|
||
| return TestResults(code, files_checked) | ||
| return TestResults(code, files_checked, packages_skipped) | ||
|
|
||
|
|
||
| def test_typeshed(code: int, args: TestConfig, tempdir: Path) -> TestResults: | ||
| print(f"*** Testing Python {args.version} on {args.platform}") | ||
| files_checked_this_version = 0 | ||
| packages_skipped_this_version = 0 | ||
| stdlib_dir, stubs_dir = Path("stdlib"), Path("stubs") | ||
| if stdlib_dir in args.filter or any(stdlib_dir in path.parents for path in args.filter): | ||
| code, stdlib_files_checked = test_stdlib(code, args) | ||
| code, stdlib_files_checked, _ = test_stdlib(code, args) | ||
| files_checked_this_version += stdlib_files_checked | ||
| print() | ||
|
|
||
| if stubs_dir in args.filter or any(stubs_dir in path.parents for path in args.filter): | ||
| code, third_party_files_checked = test_third_party_stubs(code, args, tempdir) | ||
| code, third_party_files_checked, third_party_packages_skipped = test_third_party_stubs(code, args, tempdir) | ||
| files_checked_this_version += third_party_files_checked | ||
| packages_skipped_this_version = third_party_packages_skipped | ||
| print() | ||
|
|
||
| return TestResults(code, files_checked_this_version) | ||
| return TestResults(code, files_checked_this_version, packages_skipped_this_version) | ||
|
|
||
|
|
||
| def main() -> None: | ||
|
|
@@ -531,19 +563,28 @@ def main() -> None: | |
| exclude = args.exclude or [] | ||
| code = 0 | ||
| total_files_checked = 0 | ||
| total_packages_skipped = 0 | ||
| with tempfile.TemporaryDirectory() as td: | ||
| td_path = Path(td) | ||
| for version, platform in product(versions, platforms): | ||
| config = TestConfig(args.verbose, filter, exclude, version, platform) | ||
| code, files_checked_this_version = test_typeshed(code, args=config, tempdir=td_path) | ||
| code, files_checked_this_version, packages_skipped_this_version = test_typeshed(code, args=config, tempdir=td_path) | ||
| total_files_checked += files_checked_this_version | ||
| total_packages_skipped += packages_skipped_this_version | ||
| if code: | ||
| print_error(f"--- exit status {code}, {total_files_checked} files checked ---") | ||
| plural = "" if total_files_checked == 1 else "s" | ||
| print_error(f"--- exit status {code}, {total_files_checked} file{plural} checked ---") | ||
| sys.exit(code) | ||
| if not total_files_checked: | ||
| if total_packages_skipped: | ||
| {1: ""}.get(total_packages_skipped, "s") | ||
AlexWaygood marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| plural = "" if total_packages_skipped == 1 else "s" | ||
| print(colored(f"--- {total_packages_skipped} package{plural} skipped ---", "yellow")) | ||
| elif not total_files_checked: | ||
| print_error("--- nothing to do; exit 1 ---") | ||
| sys.exit(1) | ||
| print(colored(f"--- success, {total_files_checked} files checked ---", "green")) | ||
| if total_files_checked: | ||
| plural = "" if total_files_checked == 1 else "s" | ||
| print(colored(f"--- success, {total_files_checked} file{plural} checked ---", "green")) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AlexWaygood marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.