From 5a586861863593a971640785c2a1c67fe076b390 Mon Sep 17 00:00:00 2001
From: Donald Stufft <donald@stufft.io>
Date: Sat, 5 Oct 2013 10:44:01 -0400
Subject: [PATCH] Updates to properly handle CFFI

---
 MANIFEST.in  |  2 +-
 nacl/nacl.py | 11 ++++++-----
 setup.py     |  4 ++--
 tox.ini      |  3 +--
 4 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/MANIFEST.in b/MANIFEST.in
index 1feebdd5..bd6f9370 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -35,4 +35,4 @@ recursive-include tests *.py
 recursive-include tests/data *
 
 # Remove CFFI files
-recursive-exclude nacl _cffi_*.c
+recursive-exclude nacl *.c
diff --git a/nacl/nacl.py b/nacl/nacl.py
index df1d3d90..afb04afe 100644
--- a/nacl/nacl.py
+++ b/nacl/nacl.py
@@ -79,11 +79,6 @@ ffi.cdef(
 ffi.verifier = Verifier(ffi,
     "#include <sodium.h>",
 
-    # We need to set a tmp directory otherwise when build_ext is run it'll get
-    # built in nacl/*.so but when ffi.verifier.load_library() is run it'll
-    # look (and ultimately build again) in nacl/__pycache__/*.so
-    tmpdir=os.path.abspath(os.path.dirname(__file__)),
-
     # We need to link to the sodium library
     libraries=["sodium"],
 
@@ -141,6 +136,12 @@ class Library(object):
         self._ffi = ffi
         self._initalized = False
 
+        # This prevents the compile_module() from being called, the module
+        # should have been compiled by setup.py
+        def _compile_module(*args, **kwargs):
+            raise RuntimeError("Cannot compile module during runtime")
+        self._ffi.verifier.compile_module = _compile_module
+
     def __getattr__(self, name):
         if not self._initalized:
             self._lib = self._ffi.verifier.load_library()
diff --git a/setup.py b/setup.py
index 3a1b2081..9787d911 100644
--- a/setup.py
+++ b/setup.py
@@ -185,7 +185,7 @@ setup(
             "include_dirs": [
                 sodium("include/sodium"),
             ],
-            "sources": map(sodium, [
+            "sources": [sodium(s) for s in [
                 "crypto_auth/crypto_auth.c",
                 "crypto_auth/hmacsha256/auth_hmacsha256_api.c",
                 "crypto_auth/hmacsha256/ref/hmac_hmacsha256.c",
@@ -312,7 +312,7 @@ setup(
                 "sodium/core.c",
                 "sodium/utils.c",
                 "sodium/version.c",
-            ]),
+            ]],
         }),
     ],
 
diff --git a/tox.ini b/tox.ini
index f9e837d8..143fb362 100644
--- a/tox.ini
+++ b/tox.ini
@@ -4,5 +4,4 @@ envlist = py26,py27,pypy,py32,py33
 [testenv]
 deps =
     pytest
-    pytest-cov
-commands = py.test --cov=nacl/
+commands = py.test
-- 
GitLab