From e0dd4c969515bf64ef3fcfe4bfb60efcfbecc599 Mon Sep 17 00:00:00 2001 From: Viacheslav Greshilov Date: Wed, 3 Mar 2021 02:16:38 +0200 Subject: [PATCH] fixup! fixup! fixup! Complete pip-tools setup (#5486) --- tools/deps.py | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/tools/deps.py b/tools/deps.py index ffdf074be8f..e0d8a45044d 100755 --- a/tools/deps.py +++ b/tools/deps.py @@ -61,18 +61,23 @@ def install_dependencies(in_name): def replace_duplicates_with_symlinks(): hash_to_file = collections.defaultdict(list) - for txt_file_name in PIN_FOLDER.glob("*.txt"): - if not txt_file_name.is_symlink(): - with open(txt_file_name, "rb") as f: - digest = hashlib.sha1(f.read()).hexdigest() - hash_to_file[digest].append(txt_file_name) - - for digest, files in hash_to_file.items(): - if len(files) > 1: - base_file, *other_files = files - for other_file in other_files: - os.unlink(other_file) - os.symlink(base_file, other_file) + orig_dir = os.getcwd() + os.chdir(PIN_FOLDER) + try: + for txt_fname in pathlib.Path(".").glob("*.txt"): + if not txt_fname.is_symlink(): + with open(txt_fname, "rb") as f: + digest = hashlib.sha1(f.read()).hexdigest() + hash_to_file[digest].append(txt_fname) + + for digest, files in hash_to_file.items(): + if len(files) > 1: + base_file, *other_files = files + for other_file in other_files: + os.unlink(other_file) + os.symlink(base_file, other_file) + finally: + os.chdir(orig_dir) if __name__ == "__main__":