Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a proper 'meta.yaml' recipe file for creating a conda-forge package distribution? Particularly `test` section in recipe file?

I'm trying to have conda-forge host a python package I've created which is already on PyPI: https://pypi.org/project/ludoSim-jaib1/

I've read the conda-forge documentation on contributing packages here and the conda documentation on defining metadata via a meta.yaml recipe file here

My submitted pull request to the conda-forge/staged-recipes repo is here. My meta.yaml file can be found in that pull request, but I'll post it in text here as well:

{% set name = "ludoSim-jaib1" %}
{% set version = "0.0.1" %}

 package:
  name: {{ name|lower }}
  version: {{ version }}

 source:
  url: https://pypi.io/packages/source/{{ name[0] }}/{{ name }}/{{ name }}-{{ version }}.tar.gz
  sha256: 3342abcd52a6a18e1d4b0e2e626c051f24133187647c6618c0f81d7add28d543

 build: 
  number: 0
  script: python -m pip install . --no-deps -vv 
  skip: true  # [py<30]

 requirements:
  host:
    - python
    - pip
  run:
    - python

 test:
  source_files:
    tests/test_ludo.py
    tests/runTest.py
  imports:
    - ludoSim
    - pytest

 about:
  home: http://github.com/jaib1/ludoSim
  license: GPL-3.0
  license_family: GPL
  license_file: LICENSE.md
  summary: A simple ludo simulator
  description: See the package README.md for more information.

 extra:
  recipe-maintainers:
    - jaib1

I think there must be something simple I've done wrong in the meta.yaml recipe, but as this is my first time submitting a package to conda-forge, I'm not sure exactly what. I was confused about the test section in the recipe file when reading the documentation: I didn't exactly understand how the info in the test section is used to run tests for builds: for my package, I want to run a test script which exists in my package, depends on the pytest package, and which needs to be run in the parent directory of the location my package is located in.

Can I have information on how to fix my meta.yaml recipe file and how to model the test section in that file for my scenario?

like image 906
jaib1 Avatar asked Jul 14 '19 21:07

jaib1


1 Answers

The following document is the canonical reference for everything I repeat below:

https://docs.conda.io/projects/conda-build/en/stable/resources/define-metadata.html#test-section

When creating conda recipes, there are (AFAIK) three ways to define tests that will get executed:

  • create run_test.[py,pl,sh,bat] in the recipe directory (this is automatically discovered by conda-build
  • include test/imports to test that python modules can be imported
  • include test/commands to run arbitrary shell commands

These can be supplemented by source_files, requires, and a number of other keys to format a test environment properly. I think, given your problem description:

for my package, I want to run a test script which exists in my package, depends on the pytest package, and which needs to be run in the parent directory of the location my package is located in

you probably want something like this:

test:
  imports:
    - ludoSim
  source_files:
    - tests/test_ludo.py
    - tests/runTest.py
  requires:
    - pytest
  commands:
    - pytest tests/

This should copy the given source_files from your source folder into the test directory, then install pytest, then run pytest tests/. I'm not sure if I've interpreted your directory requirement correctly, but your test/commands can include any number of calls to pushd or similar to move around to where you need to be.

like image 109
Duncan Macleod Avatar answered Nov 13 '22 12:11

Duncan Macleod