簡體   English   中英

Python 打包:在 `conda` `meta.yaml` 文件中創建對`conda-forge` package 的依賴

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

我正在為 conda conda-forge forge 編寫 package 並且需要指定對另一個conda-forge -forge 依賴項的依賴項。 本質上,我需要安裝 conda conda-forge forge gdal package 的固定版本,因為它實際上編譯了支持 BIGTIFF 文件的libtiff版本....

現在,如果我將gdal安裝到conda環境中,我會寫類似的東西。

conda install -c conda-forge gdal=2.4.4 

在安裝 package 時,我會從conda-forge forge 安裝此版本的gdal=2.4.4 現在在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

任何有關如何執行此操作的建議將不勝感激。

我認為不可能在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]

(我從conda-forge 頻道上的 gdal package 列表中復制了這些內容。)

順便說一句,既然您提到對您來說真正重要的區別是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 }}

另一種選擇是在 jinja 變量中定義查找表,直接在meta.yaml中。 這可能有點難看,但至少所有邏輯都包含在一個文件中。 我不確定更喜歡哪個。

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

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM