【问题标题】:How to get latest sdist link from PyPI如何从 PyPI 获取最新的 sdist 链接
【发布时间】:2020-01-18 09:00:55
【问题描述】:

我想在 conda 构建配方中获取 meta.yaml 的 sdist url。它需要从 URL 获取特定版本或最新版本。当我对 CI/CD 使用 Github 操作时,我需要自动检索特定版本或最新版本的源链接。

现在链接是这样的:https://files.pythonhosted.org/packages/40/e7/sha-256-of-file/file我需要可靠的东西,比如https://hosting/package/release/file

我需要知道一种更可靠的方法来检索特定版本的最新 sdist 或 sdist。有没有办法做到这一点,或者我需要走另一条路?

Is there a PyPi source download link that always points to the lastest version?

到目前为止,这个问题对我不起作用,因为我不打算在 python 中安装它。我需要将它包含在 conda-build 的 meta.yaml 配方中。

meta.yaml 看起来像这样:

{% set version = "0.1.1rc3" %}

package:
  name: blablablah
  version: {{ version }}

source:
  url: 
  sha256: f3832918bc3c66617f92e35f5d70729187676313caa60c187eb0f28b8fe5e3b5

build:
  noarch: python
  number: 0
  script: python -m pip install --no-deps --ignore-installed .

requirements:
  host:
    - python
    - pip
    - numpy==1.16.5
    - cython
  run:
    - python

test:
  imports:
    - blablablah

about:
   here are information about the package

我不知道从哪里获取此文件,因为代码每小时更新一次,并且无法手动升级。

【问题讨论】:

标签: python pypi


【解决方案1】:

如果您知道确切的项目名称和版本,则可以使用以下 URL 结构:

project_name = "..."
version = "..."
url = f"https://files.pythonhosted.org/packages/source/{project_name[0]}/{project_name}/{project_name}-{version}.tar.gz

例如

https://files.pythonhosted.org/packages/source/p/pip/pip-20.0.1.tar.gz

如果不知道最新版本,可以使用PyPI JSON API获取:

>>> import requests
>>> resp = requests.get('https://pypi.org/pypi/pip/json').json()
>>> resp['info']['version']
'20.0.1'

注意:不能保证给定版本的源代码分发存在,尽管有可能。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-25
    • 1970-01-01
    • 2021-09-05
    • 2017-05-26
    • 1970-01-01
    • 2012-12-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多