是什么决定了哪个索引`pip`将使用?

时间:2017-03-07 18:53:34

标签: python pip python-wheel

我希望pip从我的驾驶室安装车轮,然后回退到PyPI(通过高速缓存代理)当且仅当驾驶室缺少车轮时。

我试图通过调用

来实现这一目标
pip install -U --index-url $PYPI_PROXY_URL --find-links $WHEELHOUSE_URL \
            -r requirements.txt

然而,尽管驾驶室拥有所有必需的包裹,但它们来自它的地方似乎是非常随机的,它们来自它们,代理PyPI或驾驶室,而不是确定性。

我希望这是确定性的,并且总是首先选择驾驶室。如何使用pip实现这一目标?

我知道--no-index会迫使它只使用驾驶室,但我想保留对驾驶室中丢失的包裹进行后备的能力。

1 个答案:

答案 0 :(得分:1)

深入研究pip的源代码我发现:

  1. 使用内部_candidate_sort_key函数对有效候选项进行排序,其工作方式如下:

        If not finding wheels, then sorted by version only.
        If finding wheels, then the sort order is by version, then:
          1. existing installs
          2. wheels ordered via Wheel.support_index_min(self.valid_tags)
          3. source archives
        Note: it was considered to embed this logic into the Link
              comparison operators, but then different sdist links
              with the same version, would have to be considered equal
    
  2. 在其他条件相同的情况下,它会回退到hardcoded顺序,即:

    1. 本地文件系统
    2. 索引网址
    3. 查找链接网址
    4. 依赖关系链接网址
  3. 从点子9.0.1开始,上面的顺序是硬编码的,因此无法使用设置或参数对其进行更改。