From 220c5aa93fdfbea18508e98a933055d6dbbf6216 Mon Sep 17 00:00:00 2001
From: Peter Hawkins <phawkins@google.com>
Date: Fri, 20 Dec 2024 17:42:48 -0800
Subject: [PATCH] Update packaging and pip versions in rules_python to enable
 freethreading support.

The same change has been sent upstream as https://github.com/bazelbuild/rules_python/pull/2514

Forked from https://github.com/openxla/xla/pull/20723 for merging.

PiperOrigin-RevId: 708471912
---
 third_party/py/python_init_rules.bzl          |  2 +
 third_party/py/rules_python.patch             | 39 +++++++++++++++++++
 .../tsl/third_party/py/python_init_rules.bzl  |  2 +
 .../tsl/third_party/py/rules_python.patch     | 39 +++++++++++++++++++
 4 files changed, 82 insertions(+)
 create mode 100644 third_party/py/rules_python.patch
 create mode 100644 third_party/tsl/third_party/py/rules_python.patch

diff --git a/third_party/py/python_init_rules.bzl b/third_party/py/python_init_rules.bzl
index 79bc343aae489..796ae3d92d999 100644
--- a/third_party/py/python_init_rules.bzl
+++ b/third_party/py/python_init_rules.bzl
@@ -8,4 +8,6 @@ def python_init_rules():
         sha256 = "62ddebb766b4d6ddf1712f753dac5740bea072646f630eb9982caa09ad8a7687",
         strip_prefix = "rules_python-0.39.0",
         url = "https://github.com/bazelbuild/rules_python/releases/download/0.39.0/rules_python-0.39.0.tar.gz",
+        patch_args = ["-p1"],
+        patches = [Label("//third_party/py:rules_python.patch")],
     )
