On Fri, Mar 29, 2013 at 2:02 AM, Vinay Sajip <vinay_sajip@yahoo.co.uk> wrote:
Thanks for the feedback. How about if I change mount()/unmount() to:
def mount(self, append=False, destdir=None): """ Unzip the wheel's contents to the specified directory, or to a temporary directory if destdir is None. Add this directory to sys.path, either appending or prepending according to whether append is True or False.
No, mutating sys.path for versioned imports is a broken design. You end up with two possibilities: * If you append, then you can't override modules that have a default version available on sys.path. This is not an acceptable restriction, which is why pkg_resources doesn't do it that way * If you prepend, then you have the existing pkg_resources failure mode where it can accidentally shadow more modules than intended. This is a nightmare to debug when it goes wrong (it took me months to realise this was why a system install of the main application I work on was shadowing the version in source checkout when running the test suite or building the documentation). The correct way to do it is with a path hook that processes a special "<versioned-packages>" marker label in sys.path (probably placed after the standard library but before site-packages by default). Any mounted directories would be tracked by that path hook, but never included directly in sys.path itself. See http://mail.python.org/pipermail/distutils-sig/2013-March/020207.html for more on how this could be handled (consider mount/unmount as the lower level API for actually adding new path entries directly to the dynamic importer). Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia