Prhub

#41377 [CI/Build] Skip terratorch + torchgeo while PyPI has lightning quarantined

原始 PR 作者 stecasta 合并时间 2026-04-30 22:59 文件变更 8 提交数 2 评论 1 代码增减 +63 / -542

执行摘要

临时注释 terratorch 依赖修复 pip-compile 失败

PyPI 将 lightning 项目标记为 quarantined(无发布文件暴露),导致 terratorchtorchgeo 传递依赖 lightning 解析失败,约一半 PR 的 pip-compile 预提交钩子报错(详见 issue #41376)。此 PR 提供临时 workaround 恢复 CI 稳定性。

建议精读此 PR 以学习如何优雅处理外部依赖中断:使用 pytest.importorskip 或模块级 find_spec + skipif 跳过测试,并添加清晰注释和关联 issue 以便后续恢复。该模式可在其他类似场景复用。

讨论亮点

PR 获得简化批准:DarkLight1337 批准,Gemini Code Assist 机器人确认了必要性但未提供额外反馈。没有实质性讨论,整体被视作直接的外因 workaround。

实现拆解

按以下 5 步实现:

  1. requirements/test/cuda.in 中注释掉 terratorch>=1.2.2 依赖行,添加注释指向 issue #41376 以便后续恢复。
  2. requirements/test/rocm.in 中注释掉 terratorch>=1.2.2torchgeo==0.7.0(后者也传递依赖 lightning),同样添加恢复指引注释。
  3. 重新运行 pip-compilepip-compile-rocm 预提交钩子,自动更新 cuda.txtrocm.txt 锁文件,移除了 terratorch 及其大量传递依赖。
  4. 在四个测试文件中添加跳过逻辑:tests/models/test_terratorch.pytests/plugins_tests/test_terratorch_io_processor_plugins.pytests/models/multimodal/pooling/test_prithvi_mae.py 使用模块级 pytest.importorskip("terratorch")tests/entrypoints/openai/chat_completion/test_vision_embeds.py 使用 importlib.util.find_spec@pytest.mark.skipif 装饰器,仅跳过需要 terratorch 的 Prithvi 测试用例,不影响同文件中其他模型(如 Qwen3-VL)的测试。
  5. 验证 pip-compilepip-compile-rocmpip-compile-xpu 三个预提交钩子均通过,且 grep 确认 terratorchtorchgeo 已从锁文件中移除。
文件 模块 状态 重要度
requirements/test/cuda.in CUDA 依赖 modified 4.15
requirements/test/rocm.in ROCm 依赖 modified 4.27
tests/models/test_terratorch.py Terratorch 测试 modified 4.27
tests/entrypoints/openai/chat_completion/test_vision_embeds.py 视觉嵌入测试 modified 4.27
requirements/test/cuda.txt 锁文件 modified 3.83

关键源码片段

requirements/test/cuda.in configuration

CUDA 测试依赖入口文件,注释掉 terratorch 依赖行以绕过 PyPI quarantine,是本次变更的核心触发点。

# Prithvi tests
# terratorch 暂时禁用,因为 PyPI 上的 `lightning` 包处于 quarantine 状态
# (每个已发布的 terratorch 版本都传递依赖 lightning,导致解析器报错
# “no versions of lightning”)。当 PyPI 解除 quarantine 后重新启用。
# 跟踪 issue:#41376。
# terratorch>=1.2.2
imagehash # Required for Prithvi tests
segmentation-models-pytorch>0.4.0 # Required for Prithvi tests
tests/models/test_terratorch.py test-coverage

测试文件,添加 importorskip 确保 terratorch 未安装时测试被优雅跳过而非报错。

import pytest
import torchfrom tests.conftest import VllmRunner
from tests.utils import create_new_process_for_each_test# 如果 terratorch 未安装,跳过模块中所有测试
pytest.importorskip(
    "terratorch",
    reason="terratorch 不可用,因为 PyPI 上的 `lightning` 被隔离(见 #41376)",
)@create_new_process_for_each_test() # Hangs otherwise
@pytest.mark.parametrize(
    "model",
    [
        "ibm-nasa-geospatial/Prithvi-EO-2.0-300M-TL-Sen1Floods11",
        "ibm-nasa-geospatial/Prithvi-EO-2.0-300M-BurnScars",
    ],
)
def test_inference(
    vllm_runner: type[VllmRunner],
    model: str,
) -> None:
    # ... 测试体保持不变 ...
tests/entrypoints/openai/chat_completion/test_vision_embeds.py test-coverage

测试文件,添加 skipif 装饰器仅跳过 Prithvi 测试用例,不干扰同文件中其他模型。

import importlib.util
import numpy as np
import pybase64 as base64
import pytest
import requests
import torchfrom tests.utils import RemoteOpenAIServer
from vllm.utils.serial_utils import tensor2base64# Prithvi 需要 terratorch,它在 PyPI 上的 `lightning` 被隔离期间不可用。
# 仅跳过 Prithvi 用例,同文件中的 Qwen3-VL 用例不受影响。
_TERRATORCH_AVAILABLE = importlib.util.find_spec("terratorch") is not None@pytest.mark.skipif(
    not _TERRATORCH_AVAILABLE,
    reason="terratorch 不可用,因为 PyPI 上的 `lightning` 被隔离(见 #41376)",
)
@pytest.mark.parametrize(
    "model_name", ["ibm-nasa-geospatial/Prithvi-EO-2.0-300M-TL-Sen1Floods11"]
)
def test_single_content(model_name: str):
    # ... 测试体保持不变 ...

评论区精华

没有提炼出高价值讨论线程

当前评论区没有形成足够清晰的争议点或结论,后续有更多讨论时会体现在这里。

风险与影响

临时注释依赖可能被遗忘,导致 Prithvi 模型测试覆盖率长期缺失;但 PR 中添加了指向 issue #41376 的注释,便于追踪恢复。测试跳过逻辑使用标准 pytest.importorskipskipif,确保测试集不会因缺失依赖而报错。此外,torchgeo 在 ROCm 环境下被注释,可能影响相关测试,但 torchgeo 当前仅用于测试。总体风险低,但需团队在 PyPI 解除隔离后及时恢复。

直接影响 CI 构建:修复了约半数 PR 因 pip-compile 失败导致的预提交失败,恢复 CI 稳定性。对用户无影响(terratorch 为可选运行时依赖,且从锁文件中移除后不会影响生产镜像构建)。团队需关注 issue #41376 的进展以移除临时 workaround。

临时 Workaround 可能被遗忘 Prithvi 测试覆盖暂时丢失

关联 Issue

#41376 [CI/Build] pre-commit pip-compile fails for ~half of recent PRs: PyPI quarantined the `lightning` project

完整报告

参与讨论