Skip to content

Commit c7e0979

Browse files
setup.py: exclude all test files
by using exclude feature of find_packages. py_modules are determined by new function, which recursively scans the base dir but omits the external modules. Plus remove now obselete package_data setting Signed-off-by: Konrad Weihmann <[email protected]>
1 parent 0374d7c commit c7e0979

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

Diff for: setup.py

+22-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from distutils.command.build_py import build_py as _build_py
1111
from setuptools.command.sdist import sdist as _sdist
12+
import fnmatch
1213
import os
1314
import sys
1415
from os import path
@@ -66,6 +67,24 @@ def _stamp_version(filename):
6667
print("WARNING: Couldn't find version line in file %s" % filename, file=sys.stderr)
6768

6869

70+
def build_py_modules(basedir, excludes=[]):
71+
# create list of py_modules from tree
72+
res = set()
73+
_prefix = os.path.basename(basedir)
74+
for root, _, files in os.walk(basedir):
75+
for f in files:
76+
_f, _ext = os.path.splitext(f)
77+
if _ext not in [".py"]:
78+
continue
79+
_f = os.path.join(root, _f)
80+
_f = os.path.relpath(_f, basedir)
81+
_f = "{}.{}".format(_prefix, _f.replace(os.sep, "."))
82+
if any(fnmatch.fnmatch(_f, x) for x in excludes):
83+
continue
84+
res.add(_f)
85+
return list(res)
86+
87+
6988
setup(
7089
name="GitPython",
7190
cmdclass={'build_py': build_py, 'sdist': sdist},
@@ -74,9 +93,9 @@ def _stamp_version(filename):
7493
author="Sebastian Thiel, Michael Trier",
7594
7695
url="https://github.com/gitpython-developers/GitPython",
77-
packages=find_packages('.'),
78-
py_modules=['git.' + f[:-3] for f in os.listdir('./git') if f.endswith('.py')],
79-
package_data={'git.test': ['fixtures/*']},
96+
packages=find_packages(exclude=("test.*")),
97+
include_package_data=True,
98+
py_modules=build_py_modules("./git", excludes=["git.ext.*"]),
8099
package_dir={'git': 'git'},
81100
python_requires='>=3.4',
82101
install_requires=requirements,

0 commit comments

Comments
 (0)