github.com/whamcloud/lemur@v0.0.0-20190827193804-4655df8a52af/packaging/ci/lambda/GitPullS3/pygit2/_run.py (about)

     1  # -*- coding: utf-8 -*-
     2  #
     3  # Copyright 2010-2015 The pygit2 contributors
     4  #
     5  # This file is free software; you can redistribute it and/or modify
     6  # it under the terms of the GNU General Public License, version 2,
     7  # as published by the Free Software Foundation.
     8  #
     9  # In addition to the permissions in the GNU General Public License,
    10  # the authors give you unlimited permission to link the compiled
    11  # version of this file into combinations with other programs,
    12  # and to distribute those combinations without any restriction
    13  # coming from the use of this file.  (The General Public License
    14  # restrictions do apply in other respects; for example, they cover
    15  # modification of the file, and distribution when not linked into
    16  # a combined executable.)
    17  #
    18  # This file is distributed in the hope that it will be useful, but
    19  # WITHOUT ANY WARRANTY; without even the implied warranty of
    20  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    21  # General Public License for more details.
    22  #
    23  # You should have received a copy of the GNU General Public License
    24  # along with this program; see the file COPYING.  If not, write to
    25  # the Free Software Foundation, 51 Franklin Street, Fifth Floor,
    26  # Boston, MA 02110-1301, USA.
    27  
    28  """
    29  This is an special module, it provides stuff used by by pygit2 at run-time.
    30  """
    31  
    32  # Import from the Standard Library
    33  import codecs
    34  import os
    35  from os.path import abspath, dirname
    36  import sys
    37  
    38  # Import from cffi
    39  from cffi import FFI
    40  
    41  # Import from pygit2
    42  from _build import get_libgit2_paths
    43  
    44  
    45  # C_HEADER_SRC
    46  if getattr(sys, 'frozen', False):
    47      dir_path = getattr(sys, '_MEIPASS', None)
    48      if dir_path is None:
    49          dir_path = dirname(abspath(sys.executable))
    50  else:
    51      dir_path = dirname(abspath(__file__))
    52  
    53  decl_path = os.path.join(dir_path, 'decl.h')
    54  with codecs.open(decl_path, 'r', 'utf-8') as header:
    55      C_HEADER_SRC = header.read()
    56  
    57  # C_KEYWORDS
    58  libgit2_bin, libgit2_include, libgit2_lib = get_libgit2_paths()
    59  C_KEYWORDS = dict(libraries=['git2'],
    60                    library_dirs=[libgit2_lib],
    61                    include_dirs=[libgit2_include])
    62  
    63  # preamble
    64  preamble = "#include <git2.h>"
    65  
    66  # ffi
    67  ffi = FFI()
    68  set_source = getattr(ffi, 'set_source', None)
    69  if set_source is not None:
    70      set_source("pygit2._libgit2", preamble, **C_KEYWORDS)
    71  
    72  ffi.cdef(C_HEADER_SRC)
    73  
    74  
    75  if __name__ == '__main__':
    76      ffi.compile()