[PR #355] fix: use importlib to load scripts/generate_pyi.py instead of package… #388

Open
opened 2026-10-26 21:17:09 +00:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/deepseek-ai/DeepGEMM/pull/355
Author: @Mikezhang001
Created: 6/5/2026
Status: 🔄 Open

Base: main ← Head: zb


📝 Commits (1)

  • 3e99d29 fix: use importlib to load scripts/generate_pyi.py instead of package import

📊 Changes

1 file changed (+7 additions, -2 deletions)

View changed files

📝 setup.py (+7 -2)

📄 Description

Hi, I ran into an install issue and this PR fixes it.

What happened

Fresh clone + ./install.sh blows up with:

ModuleNotFoundError: No module named 'scripts.generate_pyi'

The root cause is that setup.py does from scripts.generate_pyi import generate_pyi_file at the top level, but scripts/ doesn't have an __init__.py — so Python doesn't recognize it as a package.

Looks like this was introduced in #231 when generate_pyi.py was added to scripts/.

How to reproduce

git clone --recursive https://github.com/deepseek-ai/DeepGEMM.git
cd DeepGEMM
./install.sh   # boom

What I changed

Instead of adding a __init__.py to scripts/ (which feels wrong since it's not really a package), I moved the import into CustomBuildPy.generate_pyi_file() and used importlib to load it by file path:

import importlib.util
spec = importlib.util.spec_from_file_location(
    'generate_pyi', os.path.join(current_dir, 'scripts', 'generate_pyi.py')
)
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
mod.generate_pyi_file(name='_C', root='./csrc', output_dir='./stubs')

This way scripts/ stays as a plain utility directory and the import only happens at build time when it's actually needed.

Tested locally, ./install.sh works fine after the change.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/deepseek-ai/DeepGEMM/pull/355 **Author:** [@Mikezhang001](https://github.com/Mikezhang001) **Created:** 6/5/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `zb` --- ### 📝 Commits (1) - [`3e99d29`](https://github.com/deepseek-ai/DeepGEMM/commit/3e99d290856fc0af521a71ad6bf2be04c316ee47) fix: use importlib to load scripts/generate_pyi.py instead of package import ### 📊 Changes **1 file changed** (+7 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `setup.py` (+7 -2) </details> ### 📄 Description Hi, I ran into an install issue and this PR fixes it. ## What happened Fresh clone + `./install.sh` blows up with: ``` ModuleNotFoundError: No module named 'scripts.generate_pyi' ``` The root cause is that `setup.py` does `from scripts.generate_pyi import generate_pyi_file` at the top level, but `scripts/` doesn't have an `__init__.py` — so Python doesn't recognize it as a package. Looks like this was introduced in #231 when `generate_pyi.py` was added to `scripts/`. ## How to reproduce ```bash git clone --recursive https://github.com/deepseek-ai/DeepGEMM.git cd DeepGEMM ./install.sh # boom ``` ## What I changed Instead of adding a `__init__.py` to `scripts/` (which feels wrong since it's not really a package), I moved the import into `CustomBuildPy.generate_pyi_file()` and used `importlib` to load it by file path: ```python import importlib.util spec = importlib.util.spec_from_file_location( 'generate_pyi', os.path.join(current_dir, 'scripts', 'generate_pyi.py') ) mod = importlib.util.module_from_spec(spec) spec.loader.exec_module(mod) mod.generate_pyi_file(name='_C', root='./csrc', output_dir='./stubs') ``` This way `scripts/` stays as a plain utility directory and the import only happens at build time when it's actually needed. Tested locally, `./install.sh` works fine after the change. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
deepseek-ai/DeepGEMM#388
No description provided.