Repository navigation
Conversation
find_packages() without arguments also finds tests/, so the 2.1.1 wheel installs a top-level `tests` package into site-packages. That regular package shadows a project's own `tests` namespace package. Limit find_packages() to textfsm and its subpackages. The sdist still gets tests/ and testdata/ through MANIFEST.in. Fixes google#155
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I started from #155 and checked it against the code.
c236a53 changed
packages=['textfsm']topackages=find_packages(). With no arguments,find_packages()also picks uptests/, since it has an__init__.py, so the 2.1.1 wheel installs a top-leveltestspackage next totextfsm. A regular package wins over a namespace package of the same name wherever each one sits onsys.path. A project whose owntests/has no__init__.pythen can't import from it once textfsm 2.1.1 is installed.This keeps
find_packages()and limits it totextfsmand its subpackages, as the issue suggests.How I found it
I followed the
setup.pyhistory from the issue to c236a53. Then I built wheels fromv2.1.0, currentmasterand this branch and listed their top-level entries. To check the import side, I installed themasterwheel into a fresh venv and used it from a small project that hastests/foo.pyand notests/__init__.py.Where this can show up in practice
tests/as a namespace package and imports helpers asfrom tests.helpers import .... A dependency update that pulls in textfsm 2.1.1 (netmiko does) breaks test collection withModuleNotFoundError: No module named 'tests.helpers', with no change in the project itself. This is the case 2.1.1 wheel installs a top-leveltestspackage into site-packages, shadowing users' owntestspackages #155 reports.testspackage. They write into the samesite-packages/tests/, and uninstalling one of them removes files the other one put there.The second one is my estimate; I have not seen a field report.
What changes
setup.pyonly:find_packages()becomesfind_packages(include=['textfsm', 'textfsm.*']). The sdist doesn't change.MANIFEST.instill addstests/andtestdata/to it, which is what packagers asked for in #50.I left
package_data={'textfsm': ['../testdata/*']}alone. It also puts a top-leveltestdata/into site-packages, as the issue notes, but that was already the case in 2.1.0 and isn't part of this regression.Testing
v2.1.0testdata/,textfsm/,textfsm-2.1.0.dist-info/master(7e4ed59)testdata/,tests/,textfsm/,textfsm-2.1.1.dist-info/testdata/,textfsm/,textfsm-2.1.1.dist-info/textfsm/has the same five modules in all three.With the
masterwheel installed,from tests.foo import barin the small project fails withModuleNotFoundError: No module named 'tests.foo', andimport testsresolves tosite-packages/tests/__init__.py. With the wheel from this branch the import works, and the installedtextfsm --helpstill runs.pytest testspasses (113) on Python 3.9 and 3.11. The sdist from this branch still containstests/,testdata/andexamples/.If you check this locally, build from a clean tree: a
build/lib/tests/left over from an earlier build ends up in the wheel again.I ran this on macOS only. I didn't run the publish workflow or upload to TestPyPI. I didn't add a test, since the repo has no packaging tests.
Fixes #155