Improve interpreter detection and add comprehensive test coverage#15
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Enhanced the interpreter detection logic in
discover.pyto 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
baseenvironment, which is exported by default when conda is initialized but doesn't indicate an active project environment. Detection now checks bothCONDA_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 apyproject.tomlto 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:
test_parent_venv)test_git_root_venv)test_conda_env)CONDA_DEFAULT_ENVand prefix basenameMainExitCodeTests)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 namedbase). This handles both conda and miniconda installations where users may not have explicitly setCONDA_DEFAULT_ENV.The package manager changes consolidate the manifest check into a single
has_pyprojectvariable to avoid redundant file checks and improve readability.The new
MainExitCodeTestsclass uses mocking to drive the fullmain()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