-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Upgrade dependencies in pyproject.toml
(uv upgrade
)
#6794
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
Comments
Does Also, I'm pretty sure dependencies will also be updated during every |
I don't think uv sync can bump the pinned versions of every dependency to the latest available version, which I believe is what the issue creator is asking about. uv sync just downloads modules that match the pin, it doesn't change the pin. This topic always ends up being confusing, people have different definitions of what it means to update or upgrade a dependency. 😅 |
Ahh, yes Would it be recommended to not pin exact dependencies in the
|
I suspect a lot of teams have a similar workflow to my team, which most project tooling has poor support for. In the pre-Dependabot days, once a month or so we'd open up the project file on one screen and pypi on the other, then manually bump all the versions to the latest we could find. Then we'd install everything, read release notes, check what broke, and perhaps go back a version or two for some of the dependencies (which is why unpinning all the deps wouldn't work). After that we'd generate a new lock file. Having an upgrade command would remove the manual labor of having to look up all the versions and editing the file for each individual dependency. |
Poetry has a nice workflow by using |
Use |
Although I will note that it would be nice to be able to see which packages are outdated, similar to |
That's tracked in #2150. |
Like @KotlinIsland said, especially for applications it's really nice to be able to browse narrow ranges of your top level dependencies within It's also important to be able to skip dependencies that the user has pinned to a specific version in The old For more prior art, see It has a nice output UI: (Long) discussion from the same feature requested in Poetry |
I agree this would be a really helpful feature, especially useful in PRs for tracking version increments. Its a lot easier to see these in pyproject.toml than a lock file |
I'm also a big fan of yarn's |
upgrade
commandpyproject.toml
I use this tiny script. Works like a charm. |
pyproject.toml
pyproject.toml
Is this intended to handle the following use case?
(where Would it require something like Currently, even an ugly hack like
isn't working, because |
You might be interested in @KotlinIsland’s improved version, as this should handle dependency groups. |
Would this count as using uv?
|
🤔 Does |
PDM is excruciatingly slow... The current work around with a script that uses UV to remove and readd deps is many times faster |
+1 |
I'm a fan of npm-check-updates personally, especially because you can filter via For poetry, I've used a combination of |
Hi guys, as a temporary solution I've wrote a small program to sync the minimum versions of top-level dependencies. Anyways, hope it might be helpful! Feel free to check it out: https://github.com/kedvall/pysync. |
For anyone using Basically just I recently improved it by adding the ability to search the optional dependencies. Note: It doesn't currently sort into version order. |
So, I used a variation of the script discussed above for this. But now I am working inside a monorepo with multiple UV modules, and writing a script for this has become increasingly complex. I think this has to be a part of the built-in uv command, and I frankly don't see why this should be complex - it's rather smallish. The question is, is there interest and willingness from the uv maintainers? If there is, I or someone else can contribute to this. |
Interested in this as well. |
I bit gross, but this bash command works for me. It removes and then adds all dependencies deps=$(sed -n '/^\s*dependencies\s*=\s*\[/,/^\s*]/p' pyproject.toml | \
grep -vE '^\s*dependencies\s*=\s*\[|^\s*\]' | \
sed -E 's/[",]//g' | \
sed -E 's/[<>=!~].*//' | \
grep -vE '^\s*$' | \
xargs)
bash -c "uv remove $deps && uv add $deps" |
Nice! Now optional dependencies would be good (every line is a list) 😅 |
pyproject.toml
pyproject.toml
pyproject.toml
pyproject.toml
(uv upgrade
)
I just tried to manually change a dependency version in I updated
After running It's kind of deceiving (unintentionally) for That is my use case for needing the |
the uv-bump solution above works pretty well. Perhpas it can be published? |
Do you mean:
I don't think uv run changes the lockfile, did you call There should be no other "output" files laying around (only pyproject.toml and uv.lock). And pay attention to the log output, other dependencies can influence the outcome (preventing updates). |
Here is a shell script for upgrading all dependencies: #!/bin/bash -e
# Allow to specify a directory as the first argument
dir=.
if [ $# -gt 0 ]; then
dir=$1
fi
# Sync the current project
uv --directory "$dir" sync --refresh --locked
# Get all the outdated dependencies
outdated="$(uv --directory "$dir" pip list --outdated --format json | jq -r '.[] | {name,version,latest_version} | join(" ")')"
# Iterate over all of them
upgraded=false
while IFS= read -r line; do
[ -z "$line" ] && continue
IFS=' ' read -r name version latest_version <<< "$line"
# Check if they are actually present in pyproject.toml or a dependency of a dependency
if grep -q "$name" "$dir/pyproject.toml"; then
echo "Upgrading $name $version -> $latest_version"
sed -i -E "s/$name( ?[~=>]?[>=] ?)$version/$name\1$latest_version/" "$dir/pyproject.toml"
upgraded=true
fi
done <<< "$outdated"
# Re-lock the project if a dependency was upgraded
if $upgraded; then
uv --directory "$dir" lock
fi |
@Lauszus -- great idea, but unfortunately, it misses what is, I would think, a pretty common case. If the installed version is the latest (because the version spec in For example, if
@tdamsma's script above will replace the old version spec with the new in this case (by removing, then reinstalling), but that might not always be right, either. I think the only reasonable way to really do this is to snag all the version specs out of pyproject.toml, snag them from a refreshed Also, there are some ambiguities around how to update the spec e.g. do you use Regardless, I don't know about you, but I sure wouldn't want to do that in a bash script ;-). |
Ahh I see your point. It won't work for This was just a quick script I did to get it working for me since Dependabot keeps breaking, so wanted to share it in case somebody else might find it useful :) |
I have published it here: https://pypi.org/project/uv-bump/. |
This is why in uv-bump I decided to define dependencies with |
I'd appreciate a workflow similar to |
this will update the version pins in the pyproject.toml file
prior art:
why? when i want to update all the dependencies in a project, it can be tedious to manually search for and update each and every dependency. additionally, for application projects (not libraries), i like to be able to squizz the pyproject file for an easy overview of which dependencies are actually installed, not just some possible range
The text was updated successfully, but these errors were encountered: