Skip to content

Make the registry self-tests report the backends they promise - #4

Open
egeboy35 wants to merge 1 commit into
lkk688:mainfrom
egeboy35:fix/registry-self-tests-report-empty
Open

Make the registry self-tests report the backends they promise#4
egeboy35 wants to merge 1 commit into
lkk688:mainfrom
egeboy35:fix/registry-self-tests-report-empty

Conversation

@egeboy35

Copy link
Copy Markdown

Both registry modules carry a header advertising a command to check the install:

#   python -m DeepDataMiningLearning.ngdet.detectors.base
# Expected: prints the registered detector backends (after importing adapters).

Run it and you get an empty list. Same for ngperception/depth/estimators/base.py.

$ python -m DeepDataMiningLearning.ngdet.detectors.base
Registered detector backends: []

$ python -m DeepDataMiningLearning.ngperception.depth.estimators.base
Registered depth backends: []

Why

Under python -m pkg.mod the file executes as __main__. The from . import <adapters> inside the block then imports the adapters, which do from .base import register, ... — loading this module a second time under its real name. @register populates that copy's registry; __main__ prints its own, still empty. CPython says as much:

RuntimeWarning: 'DeepDataMiningLearning.ngdet.detectors.base' found in sys.modules
after import of package 'DeepDataMiningLearning.ngdet.detectors', but prior to
execution of '...base'; this may result in unpredictable behaviour

The registry itself is fine — this is a reporting bug, not a functional one. A normal import sees one module object and registration works: importing hf_detr takes DETECTOR_REGISTRY from [] to ['hf_detr']. Only the self-test lies.

The change

Each if __name__ == "__main__": block now reads the canonical module instead of its own globals:

ngdet.detectors.base          [] -> ['hf_detr', 'yolo', 'locate_anything']
depth.estimators.base         [] -> ['hf_depth']

Nothing outside those two blocks changes.

One thing I checked because I got it wrong first

My first attempt rewrote the Registered: {list(...)} text inside build_detector / build_estimator by accident, which would have turned a helpful KeyError into a NameError for anyone asking for an unknown backend. The diff here touches only the __main__ blocks, and I verified both builders still raise KeyError naming the registered backends:

KeyError: "Unknown detector backend 'nosuchbackend'. Registered: ['hf_detr', 'yolo', 'locate_anything']"
KeyError: "Unknown depth backend 'nosuch'. Registered: ['hf_depth']"

🤖 Generated with Claude Code

@egeboy35
egeboy35 force-pushed the fix/registry-self-tests-report-empty branch from e11ede8 to 36cf103 Compare September 1, 2026 12:28
Both files carry a header advertising a command:

    #   python -m DeepDataMiningLearning.ngdet.detectors.base
    # Expected: prints the registered detector backends (after importing adapters).

Run it and the answer is an empty list. Same for
ngperception/depth/estimators/base.py.

Under `python -m pkg.mod` the file executes as `__main__`; the
`from . import <adapters>` inside the block then imports the adapters,
which do `from .base import register, ...` -- loading this module a second
time under its real name. `@register` populates that copy's registry, and
`__main__` prints its own, still empty. CPython says as much:

    RuntimeWarning: 'DeepDataMiningLearning.ngdet.detectors.base' found in
    sys.modules after import of package 'DeepDataMiningLearning.ngdet.detectors',
    but prior to execution of '...base'; this may result in unpredictable behaviour

Nothing outside the self-test is affected -- a normal `import` sees one
module object and the registry fills correctly (verified: importing
hf_detr takes DETECTOR_REGISTRY from [] to ['hf_detr']). The report is
what is wrong, not the registry.

The blocks now read the canonical module rather than their own globals:

    ngdet.detectors.base           [] -> ['hf_detr', 'yolo', 'locate_anything']
    depth.estimators.base          [] -> ['hf_depth']

Only the `if __name__ == "__main__":` block changes in each file. I checked
that the `Registered: {list(...)}` text inside build_detector /
build_estimator is untouched -- an earlier attempt of mine rewrote that
line by accident, which would have turned a helpful KeyError into a
NameError. Both still raise KeyError naming the registered backends.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@egeboy35
egeboy35 force-pushed the fix/registry-self-tests-report-empty branch from 36cf103 to ee5d38d Compare September 1, 2026 12:43
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