)]}'
{
  "commit": "84351d4ec14e474bc196c0b8cd70e04fcc9a25ca",
  "tree": "c71409cfe08de2b40d4bb430cc8cc98ebbc4ec6f",
  "parents": [
    "6e2d493f3e8e12c7cf208a4e9a398c5eabb65f24"
  ],
  "author": {
    "name": "Elvis M. Wianda",
    "email": "7077790+ewianda@users.noreply.github.com",
    "time": "Fri Apr 11 17:18:46 2025 -0600"
  },
  "committer": {
    "name": "GitHub",
    "email": "noreply@github.com",
    "time": "Fri Apr 11 23:18:46 2025 +0000"
  },
  "message": "fix: Resolve incorrect platform specific dependency (#2766)\n\nThis change addresses a bug where `pip.parse` selects the wrong\nrequirement entry when multiple extras are listed with platform-specific\nmarkers.\n\n#### 🔍 Problem:\nIn a `requirements.txt` generated by tools like `uv` or `poetry`, it\u0027s\nvalid to have multiple entries for the same package, each with different\nextras and `sys_platform` markers, for example:\n\n```ini\noptimum[onnxruntime]\u003d\u003d1.17.1 ; sys_platform \u003d\u003d \u0027darwin\u0027\noptimum[onnxruntime-gpu]\u003d\u003d1.17.1 ; sys_platform \u003d\u003d \u0027linux\u0027\n```\n\nThe current implementation in\n[`[parse_requirements.bzl](https://github.com/bazel-contrib/rules_python/blob/032f6aa738a673b13b605dabf55465c6fc1a56eb/python/private/pypi/parse_requirements.bzl#L114-L126)`](https://github.com/bazel-contrib/rules_python/blob/032f6aa738a673b13b605dabf55465c6fc1a56eb/python/private/pypi/parse_requirements.bzl#L114-L126)\nuses a sort-by-length heuristic to select the “best” requirement when\nthere are multiple entries with the same base name. This works well in\nlegacy `requirements.txt` files where:\n```\nmy_dep\nmy_dep[foo]\nmy_dep[foo,bar]\n```\n...would indicate an intent to select the **most specific subset of\nextras** (i.e. the longest name).\n\nHowever, this heuristic **breaks** in the presence of **platform\nmarkers**, where extras are **not subsets**, but distinct variants. In\nthe example above, Bazel mistakenly selects `optimum[onnxruntime-gpu]`\non macOS because it\u0027s a longer match, even though it is guarded by a\nLinux-only marker.\n\n#### ✅ Fix:\nThis PR modifies the behavior to:\n1. **Add the requirement marker** as part of the sorting key.\n2. **Then apply the longest-match logic** to drop duplicate requirements\nwith different extras but the same markers.\n\nThis ensures that only applicable requirements are considered during\nresolution, preserving correctness in multi-platform environments.\n\n#### 🧪 Before:\nOn macOS, the following entry is incorrectly selected:\n```\noptimum[onnxruntime-gpu]\u003d\u003d1.17.1 ; sys_platform \u003d\u003d \u0027linux\u0027\n```\n\n#### ✅ After:\nCorrect entry is selected:\n```\noptimum[onnxruntime]\u003d\u003d1.17.1 ; sys_platform \u003d\u003d \u0027darwin\u0027\n```\n\nclose https://github.com/bazel-contrib/rules_python/issues/2690\n\n---------\n\nCo-authored-by: Ignas Anikevicius \u003c240938+aignas@users.noreply.github.com\u003e",
  "tree_diff": [
    {
      "type": "modify",
      "old_id": "f38732f7d844a3cfab9fe77c16c6a1b6b3304238",
      "old_mode": 33188,
      "old_path": "CHANGELOG.md",
      "new_id": "7d9b648bea76574aec69408fa175b9fca1279b07",
      "new_mode": 33188,
      "new_path": "CHANGELOG.md"
    },
    {
      "type": "modify",
      "old_id": "d2014a7eb930bb417d15e217e48317da89f00622",
      "old_mode": 33188,
      "old_path": "python/private/pypi/parse_requirements.bzl",
      "new_id": "1cbf094f5cb7ddd6fdb17f3d50acf0d7e6955802",
      "new_mode": 33188,
      "new_path": "python/private/pypi/parse_requirements.bzl"
    },
    {
      "type": "modify",
      "old_id": "11f2b3e8fa435a30e479da89c231461a6052d28a",
      "old_mode": 33188,
      "old_path": "python/private/pypi/pep508_requirement.bzl",
      "new_id": "ee7b5dfc351b45388f6af051dfffd889474dbefa",
      "new_mode": 33188,
      "new_path": "python/private/pypi/pep508_requirement.bzl"
    },
    {
      "type": "modify",
      "old_id": "1652e7615678ce1876ac09f9802c886515dfd572",
      "old_mode": 33188,
      "old_path": "tests/pypi/extension/extension_tests.bzl",
      "new_id": "66c9e0549e53e1b8320772bda852adced08eaa23",
      "new_mode": 33188,
      "new_path": "tests/pypi/extension/extension_tests.bzl"
    },
    {
      "type": "modify",
      "old_id": "7c81ea50fc7e1655902fb60ea84c1f4e41949eee",
      "old_mode": 33188,
      "old_path": "tests/pypi/pep508/requirement_tests.bzl",
      "new_id": "9afb43a4374e60351bdd7c03e1b0967d7181a85a",
      "new_mode": 33188,
      "new_path": "tests/pypi/pep508/requirement_tests.bzl"
    }
  ]
}
