简体   繁体   中英

Add requirements from requirements.txt to conda meta.yaml

I'm writing a Python package that I want to publish on both pypi and conda. To avoid mistakes, I would like to store the requirements in a single file; at least for the foreseeable future, they are the same.

It is easy to go from meta.yaml to setup.py (eg through pyyaml), however what about the other way around? How can I inject the requirements into meta.yaml?

Is there anything like:

{% set data = load_setup_py_data() %}
...
requirements:
  run:
    {{ data.get('install_requires') }}

What is the best practice for this scenario?

Hard to figure out for a jinja noob but this works:

requirements:
  run:
    {% for req in data.get('install_requires', []) %}
      - {{ req }}
    {% endfor %}

Surprisingly hard to figure out why but load_setup_py_data() seems to be called multiple times during conda-build and sometimes it returns an empty dict with no install_requires, so .get would return a None .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM