Skip to content
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

Feature request: include patchlevel in python venv #1239

Open
jfly opened this issue Feb 21, 2024 · 5 comments
Open

Feature request: include patchlevel in python venv #1239

jfly opened this issue Feb 21, 2024 · 5 comments
Labels

Comments

@jfly
Copy link
Contributor

jfly commented Feb 21, 2024

Is your feature request related to a problem? Please describe.

At my company, we use poetry and we specify a full python patch version in our pyproject.toml. Example:

$ git grep -A 1 'tool.poetry.dependencies'
pyproject.toml:[tool.poetry.dependencies]
pyproject.toml:python = "3.11.7"

This means that whenever we upgrade Python versions, people need new venvs to get created, or else poetry will start to fail with errors like:

$ poetry install --with dev --sync

Current Python version (3.11.4) is not allowed by the project (3.11.7).
Please change python executable via the "env use" command.

However, direnv currently only creates new venvs when the patch version of python changes, so people have to manually delete the old venv and run direnv reload whenever this happens. direnv's behavior here is intentional (see #1033 and #1035), and apparently has something to do with IDEs like vscode.

Describe the solution you'd like

I'd like direnv to create a new venv whenever the python version changes at all (effectively, the behavior before the change in #1033). To avoid regressing on the vscode experience, I'd propose adding a little more functionality as well:

  1. We could create/update a symlink with just the minor version (e.g., python-3.11 -> python-3.11.7).
  2. We could add an option to layout_python to pick the level of granularity, or add a new layout_python_full_version with this behavior.

I'd be happy to send in a PR implementing 1) or 2) if you're open to it!

(Also @dne and @offbyone as they both requested the original change.)

@jfly jfly added the Feature label Feb 21, 2024
@dne
Copy link
Contributor

dne commented Feb 21, 2024

Option 2 would be fine to me. No idea about the vscode issue, since I don't use it.

I'm wondering why you're not using Poetry's own venv management support over direnv's layout_python though?

@jfly
Copy link
Contributor Author

jfly commented Feb 22, 2024

We just want to use poetry as a package manager. We use a mix of poetry and pipenv, and it's nice for all venvs to be managed in the same way.

@jfly
Copy link
Contributor Author

jfly commented Feb 22, 2024

@dne what are your thoughts on option 1? It seems nice to avoid changing the api of the direnv stdlib if possible.

@dne
Copy link
Contributor

dne commented Feb 22, 2024

@dne what are your thoughts on option 1? It seems nice to avoid changing the api of the direnv stdlib if possible.

I'm not sure how it'd avoid having to start over with a new empty venv, for no reason, when Python is updated to a new fix release (same major/minor version)?

@jfly
Copy link
Contributor Author

jfly commented Feb 22, 2024

You're right, it would create a brand new, empty venv each time the patch version is changed. That doesn't seem like a big deal to me, but maybe that's because we tightly control the exact version of python we're using on a project by project basis (using asdf). For us, the upgrades are very intentional and we want everyone on the same version of python. It sounds like maybe you're relying upon some floating (system level?) version of python? Then I can see how that would be annoying (system update results in effectively emptying out all your project venvs).

I thought the intent of #1033 was something about vscode (as mentioned in #1035), but now I'm just realizing you haven't said anything about IDEs or vscode in this conversation, haha.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants