From 53b341ff67f2b7d63db2783734a813354a5e3264 Mon Sep 17 00:00:00 2001 From: Jack Jansen Date: Wed, 12 Feb 2003 15:36:25 +0000 Subject: [PATCH] - Better way to find site-packages - Catch stderr as well as stdout - Fixed a bug with non-installable packages - Parse .pth files after installing, so you don't have to restart Python (or the IDE) after installing. --- Lib/plat-mac/pimp.py | 46 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/Lib/plat-mac/pimp.py b/Lib/plat-mac/pimp.py index 61a99264173..2ca5369733f 100644 --- a/Lib/plat-mac/pimp.py +++ b/Lib/plat-mac/pimp.py @@ -33,7 +33,12 @@ DEFAULT_FLAVORORDER=['source', 'binary'] DEFAULT_DOWNLOADDIR='/tmp' DEFAULT_BUILDDIR='/tmp' -DEFAULT_INSTALLDIR=os.path.join(sys.prefix, "Lib", "site-packages") +for _p in sys.path: + if _p[-13:] == 'site-packages': + DEFAULT_INSTALLDIR=_p + break +else: + DEFAULT_INSTALLDIR=sys.prefix # Have to put things somewhere DEFAULT_PIMPDATABASE="http://www.cwi.nl/~jack/pimp/pimp-%s.plist" % distutils.util.get_platform() ARCHIVE_FORMATS = [ @@ -339,7 +344,7 @@ def prerequisites(self): string should tell the user what to do.""" rv = [] - if not self._dict['Download-URL']: + if not self._dict.get('Download-URL'): return [(None, "This package needs to be installed manually")] if not self._dict['Prerequisites']: return [] @@ -369,7 +374,8 @@ def _cmd(self, output, dir, *cmditems): output.write("+ %s\n" % cmd) if NO_EXECUTE: return 0 - fp = os.popen(cmd, "r") + dummy, fp = os.popen4(cmd, "r") + dummy.close() while 1: line = fp.readline() if not line: @@ -449,23 +455,57 @@ def installSinglePackage(self, output=None): msg = self.downloadSinglePackage(output) if msg: return "download %s: %s" % (self.fullname(), msg) + msg = self.unpackSinglePackage(output) if msg: return "unpack %s: %s" % (self.fullname(), msg) + if self._dict.has_key('Pre-install-command'): if self._cmd(output, self._buildDirname, self._dict['Pre-install-command']): return "pre-install %s: running \"%s\" failed" % \ (self.fullname(), self._dict['Pre-install-command']) + + old_contents = os.listdir(self._db.preferences.installDir) installcmd = self._dict.get('Install-command') if not installcmd: installcmd = '"%s" setup.py install' % sys.executable if self._cmd(output, self._buildDirname, installcmd): return "install %s: running \"%s\" failed" % self.fullname() + + new_contents = os.listdir(self._db.preferences.installDir) + self._interpretPthFiles(old_contents, new_contents) + if self._dict.has_key('Post-install-command'): if self._cmd(output, self._buildDirname, self._dict['Post-install-command']): return "post-install %s: running \"%s\" failed" % \ (self.fullname(), self._dict['Post-install-command']) return None + + def _interpretPthFiles(self, old_contents, new_contents): + """Evaluate any new .pth files that have appeared after installing""" + for fn in new_contents: + if fn in old_contents: + continue + if fn[-4:] != '.pth': + continue + fullname = os.path.join(self._db.preferences.installDir, fn) + f = open(fullname) + for line in f.readlines(): + if not line: + continue + if line[0] == '#': + continue + if line[:6] == 'import': + exec line + continue + if line[-1] == '\n': + line = line[:-1] + if not os.path.isabs(line): + line = os.path.join(self._db.preferences.installDir, line) + line = os.path.realpath(line) + if not line in sys.path: + sys.path.append(line) + class PimpInstaller: """Installer engine: computes dependencies and installs