|
| 1 | +# coding: utf-8 |
| 2 | +import os |
| 3 | +import fnmatch |
| 4 | +import sysconfig |
| 5 | +from setuptools import setup, find_packages |
| 6 | +from setuptools.command.build_py import build_py as _build_py |
| 7 | +from Cython.Build import cythonize |
| 8 | + |
| 9 | +EXCLUDE_FILES = [ |
| 10 | + 'tslearn/main.py' |
| 11 | +] |
| 12 | + |
| 13 | + |
| 14 | +def get_ext_paths(root_dir, exclude_files): |
| 15 | + """get filepaths for compilation""" |
| 16 | + paths = [] |
| 17 | + |
| 18 | + for root, dirs, files in os.walk(root_dir): |
| 19 | + for filename in files: |
| 20 | + if os.path.splitext(filename)[1] != '.py': |
| 21 | + continue |
| 22 | + |
| 23 | + file_path = os.path.join(root, filename) |
| 24 | + if file_path in exclude_files: |
| 25 | + continue |
| 26 | + |
| 27 | + paths.append(file_path) |
| 28 | + return paths |
| 29 | + |
| 30 | + |
| 31 | +class build_py(_build_py): |
| 32 | + |
| 33 | + def find_package_modules(self, package, package_dir): |
| 34 | + ext_suffix = sysconfig.get_config_var('EXT_SUFFIX') |
| 35 | + modules = super().find_package_modules(package, package_dir) |
| 36 | + filtered_modules = [] |
| 37 | + for (pkg, mod, filepath) in modules: |
| 38 | + if os.path.exists(filepath.replace('.py', ext_suffix)): |
| 39 | + continue |
| 40 | + filtered_modules.append((pkg, mod, filepath, )) |
| 41 | + return filtered_modules |
| 42 | + |
| 43 | + |
| 44 | +setup( |
| 45 | + name='tslearn', |
| 46 | + version='0.0.0', |
| 47 | + packages=find_packages(), |
| 48 | + ext_modules=cythonize( |
| 49 | + get_ext_paths('tslearn', EXCLUDE_FILES), |
| 50 | + compiler_directives={'language_level': 3} |
| 51 | + ), |
| 52 | + cmdclass={ |
| 53 | + 'build_py':build_py |
| 54 | + } |
| 55 | +) |
| 56 | + |
| 57 | +# to compile working directory to wheel |
| 58 | +#$ python setup.py bdist_wheel |
| 59 | +#$ unzip tslearn-0.0.0-cp38-cp38-linux_x86_64.whl |
0 commit comments