File: setup.py

package info (click to toggle)
pyxmms 2.04-2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 312 kB
  • ctags: 191
  • sloc: ansic: 1,340; python: 657; makefile: 99; sh: 57
file content (152 lines) | stat: -rwxr-xr-x 6,184 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#! /usr/bin/env python

# setup.py --- Setup script for PyXMMS
# Copyright (c) 2002, 2003 Florent Rougon
#
# This file is part of PyXMMS.
#
# PyXMMS is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 dated June, 1991.
#
# PyXMMS is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING. If not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
# MA 02111-1307, USA.

import os, string, sys, distutils.dist
from distutils.core import setup, Extension

# Note:
#
#   The Distutils included in Python 2.1 don't understand the "license"
#   keyword argument of setup correctly (they only understand licence); if you
#   run the Distutils from Python 2.1, you will get License: UNKNOWN. This
#   problem does not appear with the versions included in Python 2.2 and 2.3.

PACKAGE = "pyxmms"
VERSION = "2.04"
GLIB_CONFIG = "glib-config"


def get_glib_config():
    """Get the compilation and link parameters for glib."""
    glib_opts = {}
    for option in ("cflags", "libs"):
        glib_config_pipe = os.popen("%s --%s" % (GLIB_CONFIG, option), 'r')
        # strip the trailing newline
        glib_opts[option] = glib_config_pipe.read()[:-1]
        if glib_config_pipe.close() is not None:
            sys.exit("%s returned a non-zero exit status. Aborting."
                     % GLIB_CONFIG)

    # Separate the -I options from the other options because to feed to
    # distutils.Extension as include_dirs and extra_compile_args.
    # This is not perfect since an argument starting with -I might not be a -I
    # option, I think, but Distutils' extra_compile_args go to the end of the
    # compiler command line, so we have to use something else for include
    # directories...
    compile_args = []
    include_dirs = []
    for opt in string.split(glib_opts["cflags"]):
        if len(opt) >= 3 and opt[:2] == "-I":
            include_dirs.append(opt[2:])
        else:
            compile_args.append(opt)
    
    # Make a list of the link arguments to feed to distutils.Extension as
    # extra_link_args
    link_args = string.split(glib_opts["libs"])

    return (include_dirs, compile_args, link_args)


def setup_args():
    """Craft appropriate arguments for distutils.setup."""
    (glib_include_dirs, glib_compile_args, glib_link_args) = get_glib_config()
    
    # Modules built whatever the version of the running Python
    ext_modules = [Extension("xmms._xmmscontrol",
                             ["src/_xmmscontrolmodule.c"],
                             include_dirs=glib_include_dirs,
                             extra_compile_args=glib_compile_args,
                             libraries=["xmms"],
                             extra_link_args=glib_link_args)]

    if sys.hexversion < 0x02020000:
        sys.stderr.write("Warning: this Python is 2.1 or earlier, so only "
                         "part of PyXMMS will be available.\n")
        setup_pyversion_specific_args = {
            "py_modules": ["xmms.control", "xmms.common"]
            }
    else:
        setup_pyversion_specific_args = {
            "packages": ["xmms"]
            }
        # This module requires Python >= 2.2
        ext_modules.append(Extension("xmms._xmmsconfig",
                                     ["src/_xmmsconfigmodule.c"],
                                     include_dirs=glib_include_dirs,
                                     extra_compile_args=glib_compile_args,
                                     libraries=["xmms"],
                                     extra_link_args=glib_link_args))

    # Trove classifiers picked up from the list at
    # http://www.python.org/pypi?:action=list_classifiers
    trove_classifiers = [
        "Development Status :: 6 - Mature",
        "Intended Audience :: Developers",
        "License :: OSI Approved :: GNU General Public License (GPL)",
        "Operating System :: OS Independent",
        "Programming Language :: Python",
        "Topic :: Multimedia :: Sound/Audio :: CD Audio :: CD Playing",
        "Topic :: Multimedia :: Sound/Audio :: Players",
        "Topic :: Multimedia :: Sound/Audio :: Players :: MP3",
        "Topic :: Software Development :: Libraries :: Python Modules"]

    # The metadata used below is mainly intended for PyPI... and the PyPI
    # tutorial at http://www.python.org/~jeremy/weblog/030924.html recommends
    # giving the URL of the license, instead of its name (PEP 241 requires the
    # name). So let's go with the URL...
    setup_args = {
        "name": PACKAGE,
        "version": VERSION,
        "author": "Florent Rougon",
        "author_email": "flo@via.ecp.fr",
        "maintainer": "Florent Rougon",
        "maintainer_email": "flo@via.ecp.fr",
        "url": "http://people.via.ecp.fr/~flo/",
        "download_url": "http://people.via.ecp.fr/~flo/2002/PyXMMS/dist/",
        "license": "http://www.gnu.org/licenses/gpl.html",
        "platforms": ["any"],
        "description": "A Python interface to XMMS",
        "long_description":  """\
PyXMMS is a Python package allowing full control of XMMS as well as
management of its configuration file. XMMS is a multimedia player
written for the X Window System.""",
        "keywords": ["xmms"],
        "classifiers": trove_classifiers,
        "package_dir": {"xmms": "src"},
        "ext_modules": ext_modules
        }
    setup_args.update(setup_pyversion_specific_args)
    return setup_args


def main():
    # Patch distutils if it can't cope with the "classifiers" or
    # "download_url" keywords
    if sys.hexversion < 0x02020300:
        from distutils.dist import DistributionMetadata
        DistributionMetadata.classifiers = None
        DistributionMetadata.download_url = None

    setup(**setup_args())


if __name__ == "__main__": main()