diff --git a/third_party/py/rules_python.patch b/third_party/py/rules_python.patch
new file mode 100644
index 0000000000000..ef7ff2fc6f8e5
--- /dev/null
+++ b/third_party/py/rules_python.patch
@@ -0,0 +1,39 @@
+diff --git a/python/private/pypi/deps.bzl b/python/private/pypi/deps.bzl
+index 8949ed4a..8d0ab0e7 100644
+--- a/python/private/pypi/deps.bzl
++++ b/python/private/pypi/deps.bzl
+@@ -51,8 +51,8 @@ _RULE_DEPS = [
+     ),
+     (
+         "pypi__packaging",
+-        "https://files.pythonhosted.org/packages/49/df/1fceb2f8900f8639e278b056416d49134fb8d84c5942ffaa01ad34782422/packaging-24.0-py3-none-any.whl",
+-        "2ddfb553fdf02fb784c234c7ba6ccc288296ceabec964ad2eae3777778130bc5",
++        "https://files.pythonhosted.org/packages/88/ef/eb23f262cca3c0c4eb7ab1933c3b1f03d021f2c48f54763065b6f0e321be/packaging-24.2-py3-none-any.whl",
++        "09abb1bccd265c01f4a3aa3f7a7db064b36514d2cba19a2f694fe6150451a759",
+     ),
+     (
+         "pypi__pep517",
+@@ -61,8 +61,8 @@ _RULE_DEPS = [
+     ),
+     (
+         "pypi__pip",
+-        "https://files.pythonhosted.org/packages/8a/6a/19e9fe04fca059ccf770861c7d5721ab4c2aebc539889e97c7977528a53b/pip-24.0-py3-none-any.whl",
+-        "ba0d021a166865d2265246961bec0152ff124de910c5cc39f1156ce3fa7c69dc",
++        "https://files.pythonhosted.org/packages/ef/7d/500c9ad20238fcfcb4cb9243eede163594d7020ce87bd9610c9e02771876/pip-24.3.1-py3-none-any.whl",
++        "3790624780082365f47549d032f3770eeb2b1e8bd1f7b2e02dace1afa361b4ed",
+     ),
+     (
+         "pypi__pip_tools",
+diff --git a/python/private/pypi/evaluate_markers.bzl b/python/private/pypi/evaluate_markers.bzl
+index c805fd7a..e57e6138 100644
+--- a/python/private/pypi/evaluate_markers.bzl
++++ b/python/private/pypi/evaluate_markers.bzl
+@@ -20,7 +20,7 @@ load(":pypi_repo_utils.bzl", "pypi_repo_utils")
+ SRCS = [
+     # When the version, or any of the files in `packaging` package changes,
+     # this file will change as well.
+-    Label("@pypi__packaging//:packaging-24.0.dist-info/RECORD"),
++    Label("@pypi__packaging//:packaging-24.2.dist-info/RECORD"),
+     Label("//python/private/pypi/requirements_parser:resolve_target_platforms.py"),
+     Label("//python/private/pypi/whl_installer:platform.py"),
+ ]
\ No newline at end of file
diff --git a/third_party/tsl/third_party/py/python_init_rules.bzl b/third_party/tsl/third_party/py/python_init_rules.bzl
index 79bc343aae489..796ae3d92d999 100644
--- a/third_party/tsl/third_party/py/python_init_rules.bzl
+++ b/third_party/tsl/third_party/py/python_init_rules.bzl
@@ -8,4 +8,6 @@ def python_init_rules():
         sha256 = "62ddebb766b4d6ddf1712f753dac5740bea072646f630eb9982caa09ad8a7687",
         strip_prefix = "rules_python-0.39.0",
         url = "https://github.com/bazelbuild/rules_python/releases/download/0.39.0/rules_python-0.39.0.tar.gz",
+        patch_args = ["-p1"],
+        patches = [Label("//third_party/py:rules_python.patch")],
     )
diff --git a/third_party/tsl/third_party/py/rules_python.patch b/third_party/tsl/third_party/py/rules_python.patch
new file mode 100644
index 0000000000000..ef7ff2fc6f8e5
--- /dev/null
+++ b/third_party/tsl/third_party/py/rules_python.patch
@@ -0,0 +1,39 @@
+diff --git a/python/private/pypi/deps.bzl b/python/private/pypi/deps.bzl
+index 8949ed4a..8d0ab0e7 100644
+--- a/python/private/pypi/deps.bzl
++++ b/python/private/pypi/deps.bzl
+@@ -51,8 +51,8 @@ _RULE_DEPS = [
+     ),
+     (
+         "pypi__packaging",
+-        "https://files.pythonhosted.org/packages/49/df/1fceb2f8900f8639e278b056416d49134fb8d84c5942ffaa01ad34782422/packaging-24.0-py3-none-any.whl",
+-        "2ddfb553fdf02fb784c234c7ba6ccc288296ceabec964ad2eae3777778130bc5",
++        "https://files.pythonhosted.org/packages/88/ef/eb23f262cca3c0c4eb7ab1933c3b1f03d021f2c48f54763065b6f0e321be/packaging-24.2-py3-none-any.whl",
++        "09abb1bccd265c01f4a3aa3f7a7db064b36514d2cba19a2f694fe6150451a759",
+     ),
+     (
+         "pypi__pep517",
+@@ -61,8 +61,8 @@ _RULE_DEPS = [
+     ),
+     (
+         "pypi__pip",
+-        "https://files.pythonhosted.org/packages/8a/6a/19e9fe04fca059ccf770861c7d5721ab4c2aebc539889e97c7977528a53b/pip-24.0-py3-none-any.whl",
+-        "ba0d021a166865d2265246961bec0152ff124de910c5cc39f1156ce3fa7c69dc",
++        "https://files.pythonhosted.org/packages/ef/7d/500c9ad20238fcfcb4cb9243eede163594d7020ce87bd9610c9e02771876/pip-24.3.1-py3-none-any.whl",
++        "3790624780082365f47549d032f3770eeb2b1e8bd1f7b2e02dace1afa361b4ed",
+     ),
+     (
+         "pypi__pip_tools",
+diff --git a/python/private/pypi/evaluate_markers.bzl b/python/private/pypi/evaluate_markers.bzl
+index c805fd7a..e57e6138 100644
+--- a/python/private/pypi/evaluate_markers.bzl
++++ b/python/private/pypi/evaluate_markers.bzl
+@@ -20,7 +20,7 @@ load(":pypi_repo_utils.bzl", "pypi_repo_utils")
+ SRCS = [
+     # When the version, or any of the files in `packaging` package changes,
+     # this file will change as well.
+-    Label("@pypi__packaging//:packaging-24.0.dist-info/RECORD"),
++    Label("@pypi__packaging//:packaging-24.2.dist-info/RECORD"),
+     Label("//python/private/pypi/requirements_parser:resolve_target_platforms.py"),
+     Label("//python/private/pypi/whl_installer:platform.py"),
+ ]
\ No newline at end of file