rattler-build icon indicating copy to clipboard operation
rattler-build copied to clipboard

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

Open vyasr opened this issue 1 year ago • 2 comments

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.

vyasr avatar Jul 18 '24 20:07 vyasr

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.

wolfv avatar Jul 19 '24 11:07 wolfv

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.

vyasr avatar Jul 21 '24 00:07 vyasr

I'd like to +1 the idea of adding the ability to specify requirements for python tests. I've noticed needing to do this workaround eg; when dealing w/ windows builds on conda-forge recently for packages that depend on PyTorch (which will have 3.10+ builds only).

iamthebot avatar Nov 19 '24 19:11 iamthebot

We just added the ability to add the python version, e.g.

tests:
  - python:
        imports: [ ... ]
        python_version: ["3.8", "3.9", ...]  # can be one or multiple

Do you need more?

As mentioned before, the following also works:

script:
  interpreter: python
  content: |
    import foo
    import baz
  requirements:
     run:
       - bla

wolfv avatar Nov 19 '24 19:11 wolfv

No, that's perfect! I think this issue can be closed then. Maybe one suggestion would be the ability to use the CFEP that passes a specific python version range using python_min

iamthebot avatar Nov 19 '24 19:11 iamthebot

Yeah that was the intention of @hadim's PR :) I think you can do python_version: ${{ python_min }} https://github.com/prefix-dev/rattler-build/pull/1170

wolfv avatar Nov 19 '24 20:11 wolfv