-
Notifications
You must be signed in to change notification settings - Fork 84
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
Add support to detect uv based projects #205
base: master
Are you sure you want to change the base?
Conversation
@MichaelAquilina, any chance you give me a yes/maybe/no answer? |
Hi @afeblot :) I'm open to the idea of adding support for this package manager in. Thanks for your contribution. I'll have to get a bit familiar with |
@@ -56,6 +56,10 @@ function _get_venv_type() { | |||
venv_type="poetry" | |||
elif [[ -f "$venv_dir/requirements.txt" || -f "$venv_dir/setup.py" ]]; then | |||
venv_type="virtualenv" | |||
elif [[ -f "$venv_dir/uv.lock" ]]; then | |||
venv_type="uv" | |||
elif [[ -f "$venv_dir/pyproject.toml" && $(grep -c '[tool.uv]' "$venv_dir/pyproject.toml") -gt 0 ]]; then |
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.
could this line be turned into a function?
$(grep -c '[tool.uv]' "$venv_dir/pyproject.toml") -gt 0
Something like
function _check_pyproject_type {
local result
if [[ $(grep -c '[tool.uv]' "$venv_dir/pyproject.toml") -gt 0 ]]; then
result = "uv"
elif [[ $(grep -c '[tool.poetry]' "$venv_dir/pyproject.toml") -gt 0 ]]; then
result = "poetry"
....
printf "$result"
}
elif [[ -f "$venv_dir/pyproject.toml" ]]; then
venv_type="$(_check_pyproject_type)"
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.
Hmmm. With uv 0.4.27 bringing support for dependency groups as described by PEP 735, and the replacement of
[tool.uv]
dev-dependencies = ["some-dependencies"]
by
[dependency-groups]
dev = ["some-dependencies"]
I don't really know now how to detect that a pyproject.toml file can and is supposed to be handled by uv.
I guess we can't just assume all pyproject.toml are handled by uv.
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.
@MichaelAquilina gentle reminder for reviewing this ticket if you can spare the time 🙏
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.
@afeblot I would suggest to use the lock file to determine if it is a poetry or uv managed project. If uv.lock
or poetry.lock
, handle accordingly.
uv seems to become the de-facto standard Python package and project manager.
This pull request provides support to detect uv-based projects, based on
uv.lock
pyproject.toml
containing a[tool.uv]
sectionand initializes the virtual env with the
uv.sync
command.uv sync
standard behavior beeing creating the virtual env in$project_dir/.venv/
, the virtual env is then handled as a "virtualenv" virtual env type.$ cd myproj Python uv project detected. Run mkvenv to setup autoswitching $ mkvenv Creating virtual environment at: .venv [...truncated...] Switching virtualenv: .venv [Python 3.11.6]