mise icon indicating copy to clipboard operation
mise copied to clipboard

Allow to force virtualenv creation by default

Open noirbizarre opened this issue 1 year ago • 3 comments

To enable virtualenv creation, we need to add this to the .mise.toml:

[env]
_.python.venv = { path = ".venv", create = true }

This form prevent from applying it globally and doing it with a single command line mise use python@<version>.

It would be nice to have a way to say "I always want a virtualenv created in .venv" so when I run mise use python@<version> it automatically creates the .venv whatever the directory I am into.

(If there is already a way of doing this, I might have missed it, links are welcome)

noirbizarre avatar Mar 01 '24 16:03 noirbizarre

I tried to put _.python.venv = { path = ".venv", create = true } to ~/.config/mise/config.toml, but it creates a single .venv in ~/.config/mise/.venv. Which is exactly what is written in the docs (the path is relative to that particular config file), but I had to try it nevertheless, just in case 😀

Having global config for env vars works correctly. E.g. PYTHONDONTWRITEBYTECODE = "1" in ~/.config/mise/config.toml seems to get applied globally.

honzajavorek avatar Mar 05 '24 09:03 honzajavorek

In https://github.com/jdx/mise/issues/1438#issuecomment-1889757358 I noticed existence of https://github.com/mise-plugins/mise-poetry, which solves my problem.

honzajavorek avatar Mar 05 '24 09:03 honzajavorek

Yes, I tried before submitting this issue 😉

For the mise-plugins/mise-poetry, I think this is not specific to poetry but to any Python project. Most of the time, impact is bigger for non poetry and non pdm projects as they both can create the virtualenv for you. My main case for this is contributing to projects just using setuptools for which I would love to be able to just run mise use python@<version> and be ready to contribute with a proper and clean virtualenv.

noirbizarre avatar Mar 05 '24 12:03 noirbizarre

I've been using this short alias for a while to quickly select a python version and setup a venv : pv='rm .venv ; version="$(mise list python | grep -F python | awk "{ print \$2 }" | fzf)" ; echo -e "[tools]\npython = \"$version\"\n[env]\n_.python.venv = { path = \".venv\", create = true }" | tee .mise.toml'

But it has the huge disadvantage of destroying the current .mise.toml file, which isn't much fun. That's why I came here looking for a way (i.e. a mise command) to automatically ask for a venv to be created, maybe something like mise use [email protected] --with-venv, or even further, force the .venv to be added to the local mise file by default, and allow preventing this behavior by using --no-venv ?

I'll rework my alias until it's discussed, something to append the right lined if not already present, and rely on mise for inserting the python version in the conf file.. 🙃

laluka avatar Aug 27 '24 20:08 laluka

We could have a setting for this, seems there is plenty of appetite for it.

That said, if it were me I'd use a utility like this: https://github.com/gnprice/toml-cli

We do have mise set which can be used to set env vars, however there isn't a way to use that with directives, maybe we should have something like mise set --directive python.venv --path .venv --create true

jdx avatar Aug 27 '24 20:08 jdx

2 years updatelesss.. 😱 But yeah, relying on a toml manipulation is better than my new shitty alias 🤣

#!/bin/bash
set -uo pipefail
IFS=$'\n\t'

version="$(mise list python | grep -F python | awk "{ print \$2 }" | fzf)"
rm -rf .venv
mise use python@${version}
grep -F '[env]' .mise.toml || echo -e '[env]' >> .mise.toml
grep -F '_.python.venv = { path = ".venv", create = true }' .mise.toml || echo '_.python.venv = { path = ".venv", create = true }' >> .mise.toml
mise trust 2>/dev/null
bat -P .mise.toml

laluka avatar Aug 28 '24 08:08 laluka

2 years updatelesss.. 😱

Get outta here with your fake news 😜

jdx avatar Aug 28 '24 10:08 jdx

Quel est le fuck ? :thinking: :laughing: :heart_decoration:

image

laluka avatar Aug 28 '24 10:08 laluka

oh I thought you were talking about this ticket, I was confused since mise hasn't been around 2 years 😂

in any case, weren't we just having a conversation where I said I often forget about what is actually in mise? https://github.com/jdx/mise/blob/3aa5f5784ec63ec04f0ffeb5c1d2246687a65314/src/plugins/core/python.rs#L262-L263

seems I added this setting already but forgot to add it to the docs

jdx avatar Aug 28 '24 10:08 jdx