Commit 5dd31d7
fix(hygon/platform): Improve Hygon library path resolution, fall back… (#82)
# Description
When loading Hygon libraries, the code previously assumed that
`hygon_spec.origin` is always available and directly accessed it to
determine the package path.
However, for namespace packages or certain installation layouts,
`importlib.util.find_spec()` may return a spec whose `origin` is `None`,
causing an exception when accessing `Path(hygon_spec.origin)`.
This PR adds a fallback mechanism:
- Use `hygon_spec.origin` when available.
- Fall back to `hygon_spec.submodule_search_locations` when `origin` is
`None`.
- Return gracefully with an error message if neither source can provide
a valid package path.
This improves compatibility with different Python package layouts and
prevents startup failures when loading Hygon-related libraries.
Fixes # (issue)
## Type of change
- [ ] Documentation change (change only to the documentation, either a
fix or a new content)
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] Infra/Build change
- [ ] Code refactoring
## Changes
Please list the changes introduced in this PR:
- Add a null check for `hygon_spec.origin`
- Fall back to `hygon_spec.submodule_search_locations[0]` when `origin`
is unavailable
- Add explicit error handling when neither `origin` nor
`submodule_search_locations` can determine the package path
- Prevent crashes caused by `Path(None)` during Hygon library loading
# Checklist:
- [x] I have read and followed the [contributing
guidelines](https://github.com/NVIDIA/TransformerEngine/blob/main/CONTRIBUTING.rst)
- [x] The functionality is complete
- [x] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
---------
Co-authored-by: wangyl <wangyl16@sugon.com>
Co-authored-by: wangyl166 <601199939@qq.com>1 parent 9aa7e20 commit 5dd31d7
1 file changed
Lines changed: 10 additions & 1 deletion
Lines changed: 10 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
41 | 50 | | |
42 | 51 | | |
43 | 52 | | |
| |||
0 commit comments