prefix-dev / rattler-build

rattler-build is a universal package builder for Windows, macOS and Linux
https://prefix-dev.github.io/rattler-build
BSD 3-Clause "New" or "Revised" License
185 stars 38 forks source link

Support requirements specification in the Python tests section of multi-output recipes #976

Open vyasr opened 1 month ago

vyasr commented 1 month ago

Currently the tests/script section support specifying requirements, but that is not possible for the tests/python section. Based on the error that I see, I suspect that this is an unrelated parsing bug. Here is the behavior I observe on the latest release 0.18.1 using this minimal recipe:

# recipe.yaml
recipe:
  version: 1.0.0

source:
  path: .

outputs:
  - package:
      name: test
    build:
      script: "echo hello > $PREFIX/tmp"
    tests:
      #- script:
      #  - test -f $PREFIX/tmp
      - python:
          imports:
            - numpy
        requirements:
          run:
            - numpy

Resulting error:

# rattler-build build 

 ╭─ Finding outputs from recipe
 │
 ╰─────────────────── (took 0 seconds)
Error:   x Failed to parse recipe

Error:   x Parsing: invalid field `python`.
    ,-[14:9]
 13 |     tests:
 14 |       - python:
    :         ^^^|^^
    :            `-- here
 15 |           imports:
    `----
  help: valid options for commands_test are script, requirements, files

If I uncomment the script test and comment out the python test, the recipe is successfully parsed and proceeds as expected.

wolfv commented 1 month ago

You can write a "script" test and use "interpreter: python".

Or you can write a script test and call python manually. In the script test you can specify arbitrary dependencies. We should add an example and mention that as a way to test python in arbitrary ways.

vyasr commented 1 month ago

Nice OK that seems like a good solution, so if you don't intend to implement support for specifying requirements in the python tests section that would probably be fine given the alternatives. In that case I think the only action item would be to improve the parsing error above. The error message is a bit misleading.