Skip to content
Snippets Groups Projects
Commit d4d31755 authored by Donald Stufft's avatar Donald Stufft
Browse files

Merge pull request #115 from NegativeMjark/cffi_setup_fixes

Apply some of the techniques from https://caremad.io/2014/11/distribu… … …ting-a-cffi-project/
parents 52dbe2dc 1f5c04a1
Branches
Tags
No related merge requests found
...@@ -22,15 +22,20 @@ import os.path ...@@ -22,15 +22,20 @@ import os.path
import subprocess import subprocess
import sys import sys
from distutils.command.build import build
from distutils.command.build_clib import build_clib as _build_clib from distutils.command.build_clib import build_clib as _build_clib
from distutils.command.build_ext import build_ext as _build_ext from distutils.command.build_ext import build_ext as _build_ext
from setuptools import Distribution, setup from setuptools import Distribution, setup
from setuptools.command.install import install
SODIUM_MAJOR = 4 SODIUM_MAJOR = 4
SODIUM_MINOR = 5 SODIUM_MINOR = 5
CFFI_DEPENDENCY = "cffi>=0.8"
def here(*paths): def here(*paths):
return os.path.abspath(os.path.join(os.path.dirname(__file__), *paths)) return os.path.abspath(os.path.join(os.path.dirname(__file__), *paths))
...@@ -38,7 +43,7 @@ def here(*paths): ...@@ -38,7 +43,7 @@ def here(*paths):
sodium = functools.partial(here, "src/libsodium/src/libsodium") sodium = functools.partial(here, "src/libsodium/src/libsodium")
sys.path.append(here("src")) sys.path.insert(0, here("src"))
import nacl import nacl
...@@ -61,17 +66,36 @@ def which(name, flags=os.X_OK): # Taken from twisted ...@@ -61,17 +66,36 @@ def which(name, flags=os.X_OK): # Taken from twisted
return result return result
# This hack exists so that we can import nacl here def get_ext_modules():
sys.path += glob.glob("*.egg")
try:
import nacl._lib import nacl._lib
except ImportError: return [nacl._lib.ffi.verifier.get_extension()]
# installing - there is no cffi yet
ext_modules = []
else: class CFFIBuild(build):
# building bdist - cffi is here! """
ext_modules = [nacl._lib.ffi.verifier.get_extension()] This class exists, instead of just providing ``ext_modules=[...]`` directly
in ``setup()`` because importing cryptography requires we have several
packages installed first.
By doing the imports here we ensure that packages listed in
``setup_requires`` are already installed.
"""
def finalize_options(self):
self.distribution.ext_modules = get_ext_modules()
build.finalize_options(self)
class CFFIInstall(install):
"""
As a consequence of CFFIBuild and it's late addition of ext_modules, we
need the equivalent for the ``install`` command to install into platlib
install-dir rather than purelib.
"""
def finalize_options(self):
self.distribution.ext_modules = get_ext_modules()
install.finalize_options(self)
def use_system(): def use_system():
...@@ -212,12 +236,11 @@ setup( ...@@ -212,12 +236,11 @@ setup(
author=nacl.__author__, author=nacl.__author__,
author_email=nacl.__email__, author_email=nacl.__email__,
setup_requires=[ setup_requires=[
"cffi>=0.8", CFFI_DEPENDENCY
], ],
install_requires=[ install_requires=[
"cffi>=0.8", CFFI_DEPENDENCY,
"six", "six",
], ],
extras_require={ extras_require={
...@@ -234,9 +257,10 @@ setup( ...@@ -234,9 +257,10 @@ setup(
package_data={"nacl._lib": ["*.h"]}, package_data={"nacl._lib": ["*.h"]},
ext_package="nacl._lib", ext_package="nacl._lib",
ext_modules=ext_modules,
cmdclass={ cmdclass={
"build": CFFIBuild,
"install": CFFIInstall,
"build_clib": build_clib, "build_clib": build_clib,
"build_ext": build_ext, "build_ext": build_ext,
}, },
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment