Fix (again) the chicken-and-egg problem with cffi
Broken with previous commits :)
This commit is contained in:
		| @@ -41,7 +41,7 @@ from .remote import Remote, get_credentials | ||||
| from .repository import Repository | ||||
| from .settings import Settings | ||||
| from .utils import to_bytes | ||||
| from .version import __version__ | ||||
| from ._utils import __version__ | ||||
|  | ||||
|  | ||||
| def init_repository(path, bare=False, | ||||
|   | ||||
							
								
								
									
										92
									
								
								pygit2/_utils.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										92
									
								
								pygit2/_utils.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,92 @@ | ||||
| # -*- coding: utf-8 -*- | ||||
| # | ||||
| # 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. | ||||
|  | ||||
| """ | ||||
| This is an special module, it provides stuff used by setup.py and by | ||||
| pygit2 at run-time. | ||||
| """ | ||||
|  | ||||
| # Import from the Standard Library | ||||
| import inspect | ||||
| import codecs | ||||
| import os | ||||
| from os import getenv | ||||
| from os.path import abspath, dirname | ||||
|  | ||||
|  | ||||
| # | ||||
| # The version number of pygit2 | ||||
| # | ||||
| __version__ = '0.21.3' | ||||
|  | ||||
|  | ||||
| # | ||||
| # Utility functions to get the paths required for bulding extensions | ||||
| # | ||||
| 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')), | ||||
|     ) | ||||
|  | ||||
|  | ||||
| # | ||||
| # Loads the cffi extension | ||||
| # | ||||
| def get_ffi(): | ||||
|     from cffi import 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 <git2.h>", modulename='pygit2_cffi', | ||||
|                    libraries=["git2"], | ||||
|                    include_dirs=[libgit2_include], library_dirs=[libgit2_lib]) | ||||
|  | ||||
|     # Ok | ||||
|     return ffi, C | ||||
| @@ -28,54 +28,8 @@ | ||||
| # Import from the future | ||||
| from __future__ import absolute_import | ||||
|  | ||||
| # Import from the Standard Library | ||||
| 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 ._utils import get_ffi | ||||
|  | ||||
|  | ||||
| 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')), | ||||
|     ) | ||||
|  | ||||
|  | ||||
| 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 <git2.h>", modulename='pygit2_cffi', | ||||
|                    libraries=["git2"], | ||||
|                    include_dirs=[libgit2_include], library_dirs=[libgit2_lib]) | ||||
|  | ||||
|  | ||||
| init_ffi() | ||||
| ffi, C = get_ffi() | ||||
|   | ||||
| @@ -1,26 +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. | ||||
|  | ||||
| __version__ = '0.21.3' | ||||
							
								
								
									
										11
									
								
								setup.py
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								setup.py
									
									
									
									
									
								
							| @@ -43,11 +43,9 @@ from subprocess import Popen, PIPE | ||||
| import sys | ||||
| import unittest | ||||
|  | ||||
| # Read version from local pygit2/version.py without pulling in | ||||
| # pygit2/__init__.py | ||||
| # Import stuff from pygit2/_utils.py without loading the whole pygit2 package | ||||
| sys.path.insert(0, 'pygit2') | ||||
| from version import __version__ | ||||
| import ffi | ||||
| from _utils import __version__, get_libgit2_paths, get_ffi | ||||
| del sys.path[0] | ||||
|  | ||||
| # Python 2 support | ||||
| @@ -58,7 +56,7 @@ else: | ||||
|     u = str | ||||
|  | ||||
|  | ||||
| libgit2_bin, libgit2_include, libgit2_lib = ffi.get_libgit2_paths() | ||||
| libgit2_bin, libgit2_include, libgit2_lib = get_libgit2_paths() | ||||
|  | ||||
| pygit2_exts = [os.path.join('src', name) for name in os.listdir('src') | ||||
|                if name.endswith('.c')] | ||||
| @@ -100,7 +98,8 @@ class CFFIBuild(build): | ||||
|     to add cffi as an extension. | ||||
|     """ | ||||
|     def finalize_options(self): | ||||
|         self.distribution.ext_modules.append(ffi.ffi.verifier.get_extension()) | ||||
|         ffi, C = get_ffi() | ||||
|         self.distribution.ext_modules.append(ffi.verifier.get_extension()) | ||||
|         build.finalize_options(self) | ||||
|  | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 J. David Ibáñez
					J. David Ibáñez