Skip to content

Fix clean hook, linter, typing errors and windows build error#3

Merged
ClemensKubach merged 12 commits into
mainfrom
fix-clean-not-working
Mar 19, 2026
Merged

Fix clean hook, linter, typing errors and windows build error#3
ClemensKubach merged 12 commits into
mainfrom
fix-clean-not-working

Conversation

@ClemensKubach

Copy link
Copy Markdown
Collaborator

No description provided.

ClemensKubach and others added 12 commits March 18, 2026 14:34
Remove the Windows branch from normalize_path so it always returns
forward slashes, consistent with the method's docstring. Input paths
from hatchling's recurse_selected_project_files() are always POSIX
format on all platforms, so the backslash conversion was unnecessary
and broke test assertions.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
TupleT, DictT, ListT, SetT, and ListStr were compat shims for pre-PEP 585
Python versions. With the minimum now at 3.10, all call sites can use
builtins directly (list[str], dict[K, V], set[T], tuple[...]). Also
cleaned up platform.py's stale __all__ and removed an unused Dict import.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
The `options` property was decorated with `@memo`, which caches results
in a closure dict keyed by `id(self)`. Python reuses memory addresses
after GC, so a fresh CythonBuildHook instance created after the build
hook was destroyed could get the same id, causing @memo to return a
stale Config without re-executing the function body — silently skipping
the `precompiled_extensions.add(".py")` side effect.

Since `compile_py=True` is the default, this caused `included_files` to
miss all .py-sourced files on the clean hook, leaving their generated
.c/.so artifacts in place. Projects that compile only .py files (no
.pyx) were fully unaffected by clean().

Fix: compute parse_from_dict() eagerly in __init__ and store as
self._options, applying precompiled_extensions side effects there.
The options property becomes a plain accessor.

Also add FileNotFoundError handling around os.remove in clean() so
that a second invocation (e.g. wheel + sdist targets) doesn't crash
when files were already removed by the first call.

Add test_clean_removes_generated_files which builds the src_structure
project, forces GC (triggering potential memo ID reuse), then calls
clean() on a fresh hook and asserts all .c/.so files are gone.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@ClemensKubach ClemensKubach merged commit 2661c81 into main Mar 19, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant