Skip to content

fix(setup.py): exclude top-level test/ from find_packages#4361

Open
Anai-Guo wants to merge 1 commit intopytorch:mainfrom
Anai-Guo:fix/exclude-top-level-test-from-find-packages
Open

fix(setup.py): exclude top-level test/ from find_packages#4361
Anai-Guo wants to merge 1 commit intopytorch:mainfrom
Anai-Guo:fix/exclude-top-level-test-from-find-packages

Conversation

@Anai-Guo
Copy link
Copy Markdown
Contributor

@Anai-Guo Anai-Guo commented May 1, 2026

Summary

Adds "test" and "test.*" to the find_packages(exclude=...) list in setup.py.

Why

The top-level test/ directory contains an __init__.py, so find_packages picks it up and pip install torchao ships a test package under site-packages/test/.... That:

  • pollutes the user's import namespace with a name as common as test
  • causes hard-to-diagnose conflicts with any other distribution that also ships a top-level test package (or with the user's own test module)

Repro (per #4360)

pip install torchao
python -c "import test, os; print(os.path.dirname(test.__file__))"
# → site-packages/test  (instead of failing or finding stdlib test)

After this fix the test package is no longer installed; the test code stays in the source tree where it belongs.

Scope

One-line change to setup.py. No runtime behavior change. No effect on torchao package contents.

Fixes #4360.

🤖 Generated with Claude Code

The top-level test/ directory contains an __init__.py and is currently
shipped under site-packages/test/, polluting the import namespace and
conflicting with any other package or local module named 'test'.

Add 'test' and 'test.*' to the existing find_packages exclude list so
that test code stays in the source tree but is not installed.

Fixes pytorch#4360
@Anai-Guo Anai-Guo requested review from jerryzh168 and vkuzo as code owners May 1, 2026 03:46
@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented May 1, 2026

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/4361

Note: Links to docs will display an error until the docs builds have been completed.

❌ 2 New Failures

As of commit eb96764 with merge base 28e6aca (image):

NEW FAILURES - The following jobs have failed:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 1, 2026
@vkuzo
Copy link
Copy Markdown
Contributor

vkuzo commented May 4, 2026

@claude can you review this PR, and also debug why did test start shipping in torchao in the first place, can you find the PR that caused this?

@claude
Copy link
Copy Markdown

claude Bot commented May 4, 2026

PR Review and Root Cause Investigation

  • Review the PR change in setup.py
  • Investigate root cause of test being shipped in torchao
  • Post final review and findings

Review of PR #4361

The change is correct and well-scoped. The one-line diff at setup.py:891:

# Before
packages=find_packages(exclude=["benchmarks", "benchmarks.*"]),

# After
packages=find_packages(exclude=["benchmarks", "benchmarks.*", "test", "test.*"]),

This correctly excludes the top-level test package and all its subpackages from the wheel. The fix follows the same pattern already used for benchmarks.

No issues found. The change is minimal, safe, and addresses a real packaging bug (namespace pollution with a common name like test).


Root Cause Investigation

Why test started shipping: The top-level test/ directory contains a test/__init__.py file (empty, 0 bytes), which makes find_packages() discover it as a Python package. Without an explicit exclusion in setup.py, it gets packaged into the wheel and installed under site-packages/test/.

Why test/__init__.py exists: Several test files use absolute imports that require test/ to be a package:

# test/prototype/pat/test_pat_proxmap.py
from test.prototype.pat.test_common import DistributedTestMixin, make_prox_kwargs

# test/prototype/moe_training/ep/test_compile.py
from test.prototype.moe_training.testing_utils import generate_split_sizes

There are 7 __init__.py files forming an import chain: test/__init__.py, test/prototype/__init__.py, test/prototype/attention/__init__.py, etc.

Which PR introduced it: Unfortunately, this CI environment uses a shallow git clone (only 2 commits available), so I cannot definitively trace back through the full history to identify the exact PR that first added test/__init__.py. I was able to confirm it pre-dates the last ~10 commits on main (going back to at least April 23, 2026). The file was likely added as part of a test directory restructuring (possibly when tests were moved from inside torchao/ to the top-level test/ directory, or when the from test. import pattern was first adopted).

To find the exact PR, you can run locally with full history:

git log --diff-filter=A --format="%H %s" -- test/__init__.py

Recommendation: This PR is good to merge as-is. As a follow-up, the team might consider converting those from test.prototype... imports to relative imports so that test/__init__.py could eventually be removed, but that's not blocking.


CI Failures

The two CI failures appear unrelated to this change:

  1. PR Label Check — missing required label (not a code issue)
  2. H100 Tests — Docker execution failure (infrastructure issue)

View job run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0.17.0 installs the top-level test/ directory: please remove it

2 participants