Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test files are in binary package distribution #347

Open
daskol opened this issue Apr 17, 2024 · 0 comments
Open

Test files are in binary package distribution #347

daskol opened this issue Apr 17, 2024 · 0 comments

Comments

@daskol
Copy link

daskol commented Apr 17, 2024

Test files are not filtered properly. The issue is that setuptools.find_package finds packages not modules while tests are organized as a separate modules. In order to mitigate the issue, one should filter test files manually as follows. This patch are created and tested on chex v0.1.86.

--- a/setup.py	2024-03-19 12:58:11.000000000 +0300
+++ b/setup.py	2024-04-17 15:19:33.593293889 +0300
@@ -15,8 +15,11 @@
 """Install script for setuptools."""
 
 import os
-from setuptools import find_packages
-from setuptools import setup
+from pathlib import Path
+
+from setuptools import find_packages, setup
+from setuptools.command.build_py import build_py as _build_py
+
 
 _CURRENT_DIR = os.path.dirname(os.path.abspath(__file__))
 
@@ -40,6 +43,15 @@
     ]
 
 
+class build_py(_build_py):
+
+    def find_package_modules(self, package, package_dir):
+        modules = super().find_package_modules(package, package_dir)
+        return [(pkg, mod, file)
+                for pkg, mod, file in modules
+                if not Path(file).match('**/*_test.py')]
+
+
 setup(
     name='chex',
     version=_get_version(),
@@ -51,7 +63,7 @@
     long_description_content_type='text/markdown',
     author_email='[email protected]',
     keywords='jax testing debugging python machine learning',
-    packages=find_packages(exclude=['*_test.py']),
+    packages=find_packages(),
     install_requires=_parse_requirements(
         os.path.join(_CURRENT_DIR, 'requirements', 'requirements.txt')),
     tests_require=_parse_requirements(
@@ -73,4 +85,5 @@
         'Topic :: Software Development :: Testing :: Unit',
         'Topic :: Software Development :: Libraries :: Python Modules',
     ],
+    cmdclass={'build_py': build_py},
 )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant