Skip to content

Commit 0b02a8c

Browse files
authored
uv init: Implies --package when using --build-backend (#8593)
## Summary Closes #8568
1 parent d362e03 commit 0b02a8c

File tree

4 files changed

+50
-6
lines changed

4 files changed

+50
-6
lines changed

crates/uv-cli/src/lib.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -2473,7 +2473,7 @@ pub struct InitArgs {
24732473
///
24742474
/// Defines a `[build-system]` for the project.
24752475
///
2476-
/// This is the default behavior when using `--lib`.
2476+
/// This is the default behavior when using `--lib` or `--build-backend`.
24772477
///
24782478
/// When using `--app`, this will include a `[project.scripts]` entrypoint and use a `src/`
24792479
/// project structure.
@@ -2485,7 +2485,7 @@ pub struct InitArgs {
24852485
/// Does not include a `[build-system]` for the project.
24862486
///
24872487
/// This is the default behavior when using `--app`.
2488-
#[arg(long, overrides_with = "package", conflicts_with = "lib")]
2488+
#[arg(long, overrides_with = "package", conflicts_with_all = ["lib", "build_backend"])]
24892489
pub r#no_package: bool,
24902490

24912491
/// Create a project for an application.
@@ -2515,7 +2515,7 @@ pub struct InitArgs {
25152515
///
25162516
/// By default, adds a requirement on the system Python version; use `--python` to specify an
25172517
/// alternative Python version requirement.
2518-
#[arg(long, alias="script", conflicts_with_all=["app", "lib", "package"])]
2518+
#[arg(long, alias="script", conflicts_with_all=["app", "lib", "package", "build_backend"])]
25192519
pub r#script: bool,
25202520

25212521
/// Initialize a version control system for the project.
@@ -2526,6 +2526,8 @@ pub struct InitArgs {
25262526
pub vcs: Option<VersionControlSystem>,
25272527

25282528
/// Initialize a build-backend of choice for the project.
2529+
///
2530+
/// Implicitly sets `--package`.
25292531
#[arg(long, value_enum, conflicts_with_all=["script", "no_package"])]
25302532
pub build_backend: Option<ProjectBuildBackend>,
25312533

crates/uv/src/settings.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ impl InitSettings {
202202
(_, _, _) => unreachable!("`app`, `lib`, and `script` are mutually exclusive"),
203203
};
204204

205-
let package = flag(package || r#virtual, no_package).unwrap_or(kind.packaged_by_default());
205+
let package = flag(package || build_backend.is_some() || r#virtual, no_package)
206+
.unwrap_or(kind.packaged_by_default());
206207

207208
Self {
208209
path,

crates/uv/tests/it/init.rs

+39
Original file line numberDiff line numberDiff line change
@@ -2536,6 +2536,45 @@ fn init_library_flit() -> Result<()> {
25362536
Ok(())
25372537
}
25382538

2539+
/// Run `uv init --build-backend flit` should be equivalent to `uv init --package --build-backend flit`.
2540+
#[test]
2541+
fn init_backend_implies_package() {
2542+
let context = TestContext::new("3.12");
2543+
2544+
uv_snapshot!(context.filters(), context.init().arg("project").arg("--build-backend").arg("flit"), @r#"
2545+
success: true
2546+
exit_code: 0
2547+
----- stdout -----
2548+
2549+
----- stderr -----
2550+
Initialized project `project` at `[TEMP_DIR]/project`
2551+
"#);
2552+
2553+
let pyproject = context.read("project/pyproject.toml");
2554+
insta::with_settings!({
2555+
filters => context.filters(),
2556+
}, {
2557+
assert_snapshot!(
2558+
pyproject, @r#"
2559+
[project]
2560+
name = "project"
2561+
version = "0.1.0"
2562+
description = "Add your description here"
2563+
readme = "README.md"
2564+
requires-python = ">=3.12"
2565+
dependencies = []
2566+
2567+
[project.scripts]
2568+
project = "project:main"
2569+
2570+
[build-system]
2571+
requires = ["flit_core>=3.2,<4"]
2572+
build-backend = "flit_core.buildapi"
2573+
"#
2574+
);
2575+
});
2576+
}
2577+
25392578
/// Run `uv init --app --package --build-backend maturin` to create a packaged application project
25402579
#[test]
25412580
#[cfg(feature = "crates-io")]

docs/reference/cli.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,9 @@ uv init [OPTIONS] [PATH]
489489

490490
<li><code>none</code>: Do not infer the author information</li>
491491
</ul>
492-
</dd><dt><code>--build-backend</code> <i>build-backend</i></dt><dd><p>Initialize a build-backend of choice for the project</p>
492+
</dd><dt><code>--build-backend</code> <i>build-backend</i></dt><dd><p>Initialize a build-backend of choice for the project.</p>
493+
494+
<p>Implicitly sets <code>--package</code>.</p>
493495

494496
<p>Possible values:</p>
495497

@@ -589,7 +591,7 @@ uv init [OPTIONS] [PATH]
589591

590592
<p>Defines a <code>[build-system]</code> for the project.</p>
591593

592-
<p>This is the default behavior when using <code>--lib</code>.</p>
594+
<p>This is the default behavior when using <code>--lib</code> or <code>--build-backend</code>.</p>
593595

594596
<p>When using <code>--app</code>, this will include a <code>[project.scripts]</code> entrypoint and use a <code>src/</code> project structure.</p>
595597

0 commit comments

Comments
 (0)