make texmessagepatternwarning official (i.e. remove the _)
[PyX.git] / setup.py
blobc32decfd5e9da7028707e6d18c7fb5647fdbeee4
1 #!/usr/bin/env python
2 # -*- coding: ISO-8859-1 -*-
4 """Python package for the generation of PostScript and PDF files
6 PyX is a Python package for the creation of PostScript and PDF files. It
7 combines an abstraction of the PostScript drawing model with a TeX/LaTeX
8 interface. Complex tasks like 2d and 3d plots in publication-ready quality are
9 built out of these primitives.
10 """
12 from distutils import log
13 from distutils.core import setup, Extension
14 from distutils.util import change_root, convert_path
15 from distutils.command.build_py import build_py
16 from distutils.command.install_data import install_data
17 from distutils.command.install_lib import install_lib
18 import ConfigParser
19 import sys, os
20 import pyx
23 # build list of extension modules
26 ext_modules = []
27 pykpathsea_ext_module = Extension("pyx.pykpathsea._pykpathsea",
28 sources=["pyx/pykpathsea/pykpathsea.c"],
29 libraries=["kpathsea"])
30 t1strip_ext_module = Extension("pyx.t1strip._t1strip",
31 sources=["pyx/t1strip/t1strip.c", "pyx/t1strip/writet1.c"])
33 # obtain information on which modules have to be built from setup.cfg file
34 cfg = ConfigParser.ConfigParser()
35 cfg.read("setup.cfg")
36 if cfg.has_section("PyX"):
37 if cfg.has_option("PyX", "build_pykpathsea") and cfg.getboolean("PyX", "build_pykpathsea"):
38 ext_modules.append(pykpathsea_ext_module)
39 if cfg.has_option("PyX", "build_t1strip") and cfg.getboolean("PyX", "build_t1strip"):
40 ext_modules.append(t1strip_ext_module)
42 ################################################################################
43 # data files
46 # share/pyx is taken relative to "setup.py install --home=..."
47 # whereas /etc is taken relative to "setup.py install --root=..."
49 data_files = []
51 # variable names in siteconfig.py for a list of files in data_files
52 siteconfignames = {}
54 def adddatafiles(siteconfigname, dir, files):
55 """store siteconfigname for files in siteconfignames and add (dir, files) to data_files"""
56 # convert files to a tuple to make it hashable
57 files = tuple(files)
58 data_files.append((dir, files))
59 siteconfignames[files] = siteconfigname
61 adddatafiles("lfsdir", "share/pyx", ["pyx/lfs/10pt.lfs",
62 "pyx/lfs/11pt.lfs",
63 "pyx/lfs/12pt.lfs",
64 "pyx/lfs/10ptex.lfs",
65 "pyx/lfs/11ptex.lfs",
66 "pyx/lfs/12ptex.lfs",
67 "pyx/lfs/foils17pt.lfs",
68 "pyx/lfs/foils20pt.lfs",
69 "pyx/lfs/foils25pt.lfs",
70 "pyx/lfs/foils30pt.lfs"])
71 adddatafiles("sharedir", "share/pyx", ["contrib/pyx.def"])
73 # Note that on windows we can't install to absolute paths. Hence
74 # we put the global pyxrc into the share directory as well.
75 adddatafiles("pyxrcdir", os.name != "nt" and "/etc" or "share/pyx", ["pyxrc"])
77 ################################################################################
78 # extend install commands to overwrite siteconfig.py during build and install
82 class pyx_build_py(build_py):
84 def build_module(self, module, module_file, package):
85 if package == "pyx" and module == "siteconfig":
86 # generate path information as the original build_module does it
87 outfile = self.get_module_outfile(self.build_lib, [package], module)
88 outdir = os.path.dirname(outfile)
89 self.mkpath(outdir)
91 log.info("creating proper %s" % outfile)
93 # create the additional relative path parts to be inserted into the
94 # os.path.join methods in the original siteconfig.py
95 indir = os.path.dirname(module_file)
96 addjoinstring = ", ".join(["'..'" for d in outdir.split(os.path.sep)] +
97 ["'%s'" % d for d in indir.split(os.path.sep)])
99 # write a modifed version of siteconfig.py
100 fin = open(module_file, "r")
101 fout = open(outfile, "w")
102 for line in fin.readlines():
103 fout.write(line.replace("os.path.join(os.path.dirname(__file__), ",
104 "os.path.join(os.path.dirname(__file__), %s, " % addjoinstring))
105 fin.close()
106 fout.close()
107 else:
108 return build_py.build_module(self, module, module_file, package)
111 class pyx_install_data(install_data):
113 def run(self):
114 self.siteconfiglines = []
115 for dir, files in self.data_files:
116 # append siteconfiglines by "<siteconfigname> = <dir>"
118 # get the install directory
119 # (the following four lines are copied from within the install_data.run loop)
120 dir = convert_path(dir)
121 if not os.path.isabs(dir):
122 dir = os.path.join(self.install_dir, dir)
123 elif self.root:
124 dir = change_root(self.root, dir)
126 self.siteconfiglines.append("%s = '%s'\n" % (siteconfignames[files], dir))
128 install_data.run(self)
131 class pyx_install_lib(install_lib):
133 def run(self):
134 # siteconfig.py depends on install_data:
135 self.run_command('install_data')
136 install_lib.run(self)
138 def install(self):
139 # first we perform the tree_copy
140 result = install_lib.install(self)
142 # siteconfiglines have been created by install_data
143 siteconfiglines = self.distribution.command_obj["install_data"].siteconfiglines
145 # such that we can easily overwrite siteconfig.py
146 outfile = os.path.join(self.install_dir, "pyx", "siteconfig.py")
147 log.info("creating proper %s" % outfile)
148 f = open(outfile, "w")
149 f.writelines(siteconfiglines)
150 f.close()
152 return result
154 ################################################################################
155 # additional package metadata (only available in Python 2.3 and above)
158 if sys.version_info >= (2, 3):
159 addargs = { "classifiers":
160 [ "Development Status :: 3 - Alpha",
161 "Intended Audience :: Developers",
162 "Intended Audience :: End Users/Desktop",
163 "License :: OSI Approved :: GNU General Public License (GPL)",
164 "Operating System :: OS Independent",
165 "Programming Language :: Python",
166 "Topic :: Multimedia :: Graphics",
167 "Topic :: Scientific/Engineering :: Visualization",
168 "Topic :: Software Development :: Libraries :: Python Modules" ],
169 "download_url":
170 "http://sourceforge.net/project/showfiles.php?group_id=45430",
171 "platforms":
172 "OS independent",
174 else:
175 addargs = {}
177 # We're using the module docstring as the distutils descriptions. (seen in Zope3 setup.py)
178 doclines = __doc__.split("\n")
180 setup(name="PyX",
181 version=pyx.__version__,
182 author="Jörg Lehmann, André Wobst",
183 author_email="pyx-devel@lists.sourceforge.net",
184 url="http://pyx.sourceforge.net/",
185 description=doclines[0],
186 long_description="\n".join(doclines[2:]),
187 license="GPL",
188 packages=["pyx", "pyx/graph", "pyx/graph/axis", "pyx/t1strip", "pyx/pykpathsea"],
189 ext_modules=ext_modules,
190 data_files=data_files,
191 cmdclass = {"build_py": pyx_build_py,
192 "install_data": pyx_install_data,
193 "install_lib": pyx_install_lib},
194 **addargs)