-
Notifications
You must be signed in to change notification settings - Fork 0
Distrust repository-local Python interpreters (avoid executing .venv/bin/python) #142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,9 +5,11 @@ | |
| ``python.pythonPath``. Under ``loomweave analyze`` launched from an agent hook | ||
| that ``python`` is the system interpreter, which cannot import the project's | ||
| editable install, and every ``tests/`` -> ``src/`` call target came back empty | ||
| while the coverage claim still said ``complete``. This module picks the | ||
| project's own interpreter deterministically so the answer no longer depends | ||
| on who launched the run. | ||
| while the coverage claim still said ``complete``. This module picks an | ||
| explicitly trusted or activated interpreter deterministically so the answer | ||
| no longer depends on who launched the run. Repository-local interpreters are | ||
| deliberately not discovered: Pyright executes the selected interpreter, so an | ||
| executable committed at ``.venv/bin/python`` is untrusted repository content. | ||
|
|
||
| The order below is a CROSS-LANGUAGE CONTRACT with | ||
| ``crates/loomweave-core/src/plugin/interpreter.rs`` (the host runs the same | ||
|
|
@@ -43,14 +45,14 @@ | |
| # must carry the same literal. | ||
| INTERPRETER_OVERRIDE_ENV: Final = "LOOMWEAVE_PYTHON_INTERPRETER" | ||
|
|
||
| InterpreterSource = Literal["override", "dotvenv", "virtual_env", "conda", "path", "none"] | ||
| InterpreterSource = Literal["override", "virtual_env", "conda", "path", "none"] | ||
|
|
||
| _PREFIX_SOURCES: Final[tuple[tuple[str, InterpreterSource], ...]] = ( | ||
| ("VIRTUAL_ENV", "virtual_env"), | ||
| ("CONDA_PREFIX", "conda"), | ||
| ) | ||
| _PINNED_SOURCES: Final[frozenset[InterpreterSource]] = frozenset( | ||
| {"override", "dotvenv", "virtual_env", "conda"}, | ||
| {"override", "virtual_env", "conda"}, | ||
| ) | ||
|
|
||
|
|
||
|
|
@@ -63,7 +65,7 @@ class ProjectInterpreter: | |
|
|
||
| @property | ||
| def pinned(self) -> bool: | ||
| """True when the interpreter is project-owned (not a PATH guess).""" | ||
| """True when the interpreter was explicitly selected (not a PATH guess).""" | ||
| return self.source in _PINNED_SOURCES | ||
|
|
||
|
|
||
|
|
@@ -78,6 +80,9 @@ def discover_project_interpreter( | |
| environ: Mapping[str, str] | None = None, | ||
| ) -> ProjectInterpreter: | ||
| """Resolve the project's interpreter in the contract order (see module doc).""" | ||
| # Keep the project root in the API because this function is mirrored by | ||
| # the host, but never use it to select an executable from the repository. | ||
| _ = project_root | ||
|
Comment on lines
+83
to
+85
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
After this function deliberately stops inspecting the project root, merely creating Useful? React with 👍 / 👎. |
||
| env = os.environ if environ is None else environ | ||
| override = env.get(INTERPRETER_OVERRIDE_ENV) | ||
| if override: | ||
|
|
@@ -87,8 +92,6 @@ def discover_project_interpreter( | |
| f"loomweave-plugin-python: {INTERPRETER_OVERRIDE_ENV}={override!r} is not an " | ||
| "executable file; ignoring the override and discovering the interpreter\n", | ||
| ) | ||
| if (hit := _usable(Path(project_root) / ".venv" / "bin" / "python")) is not None: | ||
| return ProjectInterpreter(path=str(hit), source="dotvenv") | ||
| for var, source in _PREFIX_SOURCES: | ||
| prefix = env.get(var) | ||
| if prefix and (hit := _usable(Path(prefix) / "bin" / "python")) is not None: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When no override or activated environment is present, ignoring
project_rootmakes discovery return the unpinned PATH/none result, butanalyze_interpreter_change_forces_full_reanalysisincrates/loomweave-cli/tests/analyze.rsstill supplies only<project>/.venv/bin/pythonand asserts that this path is fingerprinted and exported. Theverify.ymlworkspace-wide nextest job runs this test, so the suite will fail on Unix; update the integration scenario to transition between trusted interpreter sources while preserving its re-dispatch coverage.Useful? React with 👍 / 👎.