-
Notifications
You must be signed in to change notification settings - Fork 273
Python3 support #98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Python3 support #98
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,4 @@ | ||
| include scrapely/*.pyx | ||
| include scrapely/extraction/*.pyx | ||
| include scrapely/extraction/*.pyx | ||
| include scrapely/*.c | ||
| include scrapely/extraction/*.c |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,3 @@ | ||
| numpy | ||
| w3lib | ||
| six | ||
| cython | ||
| six |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,32 @@ | ||
| #!/usr/bin/env python | ||
| import os | ||
| import platform | ||
| from setuptools import setup, find_packages | ||
| from setuptools.extension import Extension | ||
| from Cython.Build import cythonize | ||
| import numpy as np | ||
|
|
||
|
|
||
| USE_CYTHON = 'CYTHONIZE' in os.environ | ||
| IS_PYPY = platform.python_implementation() == 'PyPy' | ||
| ext = '.pyx' if USE_CYTHON else '.c' | ||
| extensions = [ | ||
| Extension("scrapely._htmlpage", | ||
| ["scrapely/_htmlpage.pyx"], | ||
| ["scrapely/_htmlpage%s" % ext], | ||
| include_dirs=[np.get_include()]), | ||
| Extension("scrapely.extraction._similarity", | ||
| ["scrapely/extraction/_similarity.pyx"], | ||
| ["scrapely/extraction/_similarity%s" % ext], | ||
| include_dirs=[np.get_include()]), | ||
| ] | ||
| if USE_CYTHON and not IS_PYPY: | ||
| from Cython.Build import cythonize | ||
| extensions = cythonize(extensions) | ||
| if IS_PYPY: | ||
| extensions = [] | ||
|
|
||
|
|
||
| setup( | ||
| name='scrapely', | ||
| version='0.12.0', | ||
| version='0.13.0b1', | ||
| license='BSD', | ||
| description='A pure-python HTML screen-scraping library', | ||
| author='Scrapy project', | ||
|
|
@@ -38,6 +48,9 @@ | |
| 'Topic :: Internet :: WWW/HTTP', | ||
| 'Topic :: Text Processing :: Markup :: HTML', | ||
| ], | ||
| install_requires=['numpy', 'w3lib', 'six', 'cython'], | ||
| ext_modules=cythonize(extensions), | ||
| install_requires=['numpy', 'w3lib', 'six'], | ||
| extras_require={ | ||
| 'speedup': ['cython'] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is it for? If an user installs
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If cython isn't installed it will build the c extension from the included |
||
| }, | ||
| ext_modules=extensions, | ||
| ) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If both IS_PYPY and USE_CYTHON are True then extensions will be cythonized, but not used. I think it makes sense to either respect USE_CYTHON in PyPy (their cpyext layer is improving, so maybe it compiles and speed is not worse), or avoid compiling the extension if IS_PYPY is True.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, it shouldn't build with Cython when using pypy. The performance when using the compiled extension is 10 times slower than without so it is better for pypy to not use the extension at this time.
PR has been updated to reflect this.