|
1 | 1 | #!/usr/bin/env python3 |
2 | 2 |
|
| 3 | +import sys |
3 | 4 | import re |
4 | 5 |
|
5 | 6 | from distutils.core import setup |
|
8 | 9 | find_packages, |
9 | 10 | Extension |
10 | 11 | ) |
11 | | -from Cython.Build import cythonize |
12 | | -from Cython.Distutils import build_ext |
13 | 12 |
|
14 | 13 | # Parses version number: https://stackoverflow.com/a/7071358 |
15 | 14 | VERSIONFILE = 'learn2learn/_version.py' |
|
24 | 23 | # Compile with Cython |
25 | 24 | # https://cython.readthedocs.io/en/latest/src/userguide/source_files_and_compilation.html |
26 | 25 | # https://github.com/FedericoStra/cython-package-example/blob/master/setup.py |
27 | | -include_dirs = [] |
28 | | -compiler_directives = {'language_level': 3, |
29 | | - 'embedsignature': True, |
30 | | -# 'profile': True, |
31 | | -# 'binding': True, |
32 | | -} |
| 26 | +extension_type = '.c' |
| 27 | +cmd_class = {} |
| 28 | +use_cython = 'develop' in sys.argv |
| 29 | +if use_cython: |
| 30 | + from Cython.Build import cythonize |
| 31 | + from Cython.Distutils import build_ext |
| 32 | + extension_type = '.pyx' |
| 33 | + cmd_class = {'build_ext': build_ext} |
| 34 | + |
33 | 35 | extensions = [ |
34 | 36 | Extension(name='learn2learn.data.meta_dataset', |
35 | | - sources=['learn2learn/data/meta_dataset.pyx']), |
| 37 | + sources=['learn2learn/data/meta_dataset' + extension_type]), |
36 | 38 | Extension(name='learn2learn.data.task_dataset', |
37 | | - sources=['learn2learn/data/task_dataset.pyx']), |
| 39 | + sources=['learn2learn/data/task_dataset' + extension_type]), |
38 | 40 | Extension(name='learn2learn.data.transforms', |
39 | | - sources=['learn2learn/data/transforms.pyx']), |
| 41 | + sources=['learn2learn/data/transforms' + extension_type]), |
40 | 42 | ] |
41 | 43 |
|
| 44 | +if use_cython: |
| 45 | + compiler_directives = {'language_level': 3, |
| 46 | + 'embedsignature': True, |
| 47 | + # 'profile': True, |
| 48 | + # 'binding': True, |
| 49 | + } |
| 50 | + extensions = cythonize(extensions, compiler_directives=compiler_directives) |
| 51 | + |
42 | 52 | # Installs the package |
43 | 53 | install( |
44 | 54 | name='learn2learn', |
45 | 55 | packages=find_packages(), |
46 | | - ext_modules=cythonize(extensions, compiler_directives=compiler_directives), |
47 | | - cmdclass={'build_ext': build_ext}, |
| 56 | + ext_modules=extensions, |
| 57 | + cmdclass=cmd_class, |
48 | 58 | zip_safe=False, # as per Cython docs |
49 | 59 | version=VERSION, |
50 | 60 | description='PyTorch Meta-Learning Framework for Researchers', |
|
0 commit comments