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

Fix the wheel target for case insensitive file systems #1080

Merged
merged 2 commits into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions backend/src/hatchling/builders/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,19 @@ def set_default_file_selection(self) -> None:
self.builder.normalize_file_name_component(self.builder.metadata.core.name),
):
if os.path.isfile(os.path.join(self.root, project_name, '__init__.py')):
self.__packages.append(project_name)
normalized_project_name = self.get_raw_fs_path_name(self.root, project_name)
self.__packages.append(normalized_project_name)
break

if os.path.isfile(os.path.join(self.root, 'src', project_name, '__init__.py')):
self.__packages.append(f'src/{project_name}')
normalized_project_name = self.get_raw_fs_path_name(os.path.join(self.root, 'src'), project_name)
self.__packages.append(f'src/{normalized_project_name}')
break

if os.path.isfile(os.path.join(self.root, f'{project_name}.py')):
self.__only_include.append(f'{project_name}.py')
module_file = f'{project_name}.py'
if os.path.isfile(os.path.join(self.root, module_file)):
normalized_project_name = self.get_raw_fs_path_name(self.root, module_file)
self.__only_include.append(module_file)
break

from glob import glob
Expand Down Expand Up @@ -344,6 +348,16 @@ def macos_max_compat(self) -> bool:

return self.__macos_max_compat

@staticmethod
def get_raw_fs_path_name(directory: str, name: str) -> str:
normalized = name.casefold()
entries = os.listdir(directory)
Copy link

@jeanas jeanas Dec 3, 2023

Choose a reason for hiding this comment

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

Friendly tip: maybe you want to limit this to platform.system() == "Darwin"? In Pygments, hatchling is ~2× faster to build a wheel than setuptools, and I suspect this is in part because it saves lots of syscalls for listdir() in our huge test/ tree. Now, the way this function is used right now, this is not very likely to matter a great deal because I'd expect the package directory not to have hundreds of files, unlike some test directories, but still...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This also applies to Windows, sure I will not do this on Linux! Before I do however, did this fix it for you?

Copy link

Choose a reason for hiding this comment

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

Yes, it seems to be working on the macOS machine I have access to.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Awesome, thank you!

for entry in entries:
if entry.casefold() == normalized:
return entry

return name # no cov


class WheelBuilder(BuilderInterface):
"""
Expand Down
1 change: 1 addition & 0 deletions docs/history/hatchling.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
- Fix parsing dependencies for environments when warnings are emitted
- Properly handle non-zero version epoch for the `standard` version scheme
- Allow using an empty string for the `sources` option to add a prefix to distribution paths
- Fix the `wheel` target for case insensitive file systems when the project metadata name does not match the directory name on disk

## [1.18.0](https://github.com/pypa/hatch/releases/tag/hatchling-v1.18.0) - 2023-06-12 ## {: #hatchling-v1.18.0 }

Expand Down
12 changes: 11 additions & 1 deletion tests/backend/builders/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def test_default(self, temp_dir):
assert builder.config.default_packages() == []
assert builder.config.default_only_include() == []

def test_raw_name_not_normalized(self, temp_dir):
def test_unnormalized_name_with_unnormalized_directory(self, temp_dir):
config = {'project': {'name': 'MyApp', 'version': '0.0.1'}}
builder = WheelBuilder(str(temp_dir), config=config)

Expand All @@ -131,6 +131,16 @@ def test_raw_name_not_normalized(self, temp_dir):

assert builder.config.default_packages() == ['src/MyApp']

def test_unnormalized_name_with_normalized_directory(self, temp_dir):
config = {'project': {'name': 'MyApp', 'version': '0.0.1'}}
builder = WheelBuilder(str(temp_dir), config=config)

src_root = temp_dir / 'src' / 'myapp' / '__init__.py'
src_root.ensure_parent_dir_exists()
src_root.touch()

assert builder.config.default_packages() == ['src/myapp']


class TestCoreMetadataConstructor:
def test_default(self, isolation):
Expand Down