Skip to content

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

Open
Mikezhang001 wants to merge 1 commit into
deepseek-ai:mainfrom
Mikezhang001:zb
Open

fix: use importlib to load scripts/generate_pyi.py instead of package…#355
Mikezhang001 wants to merge 1 commit into
deepseek-ai:mainfrom
Mikezhang001:zb

Conversation

@Mikezhang001

Copy link
Copy Markdown

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.

… import

The top-level 'from scripts.generate_pyi import generate_pyi_file' in
setup.py requires scripts/ to be a Python package (with __init__.py),
but scripts/ is a utility directory and was never intended to be one.
This was introduced in PR deepseek-ai#231 and causes ModuleNotFoundError when
running install.sh or 'python setup.py bdist_wheel'.

Replace the package-style import with importlib.util.spec_from_file_location
to load the module by file path, which does not require __init__.py.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant