Skip to content

chore: exclude test packages from wheel distributions #804

@hartym

Description

@hartym

Branch: feat/804-exclude-tests-from-wheels

Summary

Test packages and testing utilities are currently being included in the wheel distribution, accounting for 23.5% (567KB of 2.4MB) of the package size. This unnecessarily increases the distribution size and exposes internal testing code to end users. The wheel should only contain production code needed to run HARP.

Context

HARP uses Hatchling as its build backend, configured in pyproject.toml. The current wheel build configuration includes entire harp and harp_apps directories without excluding test-related files:

  • Test directories found: 132 test-related files across multiple locations

    • */tests/ directories in harp and harp_apps modules
    • harp/utils/testing/ and harp_apps/storage/utils/testing/ utility modules
    • Test fixtures, snapshots, and conftest.py files
  • Impact: Increases wheel size by ~567KB (23.5% of total)

  • Security consideration: Exposes internal testing utilities and fixtures

The testing utilities in harp.utils.testing are only used internally for HARP development and are not needed by end users or plugin developers.

Input

Current pyproject.toml wheel configuration:

[tool.hatch.build.targets.wheel]
include = [
    "harp",
    "harp_apps",
]
exclude = [
    "**/node_modules/",
    "harp_apps/dashboard/frontend",
]

Output and Testing Scenarios

Expected Output:

  • Wheel package contains only production code
  • Wheel size reduced by approximately 567KB
  • No test files or testing utilities in the distribution

Testing Scenarios:

  1. Happy Path: Build wheel, verify no test files included, install and run HARP successfully
  2. Package integrity: Verify all production code still included and functional
  3. Developer experience: Confirm tests still run correctly from source checkout

Possible Implementation

Add exclude patterns to pyproject.toml for the wheel target:

[tool.hatch.build.targets.wheel]
include = [
    "harp",
    "harp_apps",
]
exclude = [
    "**/node_modules/",
    "harp_apps/dashboard/frontend",
    "**/tests/",
    "**/test_*.py", 
    "**/*_test.py",
    "**/testing/",
    "**/conftest.py",
    "**/__pycache__/",
    "**/*.pyc",
    "**/__snapshots__/",
]

This approach:

  • Uses glob patterns to exclude all test-related directories and files
  • Maintains the simple include/exclude structure
  • Covers all common test file naming conventions
  • Also excludes Python cache files for cleaner distributions

Current Challenges

  • Need to verify that all test patterns are covered
  • Must ensure no production code is accidentally excluded
  • Should validate that the wheel still installs and functions correctly after exclusion

Metadata

Metadata

Assignees

No one assigned

    Labels

    InfrapythonPull requests that update Python code

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions