-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
MISC: Check that min versions are aligned in CI and import_optional_dependency #45219
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 5 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
3e82166
Start script to check sync of min versions
mroeschke 4f996f3
Complete get_versions_from_optional
mroeschke b4e417d
Pin min pyreadstat, parser for CI file
mroeschke 85f0e3d
Dont parse via yaml
mroeschke 976bdb8
Only handle import_optional_dependency and CI for now
mroeschke e16176c
Merge remote-tracking branch 'upstream/master' into validate/min_verions
mroeschke 83d4f09
Fix edge case with psycopg2
mroeschke 01172dc
Merge remote-tracking branch 'upstream/master' into validate/min_verions
mroeschke 82de0b7
Special case for psycopg2
mroeschke d108490
Merge remote-tracking branch 'upstream/master' into validate/min_verions
mroeschke d1dbdc1
Merge remote-tracking branch 'upstream/master' into validate/min_verions
mroeschke 7b93130
Merge remote-tracking branch 'upstream/master' into validate/min_verions
mroeschke 3a76a52
Add to sys path instead of using ast
mroeschke 628c6f3
Merge remote-tracking branch 'upstream/main' into validate/min_verions
mroeschke d9bdc6a
Scope to specific files
mroeschke 9b59be7
Merge remote-tracking branch 'upstream/main' into validate/min_verions
mroeschke aa30fda
Merge remote-tracking branch 'upstream/main' into validate/min_verions
mroeschke d83b06f
Merge remote-tracking branch 'upstream/main' into validate/min_verions
mroeschke 81b1eff
Merge remote-tracking branch 'upstream/main' into validate/min_verions
mroeschke 3c9f463
Address review
mroeschke 8c96e00
Merge remote-tracking branch 'upstream/main' into validate/min_verions
mroeschke 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
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
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 |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#!/usr/bin/env python3 | ||
""" | ||
Check pandas required and optional dependencies are synced across: | ||
|
||
ci/deps/actions-.*-minimum_versions.yaml | ||
pandas/compat/_optional.py | ||
|
||
TODO: doc/source/getting_started/install.rst | ||
|
||
This is meant to be run as a pre-commit hook - to run it manually, you can do: | ||
|
||
pre-commit run validate-min-versions-in-sync --all-files | ||
""" | ||
from __future__ import annotations | ||
|
||
import ast | ||
import pathlib | ||
import sys | ||
|
||
DOC_PATH = pathlib.Path("doc/source/getting_started/install.rst").resolve() | ||
CI_PATH = next( | ||
pathlib.Path("ci/deps").absolute().glob("actions-*-minimum_versions.yaml") | ||
) | ||
CODE_PATH = pathlib.Path("pandas/compat/_optional.py").resolve() | ||
|
||
|
||
lithomas1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
def get_versions_from_code(content: str) -> dict[str, str]: | ||
lithomas1 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
num_dicts = 0 | ||
for node in ast.walk(ast.parse(content)): | ||
if isinstance(node, ast.Dict): | ||
if num_dicts == 0: | ||
version_dict_ast = node | ||
num_dicts += 1 | ||
elif num_dicts == 1: | ||
install_map = {k.value: v.value for k, v in zip(node.keys, node.values)} | ||
return { | ||
install_map.get(k.value, k.value).casefold(): v.value | ||
for k, v in zip(version_dict_ast.keys, version_dict_ast.values) | ||
if k.value != "pytest" | ||
} | ||
|
||
|
||
def get_versions_from_ci(content: list[str]) -> tuple[dict[str, str], dict[str, str]]: | ||
# Don't parse with pyyaml because it ignores comments we're looking for | ||
seen_required = False | ||
seen_optional = False | ||
required_deps = {} | ||
optional_deps = {} | ||
for line in content: | ||
if "# required dependencies" in line: | ||
seen_required = True | ||
elif "# optional dependencies" in line: | ||
seen_optional = True | ||
elif seen_required and line.strip(): | ||
package, version = line.strip().split("=") | ||
package = package[2:] | ||
if not seen_optional: | ||
required_deps[package] = version | ||
else: | ||
optional_deps[package] = version | ||
return required_deps, optional_deps | ||
|
||
|
||
def main(): | ||
with open(CI_PATH) as f: | ||
mroeschke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
_, ci_optional = get_versions_from_ci(f.readlines()) | ||
with open(CODE_PATH) as f: | ||
code_optional = get_versions_from_code(f.read()) | ||
diff = set(ci_optional.items()).symmetric_difference(code_optional.items()) | ||
if diff: | ||
sys.stdout.write( | ||
f"The follow minimum version differences were found between " | ||
f"{CI_PATH} and {CODE_PATH}. Please ensure these are aligned: " | ||
f"{diff}" | ||
mroeschke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
sys.exit(1) | ||
sys.exit(0) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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.