inference icon indicating copy to clipboard operation
inference copied to clipboard

Documented editable install breaks three unit-test suites: inference_models resolves as an empty namespace package from the repo root

Open Lingikaushikreddy opened this issue 1 month ago • 2 comments

What happens

AGENTS.md (line 28) and .github/CONTRIBUTING.md (line 76) tell contributors to set up a dev environment with

pip install -e ./inference_models -e ./workflows -e ./stream_vision -e .

and to run development commands from the repository root. Doing exactly that, these suites fail at collection:

python -m pytest tests/inference_cli/unit_tests
python -m pytest tests/workflows/unit_tests
python -m pytest tests/inference/unit_tests
ImportError while importing test module '.../tests/workflows/unit_tests/core_steps/common/query_language/operations/test_classification_results_operations.py'.
E   ImportError: cannot import name 'ClassificationPrediction' from 'inference_models' (unknown location)

tests/inference_sdk/unit_tests and (cd workflows && pytest tests/unit_tests tests/isolation) are fine.

Why

python -m pytest puts the repo root on sys.path. The repo root contains the inference_models/ project folder (pyproject, README, docs — no __init__.py), which shares its name with the inference_models package inside it. With the default setuptools editable install, the real package is served by an __editable___inference_models_*_finder.py meta-path hook, so the path-based finder sees only the project folder and resolves inference_models as an empty namespace package:

$ python -c "import inference_models as m; print(m.__path__, m.__file__)"
['/.../inference/inference_models'] None          # from repo root: wrong
$ cd /tmp && python -c "import inference_models as m; print(m.__file__)"
/.../inference/inference_models/inference_models/__init__.py   # elsewhere: right

CI is unaffected because the workflows use pip install --no-deps ./inference_models (non-editable), which installs a regular package into site-packages, and a regular package wins over a namespace portion.

workflows/ and stream_vision/ don't hit this because their package names (roboflow_workflows, streamvision) differ from their folder names.

Verified fix

pip install --config-settings editable_mode=compat -e ./inference_models

This installs via a plain .pth path entry, so the path-based finder finds the real package. After that, from the repo root:

Suite Before After
tests/inference_cli/unit_tests collection error 241 passed
tests/workflows/unit_tests collection error 1344 passed, 30 skipped
tests/inference/unit_tests collection error 5304 passed, 11 skipped

Also checked:

  • --config-settings editable_mode=strict works too (it installs a link tree via .pth), but new files then need a reinstall to be picked up, so compat is the friendlier default for development.
  • Using the pytest console script instead of python -m pytest does not help: pytest's default prepend import mode inserts the repo root anyway.
  • Installing non-editably (pip install ./inference_models, as CI does) also works, at the cost of reinstalling after every change.

Environment

macOS 15 (arm64), Python 3.12.13, pip via uv 0.10.8, setuptools default editable mode, main @ 9f67071d3.

Proposal

Happy to open a small PR. Options, smallest first:

  1. Update the install line in AGENTS.md and .github/CONTRIBUTING.md to use --config-settings editable_mode=compat for ./inference_models (or install it non-editably like CI does), with one sentence on why.
  2. Additionally, a guard in tests/conftest.py that fails fast with a clear message when inference_models.__file__ is None, so the next person gets "your editable install is shadowed" instead of a confusing ImportError.

Which would you prefer?

Lingikaushikreddy avatar Oct 12 '26 05:10 Lingikaushikreddy

Hi! I'd like to help fix this. Would you prefer a pytest config change (rootdir/pythonpath, so the root inference_models/ folder doesn't shadow the package) or a docs update? Happy to open a PR either way.

ATS-AI-6278 avatar Oct 21 '26 08:10 ATS-AI-6278

I reproduced the package-discovery issue on Ubuntu 24.04.4 LTS (x86_64) with Python 3.12.3 at commit 21059e9 (inference-models==0.39.8).

Using the same Python executable from both directories, I checked importlib.util.find_spec("inference_models").origin before and after reinstalling with --config-settings editable_mode=compat.

Working directory Default editable install With editable_mode=compat
Repository root None Package __init__.py
/tmp Package __init__.py Package __init__.py

In all three successful lookups, the resolved file was <repo>/inference_models/inference_models/__init__.py. Compatibility mode fixed package discovery from the repository root on my machine. I tested discovery only and skipped the full dependency install and pytest suites.

TanishkaDeshpande avatar Nov 06 '26 01:11 TanishkaDeshpande