Repository navigation
kernels: append revision to metadata id to prevent collision #890
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 |
|---|---|---|
|
|
@@ -79,13 +79,15 @@ def _import_from_path( | |
| if not file_path.exists(): | ||
| raise FileNotFoundError(f"No kernel module found at: `{variant_path}`") | ||
|
|
||
| spec = importlib.util.spec_from_file_location(metadata.id, file_path) | ||
| # Hub revisions can share a build ID but must have separate Python submodules. | ||
| import_name = f"{metadata.id}_{repo_info.revision}" if repo_info is not None else metadata.id | ||
|
Member
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. We shouldn't do this. The identifier from the metadata should be unique. This will still not solve it in contexts where we do not have a revision.
Member
Author
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. But it doesn't seem to be 👀 |
||
| spec = importlib.util.spec_from_file_location(import_name, file_path) | ||
| if spec is None: | ||
| raise ImportError(f"Cannot load spec for {module_name} from {file_path}") | ||
| module = importlib.util.module_from_spec(spec) | ||
| if module is None: | ||
| raise ImportError(f"Cannot load module {module_name} from spec") | ||
| sys.modules[metadata.id] = module | ||
| sys.modules[import_name] = module | ||
|
|
||
| # Avoid an import cycle. | ||
| from kernels.deps import use_kernel_deps | ||
|
|
@@ -96,7 +98,7 @@ def _import_from_path( | |
| except Exception as e: | ||
| # Remove the partially initialized module, so that a retry | ||
| # imports from scratch. | ||
| sys.modules.pop(metadata.id, None) | ||
| sys.modules.pop(import_name, None) | ||
| if hasattr(e, "add_note"): | ||
| origin = f"({repo_info.repo_id}, revision: {repo_info.revision})" if repo_info else "" | ||
| e.add_note(f"while importing kernel '{metadata.name}', variant '{variant_path.name}' {origin}") | ||
|
|
||
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.
does repo info always include a revision, e.g. is a version resolved to a revision?
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.
Yup:
kernels/kernels/src/kernels/_versions.py
Lines 204 to 235 in 1bec2d3
For local kernel, this is handled differently, i.e., no
repo_info, of course.