~townsend/compiz/fix-auto-vp-switch-0.9.10

« back to all changes in this revision

Viewing changes to compizconfig/compizconfig-python/setup.py

  • Committer: Sam Spilsbury
  • Date: 2012-10-16 13:53:20 UTC
  • mto: This revision was merged to the branch mainline in revision 3434.
  • Revision ID: sam.spilsbury@canonical.com-20121016135320-3zb8wy8u16eayb7m
Clean up the CMake code around the python modules and uninstalling
 - It isn't possible to build python extensions using distutils that
   link to things that we are building, because CMake provides no
   means for a custom command to depend on a library. Build them
   using CMake directly instead
 - Clean up the tests: the tests depended on having a working opengl
   and core plugin xml file and were also sensitive to xml data. Make
   a mock.xml and use that instead
 - Require ini for the compizconfig-python tests. They won't run without it
 - Fix the uninstall scripts. We were clobbering the uninstall target
   with the python uninstall targets, that is just plain wrong. Created
   a new cmake function to append custom uninstall scripts to the global
   uninstall script

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
from distutils.command.install import install as _install
5
5
from distutils.command.install_data import install_data as _install_data
6
6
from distutils.command.sdist import sdist as _sdist
7
 
from distutils.extension import Extension
8
7
import os
9
8
import subprocess
10
9
import sys
11
10
import unittest
 
11
 
12
12
pkg_config_environ = os.environ
13
13
pkg_config_environ["PKG_CONFIG_PATH"] = os.getcwd () + "/../libcompizconfig:" + os.environ.get ("PKG_CONFIG_PATH", '')
14
14
 
15
 
from distutils.command.build_ext import build_ext
16
 
ext_module_src = os.getcwd () + "/compizconfig.c"
17
 
 
18
 
def pkgconfig(*packages, **kw):
19
 
    flag_map = {'-I': 'include_dirs', '-L': 'library_dirs', '-l': 'libraries', '-R': 'runtime_library_dirs'}
20
 
    cmd = ['pkg-config', '--libs', '--cflags']
21
 
 
22
 
    tokens = subprocess.Popen (cmd + list(packages), stdout=subprocess.PIPE, env=pkg_config_environ).communicate()[0].split ()
23
 
 
24
 
    for t in tokens:
25
 
        if '-L' in t[:2]:
26
 
            kw.setdefault (flag_map.get ("-L"), []).append (t[2:])
27
 
        elif '-I' in t[:2]:
28
 
            kw.setdefault (flag_map.get ("-I"), []).append (t[2:])
29
 
        elif '-l' in t[:2]:
30
 
            kw.setdefault (flag_map.get ("-l"), []).append (t[2:])
31
 
    
32
 
    return kw
33
 
 
34
 
for arg in sys.argv:
35
 
    if "--version" in arg:
36
 
        VERSION = arg.split ("=")[1]
37
 
 
38
15
pkgconfig_libs = subprocess.Popen (["pkg-config", "--libs", "libcompizconfig_internal"], stdout=subprocess.PIPE, env=pkg_config_environ, stderr=open(os.devnull, 'w')).communicate ()[0]
39
16
 
40
17
if len (pkgconfig_libs) is 0:
45
22
 
46
23
INSTALLED_FILES = "installed_files"
47
24
 
 
25
for arg in sys.argv:
 
26
    if "--version" in arg:
 
27
        VERSION = arg.split ("=")[1]
 
28
 
48
29
class build (_build):
49
30
 
50
31
    user_options = _build.user_options[:]
103
84
 
104
85
class uninstall (_install):
105
86
 
 
87
    user_options = _install.user_options[:]
 
88
    user_options.extend ([('version=', None, "Version of the package")])
 
89
 
 
90
    def initialize_options(self):
 
91
        self.version = None
 
92
        _install.initialize_options (self)
 
93
 
 
94
    def finalize_options(self):
 
95
        _install.finalize_options (self)
 
96
 
106
97
    def run (self):
107
98
        try:
108
99
            file = open (INSTALLED_FILES, "r")
159
150
                      "install" : install,
160
151
                      "install_data" : install_data,
161
152
                      "build"     : build,
162
 
                      "build_ext" : build_ext,
163
 
                      "test"  : test},
164
 
  ext_modules=[ 
165
 
    Extension ("compizconfig", [ext_module_src],
166
 
               **pkgconfig("libcompizconfig_internal"))
167
 
    ]
 
153
                      "test"  : test}
168
154
)
169
155