Skip to content

Commit 1ac3c10

Browse files
authoredDec 7, 2020
Update setup (#434)
* Update cythonize in setup * Set cython language_level=2 * Exclude generated .cpp files * Relax constraints for blis and numpy in pyproject.toml Remove python version constraints from blis and numpy pins in `pyproject.toml`: * `numpy` build pins for released wheels are now only maintained in `build-constraints.txt` because it is too difficult to maintain reasonable/workable constraints across architectures for sdist installs * `blis` is easier to build from source as of v0.7.4 so there's less reason to add an unnecessary restriction, which was only intended to make binary installs for python<3.6 easier * Update blis pins in requirements and setup * Update CI to prefer binary for python 2.7/3.5
1 parent 508b08f commit 1ac3c10

6 files changed

+18
-232
lines changed
 

‎MANIFEST.in

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ include buildbot.json
33
include LICENSE
44
include README.rst
55
prune tmp/
6+
recursive-exclude *.cpp

‎azure-pipelines.yml

+10-3
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,19 @@ jobs:
7272

7373
- script: |
7474
python -m pip install --upgrade pip setuptools
75-
pip install -r requirements.txt --prefer-binary
7675
displayName: 'Install dependencies'
7776
7877
- script: |
79-
pip install -e . --only-binary :all:
78+
pip install --prefer-binary -e .
79+
displayName: 'Install (python 2.7/3.5: prefer binary)'
80+
condition: or(eq(variables['python.version'], '2.7'), eq(variables['python.version'], '3.5'))
81+
82+
- script: |
83+
pip install -e .
8084
displayName: 'Install'
85+
condition: not(or(eq(variables['python.version'], '2.7'), eq(variables['python.version'], '3.5')))
8186
82-
- script: python -m pytest thinc
87+
- script: |
88+
pip install -r requirements.txt --prefer-binary
89+
python -m pytest thinc
8390
displayName: 'Run tests'

‎bin/cythonize.py

-199
This file was deleted.

‎pyproject.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ requires = [
55
"murmurhash>=0.28.0,<1.1.0",
66
"cymem>=2.0.2,<2.1.0",
77
"preshed>=1.0.1,<3.1.0",
8-
"blis>=0.4.0,<0.5.0; python_version<'3.6'",
9-
"blis>=0.4.0,<0.8.0; python_version>='3.6'",
8+
"blis>=0.4.0,<0.8.0",
109
"numpy>=1.15.0",
1110
]
1211
build-backend = "setuptools.build_meta"

‎requirements.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
murmurhash>=0.28.0,<1.1.0
33
cymem>=2.0.2,<2.1.0
44
preshed>=1.0.1,<3.1.0
5-
blis>=0.4.0,<0.5.0; python_version<'3.6'
6-
blis>=0.4.0,<0.8.0; python_version>='3.6'
5+
blis>=0.4.0,<0.8.0
76
srsly>=0.0.6,<1.1.0
87
wasabi>=0.0.9,<1.1.0
98
catalogue>=0.0.7,<1.1.0

‎setup.py

+5-26
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,16 @@
33
import io
44
import os
55
import os.path
6-
import subprocess
76
import sys
87
import contextlib
8+
from setuptools import Extension, setup
99
import distutils.util
1010
from distutils.command.build_ext import build_ext
1111
from distutils.sysconfig import get_python_inc
1212
from distutils import ccompiler, msvccompiler
13-
from distutils.ccompiler import new_compiler
14-
import platform
13+
from Cython.Build import cythonize
1514
import numpy
1615

17-
from setuptools import Extension, setup
18-
1916

2017
def is_new_osx():
2118
"""Check whether we're on OSX >= 10.10"""
@@ -83,12 +80,12 @@ def is_new_osx():
8380
# See: https://stackoverflow.com/questions/1653047/avoid-linking-to-libstdc
8481
LINK_OPTIONS["other"].append("-nodefaultlibs")
8582

83+
8684
# By subclassing build_extensions we have the actual compiler that will be used
8785
# which is really known only after finalize_options
8886
# http://stackoverflow.com/questions/724664/python-distutils-how-to-get-a-compiler-that-is-going-to-be-used
8987
class build_ext_options:
9088
def build_options(self):
91-
src_dir = os.path.join(os.path.dirname(__file__), "thinc", "_files")
9289
if hasattr(self.compiler, "initialize"):
9390
self.compiler.initialize()
9491
self.compiler.platform = sys.platform[:6]
@@ -107,16 +104,6 @@ def build_extensions(self):
107104
build_ext.build_extensions(self)
108105

109106

110-
def generate_cython(root, source):
111-
print("Cythonizing sources")
112-
p = subprocess.call(
113-
[sys.executable, os.path.join(root, "bin", "cythonize.py"), source],
114-
env=os.environ,
115-
)
116-
if p != 0:
117-
raise RuntimeError("Running cythonize failed")
118-
119-
120107
def find_in_path(name, path):
121108
"Find a file in a search path"
122109
# adapted fom http://code.activestate.com/recipes/52224-find-a-file-given-a-search-path/
@@ -127,10 +114,6 @@ def find_in_path(name, path):
127114
return None
128115

129116

130-
def is_source_release(path):
131-
return os.path.exists(os.path.join(path, "PKG-INFO"))
132-
133-
134117
def clean(path):
135118
for name in MOD_NAMES:
136119
name = name.replace(".", "/")
@@ -180,10 +163,9 @@ def setup_package():
180163

181164
ext_modules = []
182165
for mod_name in MOD_NAMES:
183-
mod_path = mod_name.replace(".", "/") + ".cpp"
184166
if mod_name.endswith("gpu_ops"):
185167
continue
186-
mod_path = mod_name.replace(".", "/") + ".cpp"
168+
mod_path = mod_name.replace(".", "/") + ".pyx"
187169
ext_modules.append(
188170
Extension(
189171
mod_name, [mod_path], language="c++", include_dirs=include_dirs
@@ -197,9 +179,6 @@ def setup_package():
197179
)
198180
)
199181

200-
if not is_source_release(root):
201-
generate_cython(root, "thinc")
202-
203182
setup(
204183
name="thinc",
205184
zip_safe=False,
@@ -213,7 +192,7 @@ def setup_package():
213192
version=about["__version__"],
214193
url=about["__uri__"],
215194
license=about["__license__"],
216-
ext_modules=ext_modules,
195+
ext_modules=cythonize(ext_modules, language_level=2),
217196
setup_requires=[
218197
"numpy>=1.15.0",
219198
"cython>=0.25",

0 commit comments

Comments
 (0)