-
Notifications
You must be signed in to change notification settings - Fork 1.4k
update_lib hard dependency resolver #6817
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,21 +16,12 @@ | |
| import sys | ||
|
|
||
|
|
||
| def copy_lib( | ||
| def _copy_single( | ||
| src_path: pathlib.Path, | ||
| lib_path: pathlib.Path, | ||
| verbose: bool = True, | ||
| ) -> None: | ||
| """ | ||
| Copy library file or directory from CPython. | ||
|
|
||
| Args: | ||
| src_path: Source path (e.g., cpython/Lib/dataclasses.py or cpython/Lib/json) | ||
| verbose: Print progress messages | ||
| """ | ||
| from update_lib.path import parse_lib_path | ||
|
|
||
| lib_path = parse_lib_path(src_path) | ||
|
|
||
| """Copy a single file or directory.""" | ||
| # Remove existing file/directory | ||
| if lib_path.exists(): | ||
| if lib_path.is_dir(): | ||
|
|
@@ -46,6 +37,7 @@ def copy_lib( | |
| if src_path.is_dir(): | ||
| if verbose: | ||
| print(f"Copying directory: {src_path} -> {lib_path}") | ||
| lib_path.parent.mkdir(parents=True, exist_ok=True) | ||
| shutil.copytree(src_path, lib_path) | ||
| else: | ||
| if verbose: | ||
|
|
@@ -54,6 +46,46 @@ def copy_lib( | |
| shutil.copy2(src_path, lib_path) | ||
|
|
||
|
|
||
| def copy_lib( | ||
| src_path: pathlib.Path, | ||
| verbose: bool = True, | ||
| ) -> None: | ||
| """ | ||
| Copy library file or directory from CPython. | ||
|
|
||
| Also copies additional files if defined in DEPENDENCIES table. | ||
|
|
||
| Args: | ||
| src_path: Source path (e.g., cpython/Lib/dataclasses.py or cpython/Lib/json) | ||
| verbose: Print progress messages | ||
| """ | ||
| from update_lib.deps import get_lib_paths | ||
| from update_lib.path import parse_lib_path | ||
|
|
||
| # Extract module name and cpython prefix from path | ||
| path_str = str(src_path).replace("\\", "/") | ||
| if "/Lib/" in path_str: | ||
| cpython_prefix, after_lib = path_str.split("/Lib/", 1) | ||
| # Get module name (first component, without .py) | ||
| name = after_lib.split("/")[0] | ||
| if name.endswith(".py"): | ||
| name = name[:-3] | ||
| else: | ||
| # Fallback: just copy the single file | ||
| lib_path = parse_lib_path(src_path) | ||
| _copy_single(src_path, lib_path, verbose) | ||
| return | ||
|
Comment on lines
+65
to
+77
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fallback path handling is currently unreachable; nested Lib paths mis-resolve module names. When 🛠️ Proposed fix (direct-copy for nested paths + explicit fallback) if "/Lib/" in path_str:
cpython_prefix, after_lib = path_str.split("/Lib/", 1)
+ # If a deeper path is provided (e.g., Lib/test/libregrtest),
+ # copy it directly instead of resolving by top-level module name.
+ if "/" in after_lib:
+ lib_path = parse_lib_path(src_path)
+ _copy_single(src_path, lib_path, verbose)
+ return
# Get module name (first component, without .py)
name = after_lib.split("/")[0]
if name.endswith(".py"):
name = name[:-3]
else:
- # Fallback: just copy the single file
- lib_path = parse_lib_path(src_path)
- _copy_single(src_path, lib_path, verbose)
- return
+ # Fallback: allow direct Lib/... paths
+ if path_str.startswith("Lib/"):
+ lib_path = pathlib.Path(path_str)
+ _copy_single(src_path, lib_path, verbose)
+ return
+ raise ValueError(f"Path must contain '/Lib/' or start with 'Lib/' (got: {src_path})")🤖 Prompt for AI Agents |
||
|
|
||
| # Get all paths to copy from DEPENDENCIES table | ||
| all_src_paths = get_lib_paths(name, cpython_prefix) | ||
|
|
||
| # Copy each file | ||
| for src in all_src_paths: | ||
| if src.exists(): | ||
| lib_path = parse_lib_path(src) | ||
| _copy_single(src, lib_path, verbose) | ||
|
|
||
|
|
||
| def main(argv: list[str] | None = None) -> int: | ||
| parser = argparse.ArgumentParser( | ||
| description=__doc__, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I look at this again, wouldn't
as_posix()would also do this?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
once tried, but not simply replacable.