Fix import error introduced in previous commit
This commit is contained in:
@@ -32,22 +32,49 @@ from __future__ import absolute_import
|
|||||||
import inspect
|
import inspect
|
||||||
import codecs
|
import codecs
|
||||||
import os
|
import os
|
||||||
|
from os import getenv
|
||||||
from os.path import abspath, dirname
|
from os.path import abspath, dirname
|
||||||
|
|
||||||
# Import from cffi
|
# Import from cffi
|
||||||
from cffi import FFI
|
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()
|
def init_ffi():
|
||||||
C = ffi.verify("#include <git2.h>", libraries=["git2"],
|
global C, ffi
|
||||||
include_dirs=[libgit2_include], library_dirs=[libgit2_lib])
|
|
||||||
|
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 <git2.h>", libraries=["git2"],
|
||||||
|
include_dirs=[libgit2_include], library_dirs=[libgit2_lib])
|
||||||
|
|
||||||
|
|
||||||
|
init_ffi()
|
||||||
|
@@ -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')),
|
|
||||||
)
|
|
11
setup.py
11
setup.py
@@ -47,7 +47,8 @@ import unittest
|
|||||||
# pygit2/__init__.py
|
# pygit2/__init__.py
|
||||||
sys.path.insert(0, 'pygit2')
|
sys.path.insert(0, 'pygit2')
|
||||||
from version import __version__
|
from version import __version__
|
||||||
from libgit2 import get_libgit2_paths
|
import ffi
|
||||||
|
del sys.path[0]
|
||||||
|
|
||||||
# Python 2 support
|
# Python 2 support
|
||||||
# See https://github.com/libgit2/pygit2/pull/180 for a discussion about this.
|
# See https://github.com/libgit2/pygit2/pull/180 for a discussion about this.
|
||||||
@@ -57,7 +58,7 @@ else:
|
|||||||
u = str
|
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')
|
pygit2_exts = [os.path.join('src', name) for name in os.listdir('src')
|
||||||
if name.endswith('.c')]
|
if name.endswith('.c')]
|
||||||
@@ -99,11 +100,7 @@ class CFFIBuild(build):
|
|||||||
to add cffi as an extension.
|
to add cffi as an extension.
|
||||||
"""
|
"""
|
||||||
def finalize_options(self):
|
def finalize_options(self):
|
||||||
# This ffi is pygit2.ffi due to the path trick used in the beginning
|
self.distribution.ext_modules.append(ffi.ffi.verifier.get_extension())
|
||||||
# of the file
|
|
||||||
from ffi import ffi
|
|
||||||
|
|
||||||
self.distribution.ext_modules.append(ffi.verifier.get_extension())
|
|
||||||
build.finalize_options(self)
|
build.finalize_options(self)
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user