mirror of https://github.com/astral-sh/uv
Add poetry-core as a build backend option (#12781)
<!-- Thank you for contributing to uv! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? - Does this pull request include references to any relevant issues? --> ## Summary <!-- What's the purpose of the change? What does it do, and why? --> This adds `poetry-core` as a build backend choice. ## Test Plan <!-- How was it tested? --> --------- Co-authored-by: konstin <konstin@mailbox.org>
This commit is contained in:
parent
4680c9b22d
commit
6292748371
|
|
@ -24,6 +24,10 @@ pub enum ProjectBuildBackend {
|
|||
#[serde(alias = "pdm-backend")]
|
||||
#[cfg_attr(feature = "clap", value(alias = "pdm-backend"))]
|
||||
PDM,
|
||||
/// Use [poetry-core](https://pypi.org/project/poetry-core) as the project build backend.
|
||||
#[serde(alias = "poetry-core")]
|
||||
#[cfg_attr(feature = "clap", value(alias = "poetry-core", alias = "poetry_core"))]
|
||||
Poetry,
|
||||
/// Use [setuptools](https://pypi.org/project/setuptools) as the project build backend.
|
||||
Setuptools,
|
||||
/// Use [maturin](https://pypi.org/project/maturin) as the project build backend.
|
||||
|
|
|
|||
|
|
@ -959,6 +959,12 @@ fn pyproject_build_system(package: &PackageName, build_backend: ProjectBuildBack
|
|||
build-backend = "setuptools.build_meta"
|
||||
"#}
|
||||
.to_string(),
|
||||
ProjectBuildBackend::Poetry => indoc::indoc! {r#"
|
||||
[build-system]
|
||||
requires = ["poetry-core>=2,<3"]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
"#}
|
||||
.to_string(),
|
||||
// Binary build backends
|
||||
ProjectBuildBackend::Maturin => indoc::formatdoc! {r#"
|
||||
[tool.maturin]
|
||||
|
|
|
|||
|
|
@ -3048,6 +3048,87 @@ fn init_backend_implies_package() {
|
|||
});
|
||||
}
|
||||
|
||||
/// Run `uv init --build-backend poetry` to create a project with poetry-core build backend
|
||||
#[test]
|
||||
fn init_library_poetry() -> Result<()> {
|
||||
let context = TestContext::new("3.12").with_exclude_newer("2025-04-28T00:00:00Z");
|
||||
|
||||
let child = context.temp_dir.child("foo");
|
||||
child.create_dir_all()?;
|
||||
|
||||
let pyproject_toml = child.join("pyproject.toml");
|
||||
let init_py = child.join("src").join("foo").join("__init__.py");
|
||||
let py_typed = child.join("src").join("foo").join("py.typed");
|
||||
|
||||
uv_snapshot!(context.filters(), context.init().current_dir(&child).arg("--lib").arg("--build-backend").arg("poetry"), @r###"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
|
||||
----- stderr -----
|
||||
Initialized project `foo`
|
||||
"###);
|
||||
|
||||
let pyproject = fs_err::read_to_string(&pyproject_toml)?;
|
||||
insta::with_settings!({
|
||||
filters => context.filters(),
|
||||
}, {
|
||||
assert_snapshot!(
|
||||
pyproject, @r###"
|
||||
[project]
|
||||
name = "foo"
|
||||
version = "0.1.0"
|
||||
description = "Add your description here"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.12"
|
||||
dependencies = []
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core>=2,<3"]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
"###
|
||||
);
|
||||
});
|
||||
|
||||
let init = fs_err::read_to_string(init_py)?;
|
||||
insta::with_settings!({
|
||||
filters => context.filters(),
|
||||
}, {
|
||||
assert_snapshot!(
|
||||
init, @r###"
|
||||
def hello() -> str:
|
||||
return "Hello from foo!"
|
||||
"###
|
||||
);
|
||||
});
|
||||
|
||||
let py_typed = fs_err::read_to_string(py_typed)?;
|
||||
insta::with_settings!({
|
||||
filters => context.filters(),
|
||||
}, {
|
||||
assert_snapshot!(
|
||||
py_typed, @""
|
||||
);
|
||||
});
|
||||
|
||||
uv_snapshot!(context.filters(), context.run().current_dir(&child).env_remove(EnvVars::VIRTUAL_ENV).arg("python").arg("-c").arg("import foo; print(foo.hello())"), @r###"
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
Hello from foo!
|
||||
|
||||
----- stderr -----
|
||||
Using CPython 3.12.[X] interpreter at: [PYTHON-3.12]
|
||||
Creating virtual environment at: .venv
|
||||
Resolved 1 package in [TIME]
|
||||
Prepared 1 package in [TIME]
|
||||
Installed 1 package in [TIME]
|
||||
+ foo==0.1.0 (from file://[TEMP_DIR]/foo)
|
||||
"###);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Run `uv init --app --package --build-backend maturin` to create a packaged application project
|
||||
#[test]
|
||||
#[cfg(feature = "crates-io")]
|
||||
|
|
|
|||
|
|
@ -576,6 +576,8 @@ uv init [OPTIONS] [PATH]
|
|||
|
||||
<li><code>pdm</code>: Use <a href='https://pypi.org/project/pdm-backend'>pdm-backend</a> as the project build backend</li>
|
||||
|
||||
<li><code>poetry</code>: Use <a href='https://pypi.org/project/poetry-core'>poetry-core</a> as the project build backend</li>
|
||||
|
||||
<li><code>setuptools</code>: Use <a href='https://pypi.org/project/setuptools'>setuptools</a> as the project build backend</li>
|
||||
|
||||
<li><code>maturin</code>: Use <a href='https://pypi.org/project/maturin'>maturin</a> as the project build backend</li>
|
||||
|
|
|
|||
Loading…
Reference in New Issue