setup: minor cleanup
This commit is contained in:
27
setup.py
27
setup.py
@@ -37,6 +37,8 @@ from distutils.command.build import build
|
|||||||
from distutils.command.sdist import sdist
|
from distutils.command.sdist import sdist
|
||||||
from distutils import log
|
from distutils import log
|
||||||
import os
|
import os
|
||||||
|
from os import getenv, listdir, pathsep
|
||||||
|
from os.path import abspath, isfile
|
||||||
from setuptools import setup, Extension, Command
|
from setuptools import setup, Extension, Command
|
||||||
import shlex
|
import shlex
|
||||||
from subprocess import Popen, PIPE
|
from subprocess import Popen, PIPE
|
||||||
@@ -58,7 +60,7 @@ else:
|
|||||||
|
|
||||||
libgit2_bin, libgit2_include, libgit2_lib = 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')
|
pygit2_exts = [os.path.join('src', name) for name in listdir('src')
|
||||||
if name.endswith('.c')]
|
if name.endswith('.c')]
|
||||||
|
|
||||||
|
|
||||||
@@ -71,7 +73,6 @@ class TestCommand(Command):
|
|||||||
|
|
||||||
def initialize_options(self):
|
def initialize_options(self):
|
||||||
self.args = ''
|
self.args = ''
|
||||||
pass
|
|
||||||
|
|
||||||
def finalize_options(self):
|
def finalize_options(self):
|
||||||
pass
|
pass
|
||||||
@@ -80,7 +81,7 @@ class TestCommand(Command):
|
|||||||
self.run_command('build')
|
self.run_command('build')
|
||||||
bld = self.distribution.get_command_obj('build')
|
bld = self.distribution.get_command_obj('build')
|
||||||
# Add build_lib in to sys.path so that unittest can found DLLs and libs
|
# Add build_lib in to sys.path so that unittest can found DLLs and libs
|
||||||
sys.path = [os.path.abspath(bld.build_lib)] + sys.path
|
sys.path = [abspath(bld.build_lib)] + sys.path
|
||||||
|
|
||||||
test_argv0 = [sys.argv[0] + ' test --args=']
|
test_argv0 = [sys.argv[0] + ' test --args=']
|
||||||
# For transfering args to unittest, we have to split args by ourself,
|
# For transfering args to unittest, we have to split args by ourself,
|
||||||
@@ -93,6 +94,7 @@ class TestCommand(Command):
|
|||||||
test_argv = test_argv0 + shlex.split(self.args)
|
test_argv = test_argv0 + shlex.split(self.args)
|
||||||
unittest.main(None, defaultTest='test.test_suite', argv=test_argv)
|
unittest.main(None, defaultTest='test.test_suite', argv=test_argv)
|
||||||
|
|
||||||
|
|
||||||
class CFFIBuild(build):
|
class CFFIBuild(build):
|
||||||
"""Hack to combat the chicken and egg problem that we need cffi
|
"""Hack to combat the chicken and egg problem that we need cffi
|
||||||
to add cffi as an extension.
|
to add cffi as an extension.
|
||||||
@@ -116,12 +118,12 @@ class BuildWithDLLs(CFFIBuild):
|
|||||||
libgit2_dlls.append('git2.dll')
|
libgit2_dlls.append('git2.dll')
|
||||||
elif compiler_type == 'mingw32':
|
elif compiler_type == 'mingw32':
|
||||||
libgit2_dlls.append('libgit2.dll')
|
libgit2_dlls.append('libgit2.dll')
|
||||||
look_dirs = [libgit2_bin] + os.getenv("PATH", "").split(os.pathsep)
|
look_dirs = [libgit2_bin] + getenv("PATH", "").split(pathsep)
|
||||||
target = os.path.abspath(self.build_lib)
|
target = abspath(self.build_lib)
|
||||||
for bin in libgit2_dlls:
|
for bin in libgit2_dlls:
|
||||||
for look in look_dirs:
|
for look in look_dirs:
|
||||||
f = os.path.join(look, bin)
|
f = os.path.join(look, bin)
|
||||||
if os.path.isfile(f):
|
if isfile(f):
|
||||||
ret.append((f, target))
|
ret.append((f, target))
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
@@ -131,7 +133,6 @@ class BuildWithDLLs(CFFIBuild):
|
|||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
build.run(self)
|
build.run(self)
|
||||||
if os.name == 'nt':
|
|
||||||
# On Windows we package up the dlls with the plugin.
|
# On Windows we package up the dlls with the plugin.
|
||||||
for s, d in self._get_dlls():
|
for s, d in self._get_dlls():
|
||||||
self.copy_file(s, d)
|
self.copy_file(s, d)
|
||||||
@@ -167,16 +168,10 @@ with codecs.open('README.rst', 'r', 'utf-8') as readme:
|
|||||||
|
|
||||||
|
|
||||||
cmdclass = {
|
cmdclass = {
|
||||||
|
'build': BuildWithDLLs if os.name == 'nt' else CFFIBuild,
|
||||||
'test': TestCommand,
|
'test': TestCommand,
|
||||||
'sdist': sdist_files_from_git}
|
'sdist': sdist_files_from_git,
|
||||||
|
}
|
||||||
if os.name == 'nt':
|
|
||||||
# BuildWithDLLs can copy external DLLs into source directory.
|
|
||||||
cmdclass['build'] = BuildWithDLLs
|
|
||||||
else:
|
|
||||||
# Build cffi
|
|
||||||
cmdclass['build'] = CFFIBuild
|
|
||||||
|
|
||||||
|
|
||||||
setup(name='pygit2',
|
setup(name='pygit2',
|
||||||
description='Python bindings for libgit2.',
|
description='Python bindings for libgit2.',
|
||||||
|
Reference in New Issue
Block a user