简体   繁体   English

Python 打包:在 `conda` `meta.yaml` 文件中创建对`conda-forge` package 的依赖

[英]Python Packaging: Creating a dependency on a `conda-forge` package in `conda` `meta.yaml` file

I am writing a package for conda-forge and needed to specify a dependency on another conda-forge dependency.我正在为 conda conda-forge forge 编写 package 并且需要指定对另一个conda-forge -forge 依赖项的依赖项。 Essentially, I need to install a pinned version of the conda-forge gdal package, because it actually compiles the version of libtiff that supports BIGTIFF files....本质上,我需要安装 conda conda-forge forge gdal package 的固定版本,因为它实际上编译了支持 BIGTIFF 文件的libtiff版本....

Now if I was installing gdal into a conda environment, I would write something like.现在,如果我将gdal安装到conda环境中,我会写类似的东西。

conda install -c conda-forge gdal=2.4.4 

I would to get this version of gdal=2.4.4 from conda-forge installed when installing the package.在安装 package 时,我会从conda-forge forge 安装此版本的gdal=2.4.4 Now in the meta.yaml file, I can specify package dependencies like so, but I did not see how to specify a URL to a tar file, or whatever would work.现在在meta.yaml文件中,我可以像这样指定 package 依赖项,但我没有看到如何将 URL 指定到 tar 文件中。

{% 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

Any suggestions about how to do this would be appreciated.任何有关如何执行此操作的建议将不胜感激。

I don't think it's possible to specify the channel in meta.yaml .我认为不可能在meta.yaml中指定频道。 The following issue is still unresolved in the conda-build issue tracker: https://github.com/conda/conda-build/issues/532 conda-build 问题跟踪器中仍未解决以下问题: https://github.com/conda/conda-build/issues/532

As a workaround, if you know the exact version of gdal that you need, you can specify the exact version and "build string" in the recipe.作为一种解决方法,如果您知道所需的gdal的确切版本,则可以在配方中指定确切的版本和“构建字符串”。

The only annoying thing is that you'll have to list gdal once for every combination of platform and python version your recipe needs to support.唯一令人讨厌的是,您必须为您的配方需要支持的平台和 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]

(I copied those from the gdal package listing on the conda-forge channel .) (我从conda-forge 频道上的 gdal package 列表中复制了这些内容。)

BTW, since you mentioned that the real important difference for you is libtiff , then should you be pinning libtiff instead of gdal ?顺便说一句,既然您提到对您来说真正重要的区别是libtiff ,那么您应该固定libtiff而不是gdal吗? Or maybe both?或者两者兼而有之?


Edit:编辑:

It would be nice to avoid repeating the whole list of build strings in the host and run sections.避免在hostrun部分中重复整个构建字符串列表会很好。

As you suggested in the comments, one option is to define the build string in conda_build_config.yaml :正如您在评论中建议的那样,一种选择是在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 }}

Another option is to define a lookup table in a jinja variable, directly in meta.yaml .另一种选择是在 jinja 变量中定义查找表,直接在meta.yaml中。 This is slightly uglier, perhaps, but at least all of logic is contained in a single file.这可能有点难看,但至少所有逻辑都包含在一个文件中。 I'm not sure which to prefer.我不确定更喜欢哪个。

{% 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] }}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何添加适当的“ meta.yaml”配方文件以创建conda-forge软件包分发? 特别是配方文件中的“测试”部分? - How to add a proper 'meta.yaml' recipe file for creating a conda-forge package distribution? Particularly `test` section in recipe file? 从源文件中获取 conda meta.yaml 的包版本 - Get package version for conda meta.yaml from source file 无法在conda meta.yaml文件中指定pip依赖性 - can't specify pip dependency in conda meta.yaml file conda-build 错误地抱怨 meta.yaml 中不包含依赖项 - conda-build complains incorrectly that dependency is not included in meta.yaml 当上传者为“ conda-forge”时,更新conda-forge中的软件包 - Update package in conda-forge, when uploader is “conda-forge” 如何用Python中的conda / meta.yaml指定外部软件需求? - how to specify external software requirements with conda/meta.yaml in Python? 具有conda-forge的特定包版本 - Specific package version with conda-forge 在 conda-forge 中找不到旧版本的 Python - Older versions of Python not found in conda-forge 当使用 conda-build 构建 conda 包并且我的代码使用纯 python 库时,我需要在 meta.yaml 文件中放入 build/host/run 什么? - When building conda packages using conda-build and my code uses pure python libraries, what do I need to put in build/host/run in the meta.yaml file? conda 或 conda-forge 应该用于 Python 环境吗? - Should conda, or conda-forge be used for Python environments?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM