From 452f59c92bb468c7a09bf4db9068bf3f1b95ab51 Mon Sep 17 00:00:00 2001 From: Ben Dunkin Date: Thu, 28 Nov 2024 15:59:23 -0800 Subject: [PATCH 1/5] click commands will exit the whole program after being called if 'standalone_mode = False' is not passed. On linux, this ended up not mattering because the file written to by pip_compile is a symlink to the file in the source tree. Symlinks are disabled by default on windows, so it writes to a new file in the runfiles tree but doesn't copy back to the source tree because the program exits. --- python/private/pypi/dependency_resolver/dependency_resolver.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/private/pypi/dependency_resolver/dependency_resolver.py b/python/private/pypi/dependency_resolver/dependency_resolver.py index 0ff9b2fb7c..0e73e11102 100644 --- a/python/private/pypi/dependency_resolver/dependency_resolver.py +++ b/python/private/pypi/dependency_resolver/dependency_resolver.py @@ -182,7 +182,7 @@ def main( resolved_requirements_file, requirements_file_tree ) ) - cli(argv) + cli(argv, standalone_mode = False) requirements_file_relative_path = Path(requirements_file_relative) content = requirements_file_relative_path.read_text() content = content.replace(absolute_path_prefix, "") From 5f915e916e0285c5c25c16fa1bb05b0be2c6dcc4 Mon Sep 17 00:00:00 2001 From: Ben Dunkin Date: Thu, 28 Nov 2024 16:04:38 -0800 Subject: [PATCH 2/5] Populating the runfiles tree is disabled by default on windows (ie --noenable_runfiles). This means the runfiles library resolves the requirements_file to the file in the source tree (ie resolved_requirements_file is the absolute path to the file in the source tree, not to a file in the runfiles directory). pip_compile is told to output to a relative path, which means it will output to a file in the runfiles directory. The check to see if we need to copy that file to the source tree was incorrect because it didn't check to see if the file output by pip_compile was the same as the one in the source tree, it checked if the resolved file was the same as the one in the source tree. Since the resolved file IS the same as the one in the source tree, it never copied, but the resolved file is not the file that pip_compile output to. --- .../private/pypi/dependency_resolver/dependency_resolver.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/python/private/pypi/dependency_resolver/dependency_resolver.py b/python/private/pypi/dependency_resolver/dependency_resolver.py index 0e73e11102..f98ed08168 100644 --- a/python/private/pypi/dependency_resolver/dependency_resolver.py +++ b/python/private/pypi/dependency_resolver/dependency_resolver.py @@ -173,13 +173,14 @@ def main( if "BUILD_WORKSPACE_DIRECTORY" in os.environ: workspace = os.environ["BUILD_WORKSPACE_DIRECTORY"] requirements_file_tree = os.path.join(workspace, requirements_file_relative) + absolute_output_file = Path(requirements_file_relative).absolute() # In most cases, requirements_file will be a symlink to the real file in the source tree. # If symlinks are not enabled (e.g. on Windows), then requirements_file will be a copy, # and we should copy the updated requirements back to the source tree. - if not os.path.samefile(resolved_requirements_file, requirements_file_tree): + if not absolute_output_file.samefile(requirements_file_tree): atexit.register( lambda: shutil.copy( - resolved_requirements_file, requirements_file_tree + absolute_output_file, requirements_file_tree ) ) cli(argv, standalone_mode = False) From 1a6c903f969c936b612eb7edcbdeffef23f93ee9 Mon Sep 17 00:00:00 2001 From: Ben Dunkin Date: Thu, 28 Nov 2024 16:37:15 -0800 Subject: [PATCH 3/5] Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cc66afa510..9ac01ea73e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -95,6 +95,8 @@ Other changes: ([2169](https://github.com/bazelbuild/rules_python/issues/2169)). * (workspace) Corrected protobuf's name to com_google_protobuf, the name is hardcoded in Bazel, WORKSPACE mode. +* (pypi): compile_pip_requirements no longer fails on Windows when --enable_runfiles is not enabled +* (pypi): compile_pip_requirements now correctly updates files in the source tree on Windows when --windows_enable_symlinks is not enabled {#v0-0-0-added} ### Added From 3b41efeea6629beab53d4e568092510dc33b6893 Mon Sep 17 00:00:00 2001 From: Ben Dunkin Date: Thu, 28 Nov 2024 17:24:53 -0800 Subject: [PATCH 4/5] pip_compile requires that the file exist --- .../private/pypi/dependency_resolver/dependency_resolver.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/python/private/pypi/dependency_resolver/dependency_resolver.py b/python/private/pypi/dependency_resolver/dependency_resolver.py index f98ed08168..293377dc6d 100644 --- a/python/private/pypi/dependency_resolver/dependency_resolver.py +++ b/python/private/pypi/dependency_resolver/dependency_resolver.py @@ -170,6 +170,12 @@ def main( if UPDATE: print("Updating " + requirements_file_relative) + + # Make sure the output file for pip_compile exists. It won't if we are on Windows and --enable_runfiles is not set. + if not os.path.exists(requirements_file_relative): + os.makedirs(os.path.dirname(requirements_file_relative), exist_ok=True) + shutil.copy(resolved_requirements_file, requirements_file_relative) + if "BUILD_WORKSPACE_DIRECTORY" in os.environ: workspace = os.environ["BUILD_WORKSPACE_DIRECTORY"] requirements_file_tree = os.path.join(workspace, requirements_file_relative) From 727379a893e6940a20a4633d9fa78c9a4193d404 Mon Sep 17 00:00:00 2001 From: Ben Dunkin Date: Fri, 29 Nov 2024 11:25:48 -0800 Subject: [PATCH 5/5] Update CHANGELOG.md with better syntax highlighting Co-authored-by: Ignas Anikevicius <240938+aignas@users.noreply.github.com> --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ac01ea73e..64e9e5a878 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -95,8 +95,8 @@ Other changes: ([2169](https://github.com/bazelbuild/rules_python/issues/2169)). * (workspace) Corrected protobuf's name to com_google_protobuf, the name is hardcoded in Bazel, WORKSPACE mode. -* (pypi): compile_pip_requirements no longer fails on Windows when --enable_runfiles is not enabled -* (pypi): compile_pip_requirements now correctly updates files in the source tree on Windows when --windows_enable_symlinks is not enabled +* (pypi): {bzl:obj}`compile_pip_requirements` no longer fails on Windows when `--enable_runfiles` is not enabled. +* (pypi): {bzl:obj}`compile_pip_requirements` now correctly updates files in the source tree on Windows when `--windows_enable_symlinks` is not enabled. {#v0-0-0-added} ### Added