Dimebag
Dimebag

Reputation: 843

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 (e.g. 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?

Upvotes: 7

Views: 1319

Answers (1)

Dimebag
Dimebag

Reputation: 843

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.

Upvotes: 7

Related Questions