diff options
author | Sviatoslav Sydorenko <wk@sydorenko.org.ua> | 2020-12-31 17:51:58 +0100 |
---|---|---|
committer | Sviatoslav Sydorenko <wk@sydorenko.org.ua> | 2020-12-31 18:38:48 +0100 |
commit | b5fdca1ecb05a8c4c2da434e55d6ef5efec91e3e (patch) | |
tree | 3c667ed3b5d4ff940ae779592837a453c282a9a5 | |
parent | 0d3b9600b2a94449796d06e3cea06c7a3972887b (diff) | |
download | python-setuptools-git-b5fdca1ecb05a8c4c2da434e55d6ef5efec91e3e.tar.gz |
Simplify `easy_install.update_pth`
-rw-r--r-- | setuptools/command/easy_install.py | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py index ff449435..6d990af4 100644 --- a/setuptools/command/easy_install.py +++ b/setuptools/command/easy_install.py @@ -1196,11 +1196,13 @@ class easy_install(Command): return for d in self.pth_file[dist.key]: # drop old entries - if self.multi_version or d.location != dist.location: - log.info("Removing %s from easy-install.pth file", d) - self.pth_file.remove(d) - if d.location in self.shadow_path: - self.shadow_path.remove(d.location) + if not self.multi_version and d.location == dist.location: + continue + + log.info("Removing %s from easy-install.pth file", d) + self.pth_file.remove(d) + if d.location in self.shadow_path: + self.shadow_path.remove(d.location) if not self.multi_version: if dist.location in self.pth_file.paths: @@ -1214,19 +1216,21 @@ class easy_install(Command): if dist.location not in self.shadow_path: self.shadow_path.append(dist.location) - if not self.dry_run: + if self.dry_run: + return - self.pth_file.save() + self.pth_file.save() - if dist.key == 'setuptools': - # Ensure that setuptools itself never becomes unavailable! - # XXX should this check for latest version? - filename = os.path.join(self.install_dir, 'setuptools.pth') - if os.path.islink(filename): - os.unlink(filename) - f = open(filename, 'wt') - f.write(self.pth_file.make_relative(dist.location) + '\n') - f.close() + if dist.key != 'setuptools': + return + + # Ensure that setuptools itself never becomes unavailable! + # XXX should this check for latest version? + filename = os.path.join(self.install_dir, 'setuptools.pth') + if os.path.islink(filename): + os.unlink(filename) + with open(filename, 'wt') as f: + f.write(self.pth_file.make_relative(dist.location) + '\n') def unpack_progress(self, src, dst): # Progress filter for unpacking |