File tree 2 files changed +74
-1
lines changed
2 files changed +74
-1
lines changed Original file line number Diff line number Diff line change @@ -282,7 +282,17 @@ pub fn build_editable(
282
282
return Err ( Error :: AbsoluteModuleRoot ( settings. module_root . clone ( ) ) ) ;
283
283
}
284
284
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 ( ) ) ;
286
296
if !module_root. join ( "__init__.py" ) . is_file ( ) {
287
297
return Err ( Error :: MissingModule ( module_root) ) ;
288
298
}
Original file line number Diff line number Diff line change @@ -368,3 +368,66 @@ fn rename_module() -> Result<()> {
368
368
369
369
Ok ( ( ) )
370
370
}
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
+ }
You can’t perform that action at this time.
0 commit comments