[Distutils] PEP 376, Uninstallation and interoperability
Vinay Sajip
vinay_sajip at yahoo.co.uk
Sat Feb 16 13:28:21 CET 2013
Paul Moore <p.f.moore <at> gmail.com> writes:
> The obvious example is pyc/pyo files.
Yes, and these could be deleted even if they are not in the RECORD file (they
would be if byte-compiling is done at installation time, but not otherwise).
> It would be good to cater better for "clean" uninstalls. Would it not
> be easier though to simply record the directories that the installer
> created (probably just in RECORD, but maybe in a separate file) and
> once all the files have been deleted, delete the directories if they
> are empty or prompt if there are (presumably user-created) files left?
> I'd make an exception for pyc/pyo files and __pycache__ subdirectories
> and ignore them in that last "is the directory empty?" check.
I implemented this in distlib (adding dirs to RECORD), but took it out again
because (a) the PEP doesn't mention having directories in RECORD and (b)
setuptools/pip installations don't include directories in their equivalent
metadata files.
Distlib currently does what you say (look for non-empty dirs, after accounting
for all files in RECORD, and handles __pycache__), and it assumes that the
parent directory of .dist-info is the site-packages directory. This is probably
okay, but how to infer which directories were used for e.g. script
installation? It's not safe to assume the default in all cases, given that
tools may provide overrides (as distutils/setuptools do).
Consider the following: suppose I install two distributions, foo and bar, which
install scripts not in the standard location $prefix/bin, but (say)
$prefix/bin/utils. (For Windows, s/bin/Scripts/.)
When uninstalling foo, an entry for a script foo-cli is seen and foo-cli is
removed, and its parent directory $prefix/bin/utils is remembered (whether or
not it was present in RECORD, we know about it from the foo-cli entry in
RECORD). When we've gone through all the files in RECORD, we are left with a
non-empty directory $prefix/bin/utils which contains bar-cli, from the other
distribution we installed. We have no way of knowing whether bar-cli is an
extraneous file we need to mention to the user, or a file belonging to another
distribution: that's because we have no way of knowing that $prefix/bin/utils
is essentially a shared location between foo and bar. This could be rectified
if both foo.dist-info and bar.dist-info have a SHARED file which each names
$prefix/bin/utils as a shared location.
Likewise, if a number of distributions keep their man pages in $prefix/man, we
have no way of knowing if this is a shared location between distributions
(don't warn the user if extra files are found) or a location private to one
distribution (if non-empty when uninstalling it, warn the user about the
extraneous file).
Regards,
Vinay Sajip
More information about the Distutils-SIG
mailing list