Skip to content

Commit 2f537b5

Browse files
committed
Add C files and use Cython for package setup
1 parent 4769783 commit 2f537b5

File tree

4 files changed

+17
-10
lines changed

4 files changed

+17
-10
lines changed

.travis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ env:
88

99
install:
1010
- pip install cython
11-
- pip install -U tox codecov
12-
11+
- CYTHONIZE=1 python setup.py build
12+
- pip install -U tox
1313
script: tox
1414

1515
after_success:

MANIFEST.in

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
include scrapely/*.pyx
2-
include scrapely/extraction/*.pyx
2+
include scrapely/extraction/*.pyx
3+
include scrapely/*.c
4+
include scrapely/extraction/*.c

requirements.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
numpy
22
w3lib
3-
six
4-
cython
3+
six

setup.py

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
#!/usr/bin/env python
2+
import os
23
from setuptools import setup, find_packages
34
from setuptools.extension import Extension
4-
from Cython.Build import cythonize
55
import numpy as np
66

7+
8+
USE_CYTHON = 'CYTHONIZE' in os.environ
9+
ext = '.pyx' if USE_CYTHON else '.c'
710
extensions = [
811
Extension("scrapely._htmlpage",
9-
["scrapely/_htmlpage.pyx"],
12+
["scrapely/_htmlpage%s" % ext],
1013
include_dirs=[np.get_include()]),
1114
Extension("scrapely.extraction._similarity",
12-
["scrapely/extraction/_similarity.pyx"],
15+
["scrapely/extraction/_similarity%s" % ext],
1316
include_dirs=[np.get_include()]),
1417
]
18+
if USE_CYTHON:
19+
from Cython.Build import cythonize
20+
extensions = cythonize(extensions)
1521

1622

1723
setup(
@@ -38,6 +44,6 @@
3844
'Topic :: Internet :: WWW/HTTP',
3945
'Topic :: Text Processing :: Markup :: HTML',
4046
],
41-
install_requires=['numpy', 'w3lib', 'six', 'cython'],
42-
ext_modules=cythonize(extensions),
47+
install_requires=['numpy', 'w3lib', 'six'],
48+
ext_modules=extensions,
4349
)

0 commit comments

Comments
 (0)