mirror of
https://github.com/astral-sh/uv.git
synced 2025-10-10 10:32:09 +00:00
Merge 44c9302de3
into 00d3aa3780
This commit is contained in:
commit
ccc0ac433d
2 changed files with 169 additions and 98 deletions
|
@ -109,6 +109,8 @@ struct Tool {
|
||||||
#[serde(rename_all = "kebab-case")]
|
#[serde(rename_all = "kebab-case")]
|
||||||
struct ToolUv {
|
struct ToolUv {
|
||||||
workspace: Option<de::IgnoredAny>,
|
workspace: Option<de::IgnoredAny>,
|
||||||
|
/// To warn users about ignored build backend settings.
|
||||||
|
build_backend: Option<de::IgnoredAny>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BackendPath {
|
impl BackendPath {
|
||||||
|
@ -562,12 +564,49 @@ impl SourceBuild {
|
||||||
workspace_cache: &WorkspaceCache,
|
workspace_cache: &WorkspaceCache,
|
||||||
default_backend: &Pep517Backend,
|
default_backend: &Pep517Backend,
|
||||||
) -> Result<(Pep517Backend, Option<Project>), Box<Error>> {
|
) -> Result<(Pep517Backend, Option<Project>), Box<Error>> {
|
||||||
match fs::read_to_string(source_tree.join("pyproject.toml")) {
|
let pyproject_toml = match fs::read_to_string(source_tree.join("pyproject.toml")) {
|
||||||
Ok(toml) => {
|
Ok(toml) => {
|
||||||
let pyproject_toml = toml_edit::Document::from_str(&toml)
|
let pyproject_toml = toml_edit::Document::from_str(&toml)
|
||||||
.map_err(Error::InvalidPyprojectTomlSyntax)?;
|
.map_err(Error::InvalidPyprojectTomlSyntax)?;
|
||||||
let pyproject_toml = PyProjectToml::deserialize(pyproject_toml.into_deserializer())
|
PyProjectToml::deserialize(pyproject_toml.into_deserializer())
|
||||||
.map_err(Error::InvalidPyprojectTomlSchema)?;
|
.map_err(Error::InvalidPyprojectTomlSchema)?
|
||||||
|
}
|
||||||
|
Err(err) if err.kind() == io::ErrorKind::NotFound => {
|
||||||
|
// We require either a `pyproject.toml` or a `setup.py` file at the top level.
|
||||||
|
if !source_tree.join("setup.py").is_file() {
|
||||||
|
return Err(Box::new(Error::InvalidSourceDist(
|
||||||
|
source_tree.to_path_buf(),
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
// If no `pyproject.toml` is present, by default, proceed with a PEP 517 build using
|
||||||
|
// the default backend, to match `build`. `pip` uses `setup.py` directly in this
|
||||||
|
// case, but plans to make PEP 517 builds the default in the future.
|
||||||
|
// See: https://github.com/pypa/pip/issues/9175.
|
||||||
|
return Ok((default_backend.clone(), None));
|
||||||
|
}
|
||||||
|
Err(err) => return Err(Box::new(err.into())),
|
||||||
|
};
|
||||||
|
|
||||||
|
if source_strategy == SourceStrategy::Enabled
|
||||||
|
&& pyproject_toml
|
||||||
|
.tool
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|tool| tool.uv.as_ref())
|
||||||
|
.map(|uv| uv.build_backend.is_some())
|
||||||
|
.unwrap_or(false)
|
||||||
|
&& pyproject_toml
|
||||||
|
.build_system
|
||||||
|
.as_ref()
|
||||||
|
.and_then(|build_backend| build_backend.build_backend.as_deref())
|
||||||
|
!= Some("uv_build")
|
||||||
|
{
|
||||||
|
warn_user_once!(
|
||||||
|
"There are settings for `uv_build` defined in \
|
||||||
|
`tool.uv.build-backend`, but `uv_build` is not used by the project at: {}",
|
||||||
|
source_tree.join("pyproject.toml").simplified_display()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
let backend = if let Some(build_system) = pyproject_toml.build_system {
|
let backend = if let Some(build_system) = pyproject_toml.build_system {
|
||||||
// If necessary, lower the requirements.
|
// If necessary, lower the requirements.
|
||||||
|
@ -662,23 +701,6 @@ impl SourceBuild {
|
||||||
};
|
};
|
||||||
Ok((backend, pyproject_toml.project))
|
Ok((backend, pyproject_toml.project))
|
||||||
}
|
}
|
||||||
Err(err) if err.kind() == io::ErrorKind::NotFound => {
|
|
||||||
// We require either a `pyproject.toml` or a `setup.py` file at the top level.
|
|
||||||
if !source_tree.join("setup.py").is_file() {
|
|
||||||
return Err(Box::new(Error::InvalidSourceDist(
|
|
||||||
source_tree.to_path_buf(),
|
|
||||||
)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// If no `pyproject.toml` is present, by default, proceed with a PEP 517 build using
|
|
||||||
// the default backend, to match `build`. `pip` uses `setup.py` directly in this
|
|
||||||
// case, but plans to make PEP 517 builds the default in the future.
|
|
||||||
// See: https://github.com/pypa/pip/issues/9175.
|
|
||||||
Ok((default_backend.clone(), None))
|
|
||||||
}
|
|
||||||
Err(err) => Err(Box::new(err.into())),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Try calling `prepare_metadata_for_build_wheel` to get the metadata without executing the
|
/// Try calling `prepare_metadata_for_build_wheel` to get the metadata without executing the
|
||||||
/// actual build.
|
/// actual build.
|
||||||
|
|
|
@ -1029,3 +1029,52 @@ fn venv_in_source_tree() {
|
||||||
╰─▶ Virtual environments must not be added to source distributions or wheels, remove the directory or exclude it from the build: src/foo/.venv
|
╰─▶ Virtual environments must not be added to source distributions or wheels, remove the directory or exclude it from the build: src/foo/.venv
|
||||||
");
|
");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Warn for cases where `tool.uv.build-backend` is used without the corresponding build backend
|
||||||
|
/// entry.
|
||||||
|
#[test]
|
||||||
|
fn tool_uv_build_backend_without_build_backend() -> Result<()> {
|
||||||
|
let context = TestContext::new("3.12");
|
||||||
|
|
||||||
|
let pyproject_toml = context.temp_dir.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"
|
||||||
|
"#})?;
|
||||||
|
|
||||||
|
uv_snapshot!(context.filters(), context.build().arg("--no-build-logs"), @r"
|
||||||
|
success: true
|
||||||
|
exit_code: 0
|
||||||
|
----- stdout -----
|
||||||
|
|
||||||
|
----- stderr -----
|
||||||
|
Building source distribution...
|
||||||
|
warning: There are settings for `uv_build` defined in `tool.uv.build-backend`, but `uv_build` is not used by the project at: [TEMP_DIR]/pyproject.toml
|
||||||
|
Building wheel from source distribution...
|
||||||
|
warning: There are settings for `uv_build` defined in `tool.uv.build-backend`, but `uv_build` is not used by the project at: [CACHE_DIR]/sdists-v9/[TMP]/pyproject.toml
|
||||||
|
Successfully built dist/project-0.1.0.tar.gz
|
||||||
|
Successfully built dist/project-0.1.0-py3-none-any.whl
|
||||||
|
");
|
||||||
|
|
||||||
|
uv_snapshot!(context.filters(), context.pip_install().arg("."), @r"
|
||||||
|
success: true
|
||||||
|
exit_code: 0
|
||||||
|
----- stdout -----
|
||||||
|
|
||||||
|
----- stderr -----
|
||||||
|
Resolved 1 package in [TIME]
|
||||||
|
warning: There are settings for `uv_build` defined in `tool.uv.build-backend`, but `uv_build` is not used by the project at: [TEMP_DIR]/pyproject.toml
|
||||||
|
Prepared 1 package in [TIME]
|
||||||
|
Installed 1 package in [TIME]
|
||||||
|
+ project==0.1.0 (from file://[TEMP_DIR]/)
|
||||||
|
");
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue