Skip to content

Commit f2ff218

Browse files
build-backend: Allow overriding module names for editable builds (#12137)
## Summary This PR enables module name overrides for editable installs. Builds upon #11884. The `tool.uv.build-backend.module-name` option is now respected during editable build processes. ## Test Plan Added a test. --------- Co-authored-by: Charlie Marsh <[email protected]>
1 parent 897508a commit f2ff218

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

crates/uv-build-backend/src/wheel.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,17 @@ pub fn build_editable(
282282
return Err(Error::AbsoluteModuleRoot(settings.module_root.clone()));
283283
}
284284
let src_root = source_tree.join(settings.module_root);
285-
let module_root = src_root.join(pyproject_toml.name().as_dist_info_name().as_ref());
285+
286+
let module_name = if let Some(module_name) = settings.module_name {
287+
module_name
288+
} else {
289+
// Should never error, the rules for package names (in dist-info formatting) are stricter
290+
// than those for identifiers
291+
Identifier::from_str(pyproject_toml.name().as_dist_info_name().as_ref())?
292+
};
293+
debug!("Module name: `{:?}`", module_name);
294+
295+
let module_root = src_root.join(module_name.as_ref());
286296
if !module_root.join("__init__.py").is_file() {
287297
return Err(Error::MissingModule(module_root));
288298
}

crates/uv/tests/it/build_backend.rs

+63
Original file line numberDiff line numberDiff line change
@@ -368,3 +368,66 @@ fn rename_module() -> Result<()> {
368368

369369
Ok(())
370370
}
371+
372+
/// Test `tool.uv.build-backend.module-name` for editable builds.
373+
#[test]
374+
fn rename_module_editable_build() -> Result<()> {
375+
let context = TestContext::new("3.12");
376+
let temp_dir = TempDir::new()?;
377+
378+
context
379+
.temp_dir
380+
.child("pyproject.toml")
381+
.write_str(indoc! {r#"
382+
[project]
383+
name = "foo"
384+
version = "1.0.0"
385+
386+
[tool.uv.build-backend]
387+
module-name = "bar"
388+
389+
[build-system]
390+
requires = ["uv_build>=0.5,<0.7"]
391+
build-backend = "uv_build"
392+
"#})?;
393+
394+
context
395+
.temp_dir
396+
.child("src/bar/__init__.py")
397+
.write_str(r#"print("Hi from bar")"#)?;
398+
399+
uv_snapshot!(context
400+
.build_backend()
401+
.arg("build-editable")
402+
.arg(temp_dir.path())
403+
.env("UV_PREVIEW", "1"), @r###"
404+
success: true
405+
exit_code: 0
406+
----- stdout -----
407+
foo-1.0.0-py3-none-any.whl
408+
409+
----- stderr -----
410+
"###);
411+
412+
context
413+
.pip_install()
414+
.arg(temp_dir.path().join("foo-1.0.0-py3-none-any.whl"))
415+
.assert()
416+
.success();
417+
418+
// Importing the module with the `module-name` name succeeds.
419+
uv_snapshot!(Command::new(context.interpreter())
420+
.arg("-c")
421+
.arg("import bar")
422+
// Python on windows
423+
.env(EnvVars::PYTHONUTF8, "1"), @r###"
424+
success: true
425+
exit_code: 0
426+
----- stdout -----
427+
Hi from bar
428+
429+
----- stderr -----
430+
"###);
431+
432+
Ok(())
433+
}

0 commit comments

Comments
 (0)