diff options
author | Mathieu Bridon <bochecha@daitauha.fr> | 2016-06-23 22:35:42 +0200 |
---|---|---|
committer | Mathieu Bridon <bochecha@daitauha.fr> | 2016-06-29 12:33:00 +0200 |
commit | f65bb1fc8f7f6172970545412fe56ab75f57904b (patch) | |
tree | 54e0a251cf1a7c84eef461f3c5e9cbca3a7613f3 | |
parent | 14626ee5dcf380ae94680626607742a8cc048351 (diff) | |
download | pygobject-f65bb1fc8f7f6172970545412fe56ab75f57904b.tar.gz |
Allow installing with pip
This commit adds a setup.py file which just calls the autotools to
configure/make/make install.
It is heavily inspired by the similar work from Simon McVittie on
dbus-python.
https://bugzilla.gnome.org/show_bug.cgi?id=767988
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | Makefile.am | 3 | ||||
-rwxr-xr-x | setup.py | 105 |
3 files changed, 110 insertions, 1 deletions
@@ -67,3 +67,6 @@ Makefile.in /tags /xmldocs.make /tmp/* +/build/ +/dist/ +/pygobject.egg-info/ diff --git a/Makefile.am b/Makefile.am index 1a984e13..186cfd76 100644 --- a/Makefile.am +++ b/Makefile.am @@ -23,7 +23,8 @@ EXTRA_DIST = \ pygi-convert.sh \ m4/as-ac-expand.m4 \ m4/jhflags.m4 \ - m4/python.m4 + m4/python.m4 \ + setup.py MAINTAINERCLEANFILES = \ $(srcdir)/INSTALL \ diff --git a/setup.py b/setup.py new file mode 100755 index 00000000..0da9ed95 --- /dev/null +++ b/setup.py @@ -0,0 +1,105 @@ +#!/usr/bin/env python + + +import os +import re +import subprocess +import sys + +from distutils.command.build import build as orig_build +from setuptools.command.build_ext import build_ext as orig_build_ext +from setuptools.command.build_py import build_py as orig_build_py +from setuptools import setup, Extension + + +with open("configure.ac", "r") as h: + version = ".".join(re.findall("pygobject_[^\s]+_version,\s*(\d+)\)", h.read())) + + +def makedirs(dirpath): + """Safely make directories + + By default, os.makedirs fails if the directory already exists. + + Python 3.2 introduced the `exist_ok` argument, but we can't use it because + we want to keep supporting Python 2 for some time. + """ + import errno + + try: + os.makedirs(dirpath) + + except OSError as e: + if e.errno == errno.EEXIST: + return + + raise + + +class Build(orig_build): + """Dummy version of distutils build which runs an Autotools build system + instead. + """ + def run(self): + srcdir = os.getcwd() + builddir = os.path.join(srcdir, self.build_temp) + makedirs(builddir) + configure = os.path.join(srcdir, 'configure') + + if not os.path.exists(configure): + configure = os.path.join(srcdir, 'autogen.sh') + + subprocess.check_call([ + configure, + 'PYTHON=%s' % sys.executable, + # Put the documentation, etc. out of the way: we only want + # the Python code and extensions + '--prefix=' + os.path.join(builddir, 'prefix'), + ], + cwd=builddir) + make_args = [ + 'pythondir=%s' % os.path.join(srcdir, self.build_lib), + 'pyexecdir=%s' % os.path.join(srcdir, self.build_lib), + ] + subprocess.check_call(['make', '-C', builddir] + make_args) + subprocess.check_call(['make', '-C', builddir, 'install'] + make_args) + + +class BuildExt(orig_build_ext): + def run(self): + pass + + +class BuildPy(orig_build_py): + def run(self): + pass + + +setup( + name='pygobject', + version=version, + description='Python bindings for GObject Introspection', + maintainer='The pygobject maintainers', + maintainer_email='http://mail.gnome.org/mailman/listinfo/python-hackers-list', + download_url='http://download.gnome.org/sources/pygobject/', + url='https://wiki.gnome.org/Projects/PyGObject', + packages=['gi', 'pygtkcompat'], + ext_modules=[ + Extension( + '_gi', sources=['gi/gimodule.c']) + ], + license='LGPL', + classifiers=[ + 'Development Status :: 5 - Production/Stable', + 'License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)', + 'Programming Language :: C', + 'Programming Language :: Python :: 2', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: Implementation :: CPython', + ], + cmdclass={ + 'build': Build, + 'build_py': BuildPy, + 'build_ext': BuildExt, + }, +) |