Python打包:在`conda``meta.yaml`文件中创建对`conda-forge`包的依赖 [英] Python Packaging: Creating a dependency on a `conda-forge` package in `conda` `meta.yaml` file

查看:30
本文介绍了Python打包:在`conda``meta.yaml`文件中创建对`conda-forge`包的依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为conda-forge编写包,需要指定对另一个conda-forge依赖项的依赖项。实际上,我需要安装conda-forgegdal包的固定版本,因为它实际上编译了支持BIGTIFF文件的libtiff版本.

现在,如果我要将gdal安装到conda环境中,我会编写如下内容。

conda install -c conda-forge gdal=2.4.4 
我希望在安装软件包时从conda-forge安装此版本的gdal=2.4.4。现在,在meta.yaml文件中,我可以这样指定包依赖项,但是我不知道如何指定tar文件的URL或任何可以使用的方法。

{% set version = "0.0.1" %}

package:
  name: mypackage
  version: {{ version }}

source:
  url: https://github.com/myrepo/{{ version }}.tar.gz
  sha256: ****6a63

build:
  number: 1
  skip: true  # [win and py27]
  entry_points:
    - mycli = mypackage.main:main

requirements:
  build:
    - python
    - 
  host:
    - python
    - pip
    - numpy
    - gdal  # <----- want to specify from conda-forge
  run:
    - python
    - gdal  # <----- want to specify from conda-forge

如有任何有关如何执行此操作的建议,我们将不胜感激。

推荐答案

我认为无法在meta.yaml中指定频道。以下问题在CONDA-Build问题跟踪器中仍未解决: https://github.com/conda/conda-build/issues/532

作为一种解决办法,如果您知道所需的gdal的确切版本,则可以在配方中指定确切的版本和";内部版本字符串";。

唯一令人讨厌的是,对于您的菜谱需要支持的每个平台和python版本组合,您必须列出gdal一次。

requirements:
  build:
    - python
    - 
  host:
    - python
    - pip
    - numpy
    - gdal  2.4.4 py36h02fde04_1  # [osx and py==36]
    - gdal  2.4.4 py37h622575a_1  # [osx and py==37]
    - gdal  2.4.4 py38h57202bd_1  # [osx and py==38]
    - gdal  2.4.4 py36hbb8311d_1  # [linux and py==36]
    - gdal  2.4.4 py37hf8c3989_1  # [linux and py==37]
    - gdal  2.4.4 py38hfe926b7_1  # [linux and py==38]

  run:
    - python
    - gdal  2.4.4 py36h02fde04_1  # [osx and py==36]
    - gdal  2.4.4 py37h622575a_1  # [osx and py==37]
    - gdal  2.4.4 py38h57202bd_1  # [osx and py==38]
    - gdal  2.4.4 py36hbb8311d_1  # [linux and py==36]
    - gdal  2.4.4 py37hf8c3989_1  # [linux and py==37]
    - gdal  2.4.4 py38hfe926b7_1  # [linux and py==38]

(我从gdal package listing on the conda-forge channel复制了这些内容。)

顺便说一下,既然您提到对您来说真正重要的区别是libtiff,那么您是否应该钉住libtiff而不是gdal?或者两者兼而有之?


编辑:

最好避免在hostrun部分中重复生成字符串的整个列表。

按照您在注释中的建议,一种选择是在conda_build_config.yaml中定义构建字符串:

# conda_build_config.yaml
gdal_build:
  - py36h02fde04_1  # [osx and py==36]
  - py37h622575a_1  # [osx and py==37]
  - py38h57202bd_1  # [osx and py==38]
  - py36hbb8311d_1  # [linux and py==36]
  - py37hf8c3989_1  # [linux and py==37]
  - py38hfe926b7_1  # [linux and py==38]
# meta.yaml
requirements:
  build:
    - python
    - 
  host:
    - python
    - pip
    - numpy
    - gdal  2.4.4 {{ gdal_build }}

  run:
    - python
    - gdal  2.4.4 {{ gdal_build }}

另一种选择是直接在meta.yaml中在JJJA变量中定义查找表。这可能稍微难看一些,但至少所有逻辑都包含在单个文件中。我不确定更喜欢哪一个。

{% set platform = 'linux' if linux else 'osx' if osx else 'win' %}

{%
  set gdal_builds = {
    'osx': {
      36: 'py36h02fde04_1',
      37: 'py37h622575a_1',
      38: 'py38h57202bd_1',
    },
    'linux': {
      36: 'py36hbb8311d_1',
      37: 'py37hf8c3989_1',
      38: 'py38hfe926b7_1',
    }
  }
%}

requirements:
  build:
    - python
    - 
  host:
    - python
    - pip
    - numpy
    - gdal  2.4.4 {{ gdal_builds[platform][py] }}

  run:
    - python
    - gdal  2.4.4 {{ gdal_builds[platform][py] }}

这篇关于Python打包:在`conda``meta.yaml`文件中创建对`conda-forge`包的依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