Fix build config to exclude sibling packages from distributions

Merged
MA
2mo ago
+174-32

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Description

This PR fixes the Hatch build configuration to prevent sibling workspace packages and test fixtures from being included in published wheels and sdists. The main reflex package was inadvertently shipping files from packages/ subdirectories and test golden files, bloating distributions unnecessarily.

Changes:

  1. Root pyproject.toml: Updated [tool.hatch.build] to use anchored include patterns (/reflex, /scripts/hatch_build.py) that only match at the repo root, preventing nested packages/*/src/ directories from being included. Moved the build hook to targets.sdist.include so it's only shipped in sdists (needed to build wheels from sdists), not in wheels themselves.

  2. All packages/*/pyproject.toml: Standardized artifact patterns from *.pyi (which matched anywhere) to /src/**/*.pyi (anchored to each package's root), ensuring each package only ships its own generated stubs.

  3. Tests: Added comprehensive test suite (tests/units/test_build_config.py) that validates:

    • Core reflex files are included
    • Sibling package files are excluded
    • Test fixtures are excluded
    • Build hook is only in sdists, not wheels
    • Each workspace package only ships its own stubs
  4. Documentation: Updated AGENTS.md with changelog fragment guidelines and adjusted the pre-submission checklist.

  5. Changelog: Added news fragment documenting the size reduction.

Test Plan

Added 114 lines of unit tests covering all build configuration scenarios:

  • test_build_selects_reflex_files: Verifies core reflex files are included
  • test_build_skips_files_outside_reflex: Verifies sibling packages and fixtures are excluded
  • test_build_walks_only_the_reflex_tree: Validates no unexpected files are included
  • test_sdist_ships_the_build_hook / test_wheel_omits_the_build_hook: Ensures correct hook distribution
  • test_package_ships_only_its_own_stubs: Validates each workspace package's isolation

All tests pass for both SdistBuilder and WheelBuilder.

Checklist

  • Tests pass with adequate coverage
  • uv run ruff check . and uv run ruff format . clean
  • uv run pyright reflex tests passes
  • News fragment added for user-facing changes

https://claude.ai/code/session_014sgS35XWLy5xpVZqgHXupg