restore siteconfig.py even when setup failes
[PyX/mjg.git] / setup.py
blob155477874852c2af68cea2aa500f2b3c4e7e67fd
1 #!/usr/bin/env python
2 # -*- coding: ISO-8859-1 -*-
4 """Python package for the generation of encapsulated PostScript figures
6 PyX is a Python package for the creation of encapsulated PostScript figures.
7 It provides both an abstraction of PostScript and a TeX/LaTeX interface.
8 Complex tasks like 2d and 3d plots in publication-ready quality are built out
9 of these primitives.
10 """
12 from distutils.core import setup, Extension
13 from distutils.command.install import install
14 import ConfigParser
15 import sys, os
16 import pyx
19 # build list of extension modules
22 ext_modules = []
23 pykpathsea_ext_module = Extension("pyx.pykpathsea._pykpathsea",
24 sources=["pyx/pykpathsea/pykpathsea.c"],
25 libraries=["kpathsea"])
26 t1strip_ext_module = Extension("pyx.t1strip._t1strip",
27 sources=["pyx/t1strip/t1strip.c", "pyx/t1strip/writet1.c"])
29 # obtain information on which modules have to be built from setup.cfg file
30 cfg = ConfigParser.ConfigParser()
31 cfg.read("setup.cfg")
32 if cfg.has_section("PyX"):
33 if cfg.has_option("PyX", "build_pykpathsea") and cfg.getboolean("PyX", "build_pykpathsea"):
34 ext_modules.append(pykpathsea_ext_module)
35 if cfg.has_option("PyX", "build_t1strip") and cfg.getboolean("PyX", "build_t1strip"):
36 ext_modules.append(t1strip_ext_module)
39 # data files
42 data_files = [("share/pyx", ["pyx/lfs/10pt.lfs",
43 "pyx/lfs/11pt.lfs",
44 "pyx/lfs/12pt.lfs",
45 "pyx/lfs/10ptex.lfs",
46 "pyx/lfs/11ptex.lfs",
47 "pyx/lfs/12ptex.lfs",
48 "pyx/lfs/foils17pt.lfs",
49 "pyx/lfs/foils20pt.lfs",
50 "pyx/lfs/foils25pt.lfs",
51 "pyx/lfs/foils30pt.lfs",
52 "contrib/pyx.def"])]
55 # install enhanced by siteconfig
58 class pyxinstall(install):
60 def run(self):
61 # name of the siteconfig file
62 siteconfigname = os.path.join("pyx", "siteconfig.py")
64 # read existing siteconfig
65 try:
66 f = open(siteconfigname, "rb")
67 oldsiteconfig = f.read()
68 f.close()
69 except:
70 oldsiteconfig = None
72 try:
73 # fill siteconfig data
74 sharedir = os.path.join(self.install_data, "share", "pyx")
75 f = open(siteconfigname, "w")
76 f.write("lfsdir = %r\n" % sharedir)
77 f.write("sharedir = %r\n" % sharedir)
78 f.close()
80 # perform install
81 install.run(self)
82 finally:
83 # restore existing siteconfig
84 if oldsiteconfig is not None:
85 f = open(siteconfigname, "wb")
86 f.write(oldsiteconfig)
87 f.close()
88 else:
89 os.unlink(siteconfigname)
92 # additional package metadata (only available in Python 2.3 and above)
95 if sys.version_info >= (2, 3):
96 addargs = { "classifiers":
97 [ "Development Status :: 3 - Alpha",
98 "Intended Audience :: Developers",
99 "Intended Audience :: End Users/Desktop",
100 "License :: OSI Approved :: GNU General Public License (GPL)",
101 "Operating System :: OS Independent",
102 "Programming Language :: Python",
103 "Topic :: Multimedia :: Graphics",
104 "Topic :: Scientific/Engineering :: Visualization",
105 "Topic :: Software Development :: Libraries :: Python Modules" ],
106 "download_url":
107 "http://sourceforge.net/project/showfiles.php?group_id=45430",
108 "platforms":
109 "OS independent",
111 else:
112 addargs = {}
114 # We're using the module docstring as the distutils descriptions. (seen in Zope3 setup.py)
115 doclines = __doc__.split("\n")
117 setup(name="PyX",
118 version=pyx.__version__,
119 author="Jörg Lehmann, André Wobst",
120 author_email="pyx-devel@lists.sourceforge.net",
121 url="http://pyx.sourceforge.net/",
122 description=doclines[0],
123 long_description="\n".join(doclines[2:]),
124 license="GPL",
125 packages=["pyx", "pyx/graph", "pyx/graph/axis", "pyx/t1strip", "pyx/pykpathsea"],
126 ext_modules=ext_modules,
127 data_files=data_files,
128 cmdclass = {"install": pyxinstall},
129 **addargs)