better venv management#44
Conversation
Advantages over the previous approach:
- watches .python-version, pyproject.toml, and uv.lock
The previous version checked pyproject.toml in hello.pdf and
hello.svg, but nowhere else. It also didn't check .python-version or
uv.lock at all. Together these allow lots of commands to run with
outdated venvs.
The new version refreshes the venv immediately when any of those files
change.
- removes venv code from build.ninja, keeps it all in .envrc
This is a strict code simplification, and assuming we never run ninja
without direnv, it doesn't lose us anything.
- simplifies venv sourcing logic
From this:
export VIRTUAL_ENV="${PWD}/.venv"
PATH_add .venv/bin
To this:
source_env .venv/bin/activate
|
See discussion here: https://palisaderesearch.slack.com/archives/C09TUDD2YGZ/p1768513935602679 |
Summary of ChangesHello @jeremyschlatter, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly refactors the project's virtual environment management. By consolidating venv logic into .envrc and introducing automatic refreshes based on key configuration files, it aims to create a more robust and user-friendly development setup. These changes reduce manual intervention and potential inconsistencies, leading to a more reliable and efficient workflow for managing Python dependencies. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request significantly improves virtual environment management by moving the logic from build.ninja to .envrc. This simplification, combined with watching key dependency files like .python-version, pyproject.toml, and uv.lock, ensures the venv is consistently up-to-date. The changes are a great step forward in terms of developer experience and project maintainability. I have one suggestion to further optimize the environment loading performance.
|
I endorse. Could either of @jeremyschlatter @sergey-koldyba figure out what's wrong with CI and merge? Thanks! |
(This just changes the matplotlib version in the svg metadata.)
There was a problem hiding this comment.
No visual diff, just a metadata change:
diff --git a/paper-typst/hello.svg b/paper-typst/hello.svg
index 542ceec..77d2826 100644
--- a/paper-typst/hello.svg
+++ b/paper-typst/hello.svg
@@ -10,7 +10,7 @@
<dc:format>image/svg+xml</dc:format>
<dc:creator>
<cc:Agent>
- <dc:title>Matplotlib v3.10.0, https://matplotlib.org/</dc:title>
+ <dc:title>Matplotlib v3.10.8, https://matplotlib.org/</dc:title>
</cc:Agent>
</dc:creator>
</cc:Work>|
CI failed because this change had the side effect of updating the version of matplotlib in uv.lock. That in turn caused the figures to change because they include the version of matplotlib in their metadata, and CI caught that I hadn't committed the new version of the figures. While I was debugging that, I noticed that I had made a mistake in removing CI is now passing. |
Advantages over the previous approach:
watches .python-version, pyproject.toml, and uv.lock
The previous version checked pyproject.toml in hello.pdf and hello.svg, but nowhere else. It also didn't check .python-version or uv.lock at all. Together these allow lots of commands to run with outdated venvs.
The new version refreshes the venv immediately when any of those files change.
removes venv code from build.ninja, keeps it all in .envrc
This is a strict code simplification, and assuming we never run ninja without direnv, it doesn't lose us anything.
simplifies venv sourcing logic
From this:
To this: