Skip to content

bug: Unconditional import of _internal.tests in __init__.py breaks downstream packaging/compilation (e.g., Nuitka, PyInstaller) #461

@zengzhengrong

Description

@zengzhengrong

Describe the bug

In griffe/__init__.py, the test-related helpers from griffe._internal.tests (such as temporary_pypackage, temporary_pyfile, etc.) are imported unconditionally at the top level:

https://github.com/mkdocstrings/griffe/blob/main/src/griffe/__init__.py (around line 361)

from griffe._internal.tests import (
    TmpPackage,
    htree,
    module_vtree,
    temporary_inspected_module,
    temporary_inspected_package,
    temporary_pyfile,
    temporary_pypackage,
    temporary_visited_module,
    temporary_visited_package,
    vtree,
)

While these helpers are useful for users writing test suites for their extensions, unconditionally importing them in the package's top-level entrypoint creates a hard runtime dependency on griffe._internal.tests.

When downstream developers compile or package their applications using tools like Nuitka, PyInstaller, or PyStand, they typically configure these tools to exclude test suites (e.g., using --nofollow-import-to=*.tests or excluding subpackages matching tests) to keep the bundle size small.

Because of this unconditional import, any attempt to load griffe (or frameworks that depend on it, like pydantic_ai) in the compiled environment fails immediately with:

ModuleNotFoundError: No module named 'griffe._internal.tests'

To Reproduce

Create a script app.py that imports griffe:

import griffe
print("Loaded!")

Compile it using Nuitka with tests excluded:

nuitka --standalone --nofollow-import-to=*.tests app.py

Run the compiled executable, and it crashes with ModuleNotFoundError: No module named 'griffe._internal.tests'.
Expected behavior
griffe should be importable without requiring the test utilities package to be present. The core library should not have a hard runtime import dependency on its own test helpers in init.py.

Metadata

Metadata

Assignees

Labels

packagingPackaging or distribution issues

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions