Skip to content
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

Allow to install the library on systems without compilation toolset #281

Merged
merged 13 commits into from Sep 7, 2018
1 change: 1 addition & 0 deletions .appveyor.yml
Expand Up @@ -17,6 +17,7 @@ environment:

install:
- "tools/build.cmd %PYTHON%\\python.exe -m pip install -U tox"
- DEL /S /F /Q ".git"
- "tools/build.cmd %PYTHON%\\python.exe -m tox --notest" # Pre-populate a virtualenv with dependencies

build_script:
Expand Down
2 changes: 2 additions & 0 deletions .circleci/config.yml
Expand Up @@ -33,6 +33,7 @@ jobs:

- run: pip install tox tox-pyenv
- checkout
- run: rm -rf .git
- run: tox -e py34,py35,py36,py37,pypy3 -- -p no:sugar

linux-build:
Expand All @@ -41,6 +42,7 @@ jobs:

steps:
- checkout
- run: rm -rf .git
- run: pip install tox
- run: tox -e py34,py35,py36,py37

Expand Down
4 changes: 4 additions & 0 deletions .travis.yml
Expand Up @@ -183,21 +183,25 @@ jobs:
- <<: *_doc_base
name: Documentation linting
env:
<<: *env_extensions_disabled
TOXENV: doc-spelling

- <<: *_lint_base
name: Flake8 linter
env:
<<: *env_extensions_disabled
TOXENV: flake8

- <<: *_lint_base
name: MyPy linter
env:
<<: *env_extensions_disabled
TOXENV: mypy

- <<: *_lint_base
name: dist setup check
env:
<<: *env_extensions_disabled
TOXENV: setup-check

- <<: *osx_python_base
Expand Down
1 change: 0 additions & 1 deletion requirements/ci.txt
Expand Up @@ -6,7 +6,6 @@ sphinx==1.7.8
alabaster>=0.6.2
pygments==2.2.0
mypy==0.620; platform_python_implementation != "PyPy"
-e .

codecov==2.0.15

Expand Down
49 changes: 39 additions & 10 deletions setup.py
@@ -1,4 +1,5 @@
import codecs
import pathlib
from itertools import islice
import os
import platform
Expand All @@ -9,24 +10,53 @@
DistutilsPlatformError)
from distutils.command.build_ext import build_ext

try:
from Cython.Build import cythonize
USE_CYTHON = True
except ImportError:
USE_CYTHON = False


PROFILE_BUILD = bool(os.environ.get('PROFILE_BUILD'))
"""Flag whether extensions should be built with profiling enabled."""

NO_EXTENSIONS = bool(os.environ.get('MULTIDICT_NO_EXTENSIONS'))
"""Flag whether extensions building/usage should be skipped."""

PYPY = platform.python_implementation() == 'PyPy'
"""Flag whether we are in PyPy runtime."""

USE_CYTHON_EXTENSIONS = not NO_EXTENSIONS and not PYPY
"""Flag whether prerequisites for building extensions are met."""

here = pathlib.Path(__file__).parent
"""Current folder (containing setup.py)."""

IS_GIT_REPO = (here / '.git').exists()
"""Flag whether we are in Git repo."""

ignore_compile_excs = (
() if USE_CYTHON_EXTENSIONS and IS_GIT_REPO
else (CCompilerError, )
) + (DistutilsExecError, DistutilsPlatformError, ValueError)
"""Exceptions to ignore during compilation."""

# Fallbacks for PyPy: don't use C extensions
extensions = []
cmdclass = {}

if not PYPY:
try:
from Cython.Build import cythonize
USE_CYTHON = True
except ImportError:
USE_CYTHON = False
if USE_CYTHON_EXTENSIONS:

if IS_GIT_REPO and not USE_CYTHON:
print("Install cython when building from git clone",
file=sys.stderr)
print("Hint:", file=sys.stderr)
print(" pip install cython", file=sys.stderr)
sys.exit(1)

ext = '.pyx' if USE_CYTHON else '.c'

if bool(os.environ.get('PROFILE_BUILD')):
if PROFILE_BUILD:
macros = [('CYTHON_TRACE', '1')]
else:
macros = []
Expand All @@ -50,7 +80,7 @@
]

if USE_CYTHON:
if bool(os.environ.get('PROFILE_BUILD')):
if PROFILE_BUILD:
directives = {"linetrace": True}
else:
directives = {}
Expand All @@ -74,8 +104,7 @@ def run(self):
def build_extension(self, ext):
try:
build_ext.build_extension(self, ext)
except (DistutilsExecError,
DistutilsPlatformError, ValueError):
except ignore_compile_excs:
raise BuildFailed()

cmdclass['build_ext'] = ve_build_ext
Expand Down
5 changes: 5 additions & 0 deletions shippable.yml
Expand Up @@ -12,4 +12,9 @@ env:
build:
ci:
- pip install -U tox
- |
if [ -z "$MULTIDICT_NO_EXTENSIONS" ]
then
rm -rf .git
fi
- python -m tox