Skip to content

Improve interpreter detection and add comprehensive test coverage#15

Merged
samuelduchesne merged 1 commit into
mainfrom
claude/hopeful-lovelace-gnGhb
May 27, 2026
Merged

Improve interpreter detection and add comprehensive test coverage#15
samuelduchesne merged 1 commit into
mainfrom
claude/hopeful-lovelace-gnGhb

Conversation

@samuelduchesne
Copy link
Copy Markdown
Contributor

Summary

Enhanced the interpreter detection logic in discover.py to handle edge cases more robustly and added extensive test coverage for all detection branches. The changes ensure that conda base environments are properly skipped and that package managers (poetry, pdm, uv) only activate when both a lockfile and manifest are present.

Key Changes

  • Conda base environment handling: Added logic to skip conda's base environment, which is exported by default when conda is initialized but doesn't indicate an active project environment. Detection now checks both CONDA_DEFAULT_ENV != "base" and that the conda prefix basename isn't "base".

  • Package manager manifest requirement: Poetry, PDM, and UV now require both a lockfile (poetry.lock, pdm.lock, uv.lock) AND a pyproject.toml to activate. This prevents false positives when only a lockfile exists, which would cause the tool to emit unhelpful error messages instead of falling through to system Python.

  • Comprehensive test suite: Added 11 new test cases covering:

    • Parent directory venv detection (test_parent_venv)
    • Git root venv detection (test_git_root_venv)
    • Conda environment detection (test_conda_env)
    • Conda base environment skipping via both CONDA_DEFAULT_ENV and prefix basename
    • Pipenv, Poetry, and PDM detection with proper manifest validation
    • UV lockfile detection with manifest requirement
    • Fallthrough behavior when lockfile exists without manifest
    • Exit code handling for various idfkit installation states (MainExitCodeTests)
  • Documentation updates: Clarified the module docstring to explain the conda base environment behavior and the manifest requirement for package managers.

Implementation Details

The conda base detection uses a compound condition to catch both explicit base environment markers (CONDA_DEFAULT_ENV == "base") and implicit ones (when the conda prefix directory is named base). This handles both conda and miniconda installations where users may not have explicitly set CONDA_DEFAULT_ENV.

The package manager changes consolidate the manifest check into a single has_pyproject variable to avoid redundant file checks and improve readability.

The new MainExitCodeTests class uses mocking to drive the full main() function with controlled subprocess returns, allowing deterministic testing of exit codes 0, 1, 2, and 4 across platforms without requiring actual idfkit installation.

https://claude.ai/code/session_011vxyvBpp9229dcqBMyTGNT

Skip conda when the active env is `base` (CONDA_PREFIX is exported merely
by initializing conda), so install advice no longer targets the base env.
Gate the poetry/pdm/uv branches on a pyproject.toml so a bare lockfile no
longer leaks the tool's "no pyproject.toml" stderr instead of install advice.

Add tests for the previously uncovered detection branches (conda, venv-parent,
venv-git-root, pipenv, poetry, pdm) and drive main() through exit codes 0/1/2/4.

Closes #5

https://claude.ai/code/session_011vxyvBpp9229dcqBMyTGNT
@samuelduchesne samuelduchesne merged commit 4c9912e into main May 27, 2026
4 checks passed
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.

2 participants