Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support modules with different casing in build backend #12240

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

konstin
Copy link
Member

@konstin konstin commented Mar 17, 2025

Match the module name to its module directory with potentially different casing.

For example, a package may have the dist-info-normalized package name pil_util, but the importable module is named PIL_util.

We get the module name either as dist-info-normalized package name, or explicitly from the user. For dist-info-normalizing a package name, the rules are lowercasing, replacing . with _ and replace - with _. Since . and - are not allowed in module names, we can check whether a directory name matches our expected module name by lowercasing it.

Fixes #12187

Match the module name to its module directory with potentially different casing.

For example, a package may have the dist-info-normalized package name `pil_util`, but the importable module is named `PIL_util`.

We get the module either as dist-info-normalized package name, or explicitly from the user.
For dist-info-normalizing a package name, the rules are lowercasing, replacing `.` with `_` and
replace `-` with `_`. Since `.` and `-` are not allowed in module names, we can check whether a
directory name matches our expected module name by lowercasing it.

Fixes #12187
@konstin konstin added the bug Something isn't working label Mar 17, 2025
let normalized = module_name.to_string();
let modules = fs_err::read_dir(src_root)?
.filter_ok(|entry| {
entry.file_name().to_string_lossy().to_lowercase() == normalized
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can probably use to_str here since if it's not Unicode it would never match, right?

[] => Err(Error::MissingModule {
module_name,
project_src: src_root.to_path_buf(),
}),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest adding an error for the case in which a matching directory exists, but there's no __init__.py file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

uv_build Error when the folder name is capitalized
2 participants