On Tue, 18 Sep 2018 at 19:54, Thomas Kluyver <tho...@kluyver.me.uk> wrote: > > On Fri, Sep 14, 2018, at 4:26 PM, Paul Moore wrote: > > I don't think it's "hard to predict". I *do* think it's badly > > documented/not standardised. > > ... > > Better would be to have a supported library that exposes the logic pip > > uses (or as I said above, the standard-defined logic) to determine > > such paths. See https://github.com/pypa/pip/issues/5191 > > There is an official standard library API in the sysconfig module to find > installation locations: > https://docs.python.org/3/library/sysconfig.html#installation-paths
Yes, if it weren't for the stuff mentioned below, that would be the one obvious way of doing things. However... > Unfortunately, distutils has a copy of this logic rather than using the > sysconfig module, from what I remember. Some Linux distros have patched > distutils to put installed files in different locations, but have not > necessarily patched sysconfig, presumably because they didn't think about it. (Technically, I think the history is that sysconfig was created by pulling the distutils logic out into a standalone module, but no-one modified distutils to use sysconfig - probably the usual "fear of changing anything in distutils" problem :-() Even more unfortunately, pip further layers its own logic on this (https://github.com/pypa/pip/blob/master/src/pip/_internal/locations.py#L136) - basically a "sledgehammer to crack a nut" approach of initialising a distutils install command object, and then introspecting it to find out where it'll install stuff - then hacking some special cases on top of that. I assume it's doing that to patch over the incomplete Linux distro patching. > Even if sysconfig were patched, distros may have a different location for > files installed by the distro package manager and files installed by other > means (Debian based distros use /usr and /usr/local for these). So there's no > one data directory where you can find all files related to importable > packages. (Of course, we advise against 'sudo pip install', but people still > do it anyway). Yeah. We don't really have any control or influence over what distros do, we just end up reacting to their changes. That's why I think we need a centralised supported library - unless the distros start working better with the Python stdlib APIs, someone needs to collect together all the workarounds and hacks needed to interact with them, and that's better done in one place than duplicating the work in multiple projects (and the fact that people have asked for pip's locations module to be exposed as an API confirms to me that there *are* multiple projects that need this). > This may be somewhat outdated - it's been a while since I looked into this, > but I don't think the relevant pieces are changing rapidly. My conclusion at > the time was that the only reliable way to have data files findable at > runtime was to put them inside the importable package. Agreed. There's more engagement with the distros these days (I think) but it hasn't resulted in much change in how they handle things yet. Paul -- Distutils-SIG mailing list -- distutils-sig@python.org To unsubscribe send an email to distutils-sig-le...@python.org https://mail.python.org/mm3/mailman3/lists/distutils-sig.python.org/ Message archived at https://mail.python.org/mm3/archives/list/distutils-sig@python.org/message/SOPHWWWXEPV4MJARUETPNWO5BVQA5RYB/