Skip to content

chore: exclude test_ files from published package#2706

Open
paul-nechifor wants to merge 1 commit into
mainfrom
paul/chore/do-not-ship-test-code
Open

chore: exclude test_ files from published package#2706
paul-nechifor wants to merge 1 commit into
mainfrom
paul/chore/do-not-ship-test-code

Conversation

@paul-nechifor

Copy link
Copy Markdown
Contributor

Problem

We ship a lot of test_*.py files. They are useless for the users.

Closes DIM-539

Solution

Don't include them.

@greptile-apps

greptile-apps Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR excludes test_*.py and conftest.py files from the published package by updating both MANIFEST.in (for source distributions) and setup.py (for wheels), using a two-pronged approach that covers all distribution formats.

  • MANIFEST.in: Adds two global-exclude directives that strip test and conftest files from sdist archives.
  • setup.py: Introduces a build_py subclass overriding find_package_modules to filter test files during wheel builds using fnmatch, then registers it via cmdclass.

Confidence Score: 5/5

Safe to merge — the change only affects which files are bundled into the published package, with no impact on runtime behaviour or source code logic.

Both distribution paths (sdist via MANIFEST.in and wheel via the build_py override) are handled correctly. The fnmatch filter operates on the filename only via os.path.basename, the superclass call is properly chained, and the patterns (test_*.py, conftest.py) precisely target only test artefacts. No production modules are at risk of being accidentally excluded.

No files require special attention.

Important Files Changed

Filename Overview
MANIFEST.in Adds global-exclude test_*.py and global-exclude conftest.py to prevent test files from being included in the source distribution (sdist).
setup.py Adds a custom build_py subclass that overrides find_package_modules to filter out test files during wheel builds, complementing the MANIFEST.in change for sdist.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[pip install / build] --> B{Distribution type?}
    B -->|sdist| C[MANIFEST.in processed]
    B -->|wheel| D[setup.py build_py invoked]

    C --> E["global-exclude test_*.py\nglobal-exclude conftest.py"]
    E --> F[Test files removed from sdist]

    D --> G["build_py.find_package_modules()"]
    G --> H["super().find_package_modules()"]
    H --> I[All .py modules found]
    I --> J{"fnmatch: matches\ntest_*.py or conftest.py?"}
    J -->|Yes| K[Excluded from wheel]
    J -->|No| L[Included in wheel]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[pip install / build] --> B{Distribution type?}
    B -->|sdist| C[MANIFEST.in processed]
    B -->|wheel| D[setup.py build_py invoked]

    C --> E["global-exclude test_*.py\nglobal-exclude conftest.py"]
    E --> F[Test files removed from sdist]

    D --> G["build_py.find_package_modules()"]
    G --> H["super().find_package_modules()"]
    H --> I[All .py modules found]
    I --> J{"fnmatch: matches\ntest_*.py or conftest.py?"}
    J -->|Yes| K[Excluded from wheel]
    J -->|No| L[Included in wheel]
Loading

Reviews (1): Last reviewed commit: "chore: exclude test_ files from publishe..." | Re-trigger Greptile

@codecov

codecov Bot commented Jul 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

@@           Coverage Diff           @@
##             main    #2706   +/-   ##
=======================================
  Coverage   72.04%   72.04%           
=======================================
  Files         893      893           
  Lines       80728    80728           
  Branches     7310     7310           
=======================================
  Hits        58163    58163           
  Misses      20614    20614           
  Partials     1951     1951           
Flag Coverage Δ
OS-ubuntu-24.04-arm 64.13% <ø> (-0.01%) ⬇️
OS-ubuntu-latest 66.82% <ø> (ø)
Py-3.10 66.81% <ø> (+<0.01%) ⬆️
Py-3.11 66.81% <ø> (-0.01%) ⬇️
Py-3.12 66.81% <ø> (-0.01%) ⬇️
Py-3.13 66.81% <ø> (-0.01%) ⬇️
Py-3.14 66.83% <ø> (+<0.01%) ⬆️
Py-3.14t 66.82% <ø> (+0.01%) ⬆️
SelfHosted-Large 30.14% <ø> (ø)
SelfHosted-Linux 37.99% <ø> (+<0.01%) ⬆️
SelfHosted-macOS 36.31% <ø> (+0.03%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions github-actions Bot added the ready-to-merge Required CI checks have passed on this PR label Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-merge Required CI checks have passed on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant