Update description

This commit is contained in:
konstin 2025-12-11 15:42:28 +01:00
parent ad12ba6907
commit 19756166c1
2 changed files with 77 additions and 20 deletions

View File

@ -310,7 +310,6 @@ impl SourceBuild {
&source_tree, &source_tree,
install_path, install_path,
fallback_package_name, fallback_package_name,
fallback_package_version,
locations, locations,
source_strategy, source_strategy,
workspace_cache, workspace_cache,
@ -563,7 +562,6 @@ impl SourceBuild {
source_tree: &Path, source_tree: &Path,
install_path: &Path, install_path: &Path,
package_name: Option<&PackageName>, package_name: Option<&PackageName>,
package_version: Option<&Version>,
locations: &IndexLocations, locations: &IndexLocations,
source_strategy: SourceStrategy, source_strategy: SourceStrategy,
workspace_cache: &WorkspaceCache, workspace_cache: &WorkspaceCache,
@ -593,6 +591,10 @@ impl SourceBuild {
Err(err) => return Err(Box::new(err.into())), Err(err) => return Err(Box::new(err.into())),
}; };
let build_backend = pyproject_toml
.build_system
.as_ref()
.and_then(|build_backend| build_backend.build_backend.as_deref());
if source_strategy == SourceStrategy::Enabled if source_strategy == SourceStrategy::Enabled
&& pyproject_toml && pyproject_toml
.tool .tool
@ -600,24 +602,24 @@ impl SourceBuild {
.and_then(|tool| tool.uv.as_ref()) .and_then(|tool| tool.uv.as_ref())
.map(|uv| uv.build_backend.is_some()) .map(|uv| uv.build_backend.is_some())
.unwrap_or(false) .unwrap_or(false)
&& pyproject_toml && build_backend != Some("uv_build")
.build_system
.as_ref()
.and_then(|build_backend| build_backend.build_backend.as_deref())
!= Some("uv_build")
&& let Some(package_name) = && let Some(package_name) =
package_name.or(pyproject_toml.project.as_ref().map(|project| &project.name)) package_name.or(pyproject_toml.project.as_ref().map(|project| &project.name))
&& let Some(package_version) = package_version.or(pyproject_toml
.project
.as_ref()
.and_then(|project| project.version.as_ref()))
{ {
// Show name/version where available to avoid showing a (duplicate) warning with // Show only the name, but not the path to `pyproject.toml`, to avoid showing a
// a temporary path. // (duplicate) warning that contains the temporary path of an unpacked source
// distribution in a source tree -> source dist -> wheel build.
if let Some(build_backend) = build_backend {
warn_user_once!( warn_user_once!(
"`pyproject.toml` of {package_name}=={package_version} defines settings for \ "`{package_name}` defines settings for `uv_build` in `tool.uv.build-backend`, \
`uv_build` in `tool.uv.build-backend`, but does not use `uv_build`", but uses `{build_backend}` as build backend instead",
); );
} else {
warn_user_once!(
"`{package_name}` defines settings for `uv_build` in `tool.uv.build-backend`, \
but the `build-system` table is missing",
);
}
} }
let backend = if let Some(build_system) = pyproject_toml.build_system { let backend = if let Some(build_system) = pyproject_toml.build_system {
@ -640,7 +642,8 @@ impl SourceBuild {
locations, locations,
source_strategy, source_strategy,
workspace_cache, workspace_cache,
credentials_cache,) credentials_cache,
)
.await .await
.map_err(Error::Lowering)?; .map_err(Error::Lowering)?;
build_requires.requires_dist build_requires.requires_dist

View File

@ -1249,7 +1249,7 @@ fn tool_uv_build_backend_without_build_backend() -> Result<()> {
----- stderr ----- ----- stderr -----
Building source distribution... Building source distribution...
warning: `pyproject.toml` of project==0.1.0 defines settings for `uv_build` in `tool.uv.build-backend`, but does not use `uv_build` warning: `project` defines settings for `uv_build` in `tool.uv.build-backend`, but the `build-system` table is missing
Building wheel from source distribution... Building wheel from source distribution...
Successfully built dist/project-0.1.0.tar.gz Successfully built dist/project-0.1.0.tar.gz
Successfully built dist/project-0.1.0-py3-none-any.whl Successfully built dist/project-0.1.0-py3-none-any.whl
@ -1262,7 +1262,7 @@ fn tool_uv_build_backend_without_build_backend() -> Result<()> {
----- stderr ----- ----- stderr -----
Resolved 1 package in [TIME] Resolved 1 package in [TIME]
warning: `pyproject.toml` of project==0.1.0 defines settings for `uv_build` in `tool.uv.build-backend`, but does not use `uv_build` warning: `project` defines settings for `uv_build` in `tool.uv.build-backend`, but the `build-system` table is missing
Prepared 1 package in [TIME] Prepared 1 package in [TIME]
Installed 1 package in [TIME] Installed 1 package in [TIME]
+ project==0.1.0 (from file://[TEMP_DIR]/) + project==0.1.0 (from file://[TEMP_DIR]/)
@ -1270,3 +1270,57 @@ fn tool_uv_build_backend_without_build_backend() -> Result<()> {
Ok(()) Ok(())
} }
/// Warn for cases where `tool.uv.build-backend` is used without the corresponding build backend
/// entry.
#[test]
fn tool_uv_build_backend_wrong_build_backend() -> Result<()> {
let context = TestContext::new("3.12");
let project = context.temp_dir.child("project");
let pyproject_toml = project.child("pyproject.toml");
pyproject_toml.write_str(indoc! {r#"
[project]
name = "project"
version = "0.1.0"
[tool.uv]
package = true
[tool.uv.build-backend.data]
data = "assets"
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
"#})?;
project.child("src/project/__init__.py").touch()?;
uv_snapshot!(context.filters(), context.build().arg("--no-build-logs").arg(project.path()), @r"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Building source distribution...
warning: `project` defines settings for `uv_build` in `tool.uv.build-backend`, but uses `hatchling.build` as build backend instead
Building wheel from source distribution...
Successfully built project/dist/project-0.1.0.tar.gz
Successfully built project/dist/project-0.1.0-py2.py3-none-any.whl
");
uv_snapshot!(context.filters(), context.pip_install().arg(project.path()), @r"
success: true
exit_code: 0
----- stdout -----
----- stderr -----
Resolved 1 package in [TIME]
warning: `project` defines settings for `uv_build` in `tool.uv.build-backend`, but uses `hatchling.build` as build backend instead
Prepared 1 package in [TIME]
Installed 1 package in [TIME]
+ project==0.1.0 (from file://[TEMP_DIR]/project)
");
Ok(())
}