[pygobject] Allow installing with pip



commit f65bb1fc8f7f6172970545412fe56ab75f57904b
Author: Mathieu Bridon <bochecha daitauha fr>
Date:   Thu Jun 23 22:35:42 2016 +0200

    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

 .gitignore  |    3 ++
 Makefile.am |    3 +-
 setup.py    |  105 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 110 insertions(+), 1 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index ad1b294..8664413 100644
--- a/.gitignore
+++ b/.gitignore
@@ -67,3 +67,6 @@ Makefile.in
 /tags
 /xmldocs.make
 /tmp/*
+/build/
+/dist/
+/pygobject.egg-info/
diff --git a/Makefile.am b/Makefile.am
index 1a984e1..186cfd7 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 0000000..0da9ed9
--- /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,
+    },
+)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]