Skip to content

Commit 9622558

Browse files
authored
Remove Cython dependency when installing from PyPI. (#118)
* Remove cython dependency for PyPI install. * Version bump and cleaner publish. * Add comments to the publish process. * Update changelog. * Update travis. * Update getting started guide.
1 parent 83e8bc6 commit 9622558

File tree

7 files changed

+40
-18
lines changed

7 files changed

+40
-18
lines changed

.travis.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ before_install: |
4343
4444
install:
4545
- pip install -U pip && pip install --install-option="--no-cython-compile" cython
46-
- pip install --progress-bar off -r requirements.txt && pip install pycodestyle
47-
- python setup.py develop
46+
- pip install --progress-bar off -e . && pip install pycodestyle
4847
# - python -c 'import torch, torchvision; print(torch.__version__, torchvision.__version__)'
4948

5049
script:

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
### Fixed
1616

1717

18+
## v0.1.0.1
19+
20+
### Fixed
21+
22+
* Remove Cython dependency when installing from PyPI and clean up package distribution.
23+
24+
1825
## v0.1.0
1926

2027
### Added

MANIFEST.in

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
global-include *.pyx
22
global-include *.pxd
3+
global-include *.c
34
include learn2learn/**/*

Makefile

+5-2
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,8 @@ release:
5656
git push origin --tags
5757

5858
publish:
59-
python setup.py sdist
60-
twine upload --repository-url https://upload.pypi.org/legacy/ dist/*
59+
pip install -e . # Full build
60+
rm -f learn2learn/*.so # Remove .so files but leave .c files
61+
rm -f learn2learn/**/*.so
62+
python setup.py sdist # Create package
63+
twine upload --repository-url https://upload.pypi.org/legacy/ dist/* # Push to PyPI

docs/source/tutorials/getting_started.md

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ For the most update-to-date version clone the [repository](https://github.com/le
1717

1818
```pip install -e .```
1919

20+
When installing from sources, make sure that Cython is installed: `pip install cython`.
21+
2022
!!! info
2123
While learn2learn is actively used in current research projects, it is still in development.
2224
Breaking changes might occur.

learn2learn/_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.1.0'
1+
__version__ = '0.1.0.1'

setup.py

+23-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env python3
22

3+
import sys
34
import re
45

56
from distutils.core import setup
@@ -8,8 +9,6 @@
89
find_packages,
910
Extension
1011
)
11-
from Cython.Build import cythonize
12-
from Cython.Distutils import build_ext
1312

1413
# Parses version number: https://stackoverflow.com/a/7071358
1514
VERSIONFILE = 'learn2learn/_version.py'
@@ -24,27 +23,38 @@
2423
# Compile with Cython
2524
# https://cython.readthedocs.io/en/latest/src/userguide/source_files_and_compilation.html
2625
# 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+
3335
extensions = [
3436
Extension(name='learn2learn.data.meta_dataset',
35-
sources=['learn2learn/data/meta_dataset.pyx']),
37+
sources=['learn2learn/data/meta_dataset' + extension_type]),
3638
Extension(name='learn2learn.data.task_dataset',
37-
sources=['learn2learn/data/task_dataset.pyx']),
39+
sources=['learn2learn/data/task_dataset' + extension_type]),
3840
Extension(name='learn2learn.data.transforms',
39-
sources=['learn2learn/data/transforms.pyx']),
41+
sources=['learn2learn/data/transforms' + extension_type]),
4042
]
4143

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+
4252
# Installs the package
4353
install(
4454
name='learn2learn',
4555
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,
4858
zip_safe=False, # as per Cython docs
4959
version=VERSION,
5060
description='PyTorch Meta-Learning Framework for Researchers',

0 commit comments

Comments
 (0)