Skip to content

Commit a4a350a

Browse files
committed
Review
1 parent f9dbfbd commit a4a350a

File tree

3 files changed

+42
-19
lines changed

3 files changed

+42
-19
lines changed

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

+9-8
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,17 @@ pub enum Error {
5656
#[error("Failed to write RECORD file")]
5757
Csv(#[from] csv::Error),
5858
#[error(
59-
"Expected a Python module for `{}` with an `__init__.py` at: `{}`",
60-
module_name,
61-
project_src.user_display()
59+
"Expected a Python module directory at: `{}`",
60+
_0.user_display()
6261
)]
63-
MissingModule {
64-
module_name: Identifier,
65-
project_src: PathBuf,
66-
},
62+
MissingModule(PathBuf),
63+
#[error(
64+
"Expected an `__init__.py` at: `{}`",
65+
_0.user_display()
66+
)]
67+
MissingInitPy(PathBuf),
6768
#[error(
68-
"Expected a single Python module for `{}` with an `__init__.py`, found multiple:\n* `{}`",
69+
"Expected an `__init__.py` at `{}`, found multiple:\n* `{}`",
6970
module_name,
7071
paths.iter().map(Simplified::user_display).join("`\n* `")
7172
)]

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

+15-7
Original file line numberDiff line numberDiff line change
@@ -254,17 +254,25 @@ fn find_module_root(src_root: &Path, module_name: Identifier) -> Result<PathBuf,
254254
let normalized = module_name.to_string();
255255
let modules = fs_err::read_dir(src_root)?
256256
.filter_ok(|entry| {
257-
entry.file_name().to_string_lossy().to_lowercase() == normalized
258-
&& entry.path().join("__init__.py").is_file()
257+
entry
258+
.file_name()
259+
.to_str()
260+
.is_some_and(|file_name| file_name.to_lowercase() == normalized)
259261
})
260262
.map_ok(|entry| entry.path())
261263
.collect::<Result<Vec<_>, _>>()?;
262264
match modules.as_slice() {
263-
[] => Err(Error::MissingModule {
264-
module_name,
265-
project_src: src_root.to_path_buf(),
266-
}),
267-
[module_root] => Ok(module_root.clone()),
265+
[] => {
266+
// Show the normalized path in the error message, as representative example.
267+
Err(Error::MissingModule(src_root.join(module_name.as_ref())))
268+
}
269+
[module_root] => {
270+
if module_root.join("__init__.py").is_file() {
271+
Ok(module_root.clone())
272+
} else {
273+
Err(Error::MissingInitPy(module_root.join("__init__.py")))
274+
}
275+
}
268276
multiple => {
269277
let mut paths = multiple.to_vec();
270278
paths.sort();

crates/uv/tests/it/build_backend.rs

+18-4
Original file line numberDiff line numberDiff line change
@@ -458,14 +458,28 @@ fn build_module_name_normalization() -> Result<()> {
458458
uv_snapshot!(context
459459
.build_backend()
460460
.arg("build-wheel")
461-
.arg(&wheel_dir), @r"
461+
.arg(&wheel_dir), @r###"
462462
success: false
463463
exit_code: 2
464464
----- stdout -----
465465
466466
----- stderr -----
467-
error: Expected a Python module for `django_plugin` with an `__init__.py` at: `src`
468-
");
467+
error: Expected a Python module directory at: `src/django_plugin`
468+
"###);
469+
470+
fs_err::create_dir_all(context.temp_dir.join("src/Django_plugin"))?;
471+
// Error case 2: A matching module, but no `__init__.py`.
472+
uv_snapshot!(context
473+
.build_backend()
474+
.arg("build-wheel")
475+
.arg(&wheel_dir), @r###"
476+
success: false
477+
exit_code: 2
478+
----- stdout -----
479+
480+
----- stderr -----
481+
error: Expected an `__init__.py` at: `src/Django_plugin/__init__.py`
482+
"###);
469483

470484
// Use `Django_plugin` instead of `django_plugin`
471485
context
@@ -507,7 +521,7 @@ fn build_module_name_normalization() -> Result<()> {
507521
----- stderr -----
508522
");
509523

510-
// Error case 2: Multiple modules a matching name.
524+
// Error case 3: Multiple modules a matching name.
511525
// Requires a case-sensitive filesystem.
512526
#[cfg(target_os = "linux")]
513527
{

0 commit comments

Comments
 (0)