From 93dd5450690f24d078a88bbc9cf8cd652159fd24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20David=20Ib=C3=A1=C3=B1ez?= Date: Wed, 29 Oct 2014 12:05:19 +0100 Subject: [PATCH] Fix import error introduced in previous commit --- pygit2/ffi.py | 47 +++++++++++++++++++++++++++++++++++---------- pygit2/libgit2.py | 49 ----------------------------------------------- setup.py | 11 ++++------- 3 files changed, 41 insertions(+), 66 deletions(-) delete mode 100644 pygit2/libgit2.py diff --git a/pygit2/ffi.py b/pygit2/ffi.py index e61fa2c..c51791c 100644 --- a/pygit2/ffi.py +++ b/pygit2/ffi.py @@ -32,22 +32,49 @@ from __future__ import absolute_import import inspect import codecs import os +from os import getenv from os.path import abspath, dirname # Import from cffi from cffi import FFI -# Import from pygit2 -from libgit2 import get_libgit2_paths + +def _get_libgit2_path(): + # LIBGIT2 environment variable takes precedence + libgit2_path = getenv("LIBGIT2") + if libgit2_path is not None: + return libgit2_path + + # Default + if os.name == 'nt': + return '%s\libgit2' % getenv("ProgramFiles") + return '/usr/local' -ffi = FFI() +def get_libgit2_paths(): + libgit2_path = _get_libgit2_path() + return ( + os.path.join(libgit2_path, 'bin'), + os.path.join(libgit2_path, 'include'), + getenv('LIBGIT2_LIB', os.path.join(libgit2_path, 'lib')), + ) -dir_path = dirname(abspath(inspect.getfile(inspect.currentframe()))) -decl_path = os.path.join(dir_path, 'decl.h') -with codecs.open(decl_path, 'r', 'utf-8') as header: - ffi.cdef(header.read()) -libgit2_bin, libgit2_include, libgit2_lib = get_libgit2_paths() -C = ffi.verify("#include ", libraries=["git2"], - include_dirs=[libgit2_include], library_dirs=[libgit2_lib]) +def init_ffi(): + global C, ffi + + ffi = FFI() + + # Load C definitions + dir_path = dirname(abspath(inspect.getfile(inspect.currentframe()))) + decl_path = os.path.join(dir_path, 'decl.h') + with codecs.open(decl_path, 'r', 'utf-8') as header: + ffi.cdef(header.read()) + + # Load extension module + libgit2_bin, libgit2_include, libgit2_lib = get_libgit2_paths() + C = ffi.verify("#include ", libraries=["git2"], + include_dirs=[libgit2_include], library_dirs=[libgit2_lib]) + + +init_ffi() diff --git a/pygit2/libgit2.py b/pygit2/libgit2.py deleted file mode 100644 index f8a4178..0000000 --- a/pygit2/libgit2.py +++ /dev/null @@ -1,49 +0,0 @@ -# Copyright 2010-2014 The pygit2 contributors -# -# This file is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License, version 2, -# as published by the Free Software Foundation. -# -# In addition to the permissions in the GNU General Public License, -# the authors give you unlimited permission to link the compiled -# version of this file into combinations with other programs, -# and to distribute those combinations without any restriction -# coming from the use of this file. (The General Public License -# restrictions do apply in other respects; for example, they cover -# modification of the file, and distribution when not linked into -# a combined executable.) -# -# This file is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; see the file COPYING. If not, write to -# the Free Software Foundation, 51 Franklin Street, Fifth Floor, -# Boston, MA 02110-1301, USA. - -# Import from the Standard Library -from os import getenv -import os - - -def _get_libgit2_path(): - # LIBGIT2 environment variable takes precedence - libgit2_path = getenv("LIBGIT2") - if libgit2_path is not None: - return libgit2_path - - # Default - if os.name == 'nt': - return '%s\libgit2' % getenv("ProgramFiles") - return '/usr/local' - - -def get_libgit2_paths(): - libgit2_path = _get_libgit2_path() - return ( - os.path.join(libgit2_path, 'bin'), - os.path.join(libgit2_path, 'include'), - getenv('LIBGIT2_LIB', os.path.join(libgit2_path, 'lib')), - ) diff --git a/setup.py b/setup.py index 210e922..2b328b6 100644 --- a/setup.py +++ b/setup.py @@ -47,7 +47,8 @@ import unittest # pygit2/__init__.py sys.path.insert(0, 'pygit2') from version import __version__ -from libgit2 import get_libgit2_paths +import ffi +del sys.path[0] # Python 2 support # See https://github.com/libgit2/pygit2/pull/180 for a discussion about this. @@ -57,7 +58,7 @@ else: u = str -libgit2_bin, libgit2_include, libgit2_lib = get_libgit2_paths() +libgit2_bin, libgit2_include, libgit2_lib = ffi.get_libgit2_paths() pygit2_exts = [os.path.join('src', name) for name in os.listdir('src') if name.endswith('.c')] @@ -99,11 +100,7 @@ class CFFIBuild(build): to add cffi as an extension. """ def finalize_options(self): - # This ffi is pygit2.ffi due to the path trick used in the beginning - # of the file - from ffi import ffi - - self.distribution.ext_modules.append(ffi.verifier.get_extension()) + self.distribution.ext_modules.append(ffi.ffi.verifier.get_extension()) build.finalize_options(self)