Skip to content

feat: Add Uv Python package manager #10020

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

feat: Add Uv Python package manager #10020

wants to merge 3 commits into from

Conversation

heliocastro
Copy link
Contributor

@heliocastro heliocastro commented Mar 11, 2025

Uv is Astral.sh Python package/project manager solution. The backend is based on Rust and is a merge result of two projects, the original package manager uv and the Python project manager rye,

Reference:

@heliocastro heliocastro added the analyzer About the analyzer tool label Mar 11, 2025
@heliocastro heliocastro self-assigned this Mar 11, 2025
@heliocastro heliocastro force-pushed the feat/python_uv branch 2 times, most recently from 27a370a to 8e01f73 Compare March 11, 2025 16:47
Copy link

codecov bot commented Mar 11, 2025

Codecov Report

Attention: Patch coverage is 52.00000% with 12 lines in your changes missing coverage. Please review.

Project coverage is 69.55%. Comparing base (d50c3ae) to head (f0c902f).

Files with missing lines Patch % Lines
...nagers/python/src/main/kotlin/utils/PythonUtils.kt 63.15% 1 Missing and 6 partials ⚠️
...ommands/repoconfig/GenerateScopeExcludesCommand.kt 0.00% 5 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main   #10020      +/-   ##
============================================
- Coverage     69.59%   69.55%   -0.04%     
  Complexity     1462     1462              
============================================
  Files           270      270              
  Lines          9665     9690      +25     
  Branches       1025     1034       +9     
============================================
+ Hits           6726     6740      +14     
- Misses         2489     2495       +6     
- Partials        450      455       +5     
Flag Coverage Δ
funTest-docker 68.19% <63.15%> (+<0.01%) ⬆️
funTest-non-docker 33.26% <0.00%> (-0.04%) ⬇️
test-ubuntu-24.04 39.37% <48.00%> (+0.03%) ⬆️
test-windows-2022 39.35% <48.00%> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@heliocastro heliocastro marked this pull request as ready for review March 11, 2025 18:08
@heliocastro heliocastro requested review from a team as code owners March 11, 2025 18:08
@heliocastro heliocastro force-pushed the feat/python_uv branch 3 times, most recently from 1b134d5 to ed7dd63 Compare March 12, 2025 07:51
@heliocastro heliocastro force-pushed the feat/python_uv branch 2 times, most recently from 11ffddc to 736c767 Compare March 12, 2025 11:19
Signed-off-by: Helio Chissini de Castro <helio.chissini.de.castro@cariad.technology>
Signed-off-by: Helio Chissini de Castro <helio.chissini.de.castro@cariad.technology>
@sschuberth
Copy link
Member

Just as a somewhat related remark, Dependabot now can also handle uv.

@heliocastro
Copy link
Contributor Author

Just as a somewhat related remark, Dependabot now can also handle uv.

Right on time, i say

Copy link
Member

@sschuberth sschuberth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this needs major rework for work without python-inspector, which is know to have several problems.

Please also remove the merge commit from the history.

@@ -147,6 +147,7 @@ ARG PYTHON_PIPENV_VERSION
ARG PYTHON_POETRY_VERSION
ARG PYTHON_POETRY_PLUGIN_EXPORT_VERSION
ARG PYTHON_SETUPTOOLS_VERSION
ARG PYTHON_UV_VERSION
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is the first commit introducing uv, the commit should briefly explain what it is, plus contain a link to https://docs.astral.sh/uv/.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spelling-wise, it seems we should use "uv" instead of "Uv".

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, the commit message should make explicit that this is done as a preparation for adding uv support as a package manager in ORT.

@@ -25,6 +25,7 @@ ARG PYTHON_POETRY_VERSION=2.0.1
ARG PYTHON_POETRY_PLUGIN_EXPORT_VERSION=1.9.0
ARG PYTHON_SETUPTOOLS_VERSION=74.1.3
ARG PYTHON_VERSION=3.11.10
ARG PYTHON_UV_VERSION=0.6.5
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import org.ossreviewtoolkit.utils.test.matchExpectedResult

class UvFunTest : WordSpec({
"Python 3" should {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Python 3" -> "Uv"

internal object UvCommand : CommandLineTool {
override fun command(workingDir: File?) = "uv"

override fun transformVersion(output: String) = output.substringAfter("version ").removeSuffix(")")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me, the version output is

$ uv --version
uv 0.6.2

So why the .substringAfter("version ").removeSuffix(")")? Shouldn't it be just .substringAfter("uv ")?

*/
@OrtPlugin(
displayName = "Uv",
description = "An extremely fast Python package and project manager.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO we should not adopt to their marketing language here, and drop "extremely fast". So just say "A Python package and project manager".

description = "An extremely fast Python package and project manager.",
factory = PackageManagerFactory::class
)
class Uv(override val descriptor: PluginDescriptor = UvFactory.descriptor, private val config: PipConfig) :
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the only reason why Pip.kt, Pipenv.kt and Poetry.kt shared PipConfig so far is that all of these are handled by python-inspector (and PipConfig contains python-inspector-specific config).

But for the independent Uv implementation, I believe we should have a separate UvConfig.

internal const val PYPROJECT_FILENAME = "pyproject.toml"
}

override val globsForDefinitionFiles = listOf("uv.lock")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line triggered cc7059a on my side. Once that PR is merged, please take over the final wording of that comment here.

Comment on lines +84 to +85
.distinctBy { it.id }
.toSet()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also looks unnecessary. As I realize you've copied this from the Poetry implementation, I'm removing that as part of #10051 as well.

}

/**
* Return the result of running Python inspector against a requirements file generated by exporting the dependencies
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, so you are using python-inspector after all... not that falling back to using requirements.txt files should really just be a last resort, as those files only contain a flat list of direct dependencies without much metadata.

I was under the assumption that a modern manager like uv offers better ways to query dependencies.

@sschuberth
Copy link
Member

I believe this needs major rework for work without python-inspector, which is know to have several problems.

So I guess we'd want astral-sh/uv#4711 to be implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer About the analyzer tool
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants