Skip to content

Commit 8e933c8

Browse files
committed
issue#441: change modulename to include hash of source
This should make it work both for users and developers.
1 parent 94f650a commit 8e933c8

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

docs/install.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ everytime. Verify yourself if curious:
176176

177177
.. code-block:: sh
178178
179-
$ readelf --dynamic lib/python2.7/site-packages/pygit2-0.21.3-py2.7-linux-x86_64.egg/pygit2_cffi.so | grep PATH
179+
$ readelf --dynamic lib/python2.7/site-packages/pygit2-0.21.3-py2.7-linux-x86_64.egg/_pygit2.so | grep PATH
180180
0x000000000000001d (RUNPATH) Library runpath: [/tmp/venv/lib]
181181
182182

pygit2/_utils.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@
3131
"""
3232

3333
# Import from the Standard Library
34+
from binascii import crc32
3435
import inspect
3536
import codecs
3637
import os
3738
from os import getenv
3839
from os.path import abspath, dirname
40+
import sys
3941

4042

4143
#
@@ -72,20 +74,30 @@ def get_libgit2_paths():
7274
# Loads the cffi extension
7375
#
7476
def get_ffi():
75-
from cffi import FFI
77+
import cffi
7678

77-
ffi = FFI()
79+
ffi = cffi.FFI()
7880

7981
# Load C definitions
8082
dir_path = dirname(abspath(inspect.getfile(inspect.currentframe())))
8183
decl_path = os.path.join(dir_path, 'decl.h')
8284
with codecs.open(decl_path, 'r', 'utf-8') as header:
8385
ffi.cdef(header.read())
8486

87+
# The modulename
88+
# Simplified version of what cffi does: remove kwargs and vengine
89+
preamble = "#include <git2.h>"
90+
key = [sys.version[:3], cffi.__version__, preamble] + ffi._cdefsources
91+
key = '\x00'.join(key)
92+
if sys.version_info >= (3,):
93+
key = key.encode('utf-8')
94+
k1 = hex(crc32(key[0::2]) & 0xffffffff).lstrip('0x').rstrip('L')
95+
k2 = hex(crc32(key[1::2]) & 0xffffffff).lstrip('0').rstrip('L')
96+
modulename = 'pygit2_cffi_%s%s' % (k1, k2)
97+
8598
# Load extension module
8699
libgit2_bin, libgit2_include, libgit2_lib = get_libgit2_paths()
87-
C = ffi.verify("#include <git2.h>", modulename='pygit2_cffi',
88-
libraries=["git2"],
100+
C = ffi.verify(preamble, modulename=modulename, libraries=["git2"],
89101
include_dirs=[libgit2_include], library_dirs=[libgit2_lib])
90102

91103
# Ok

0 commit comments

Comments
 (0)