Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Values from variant file are always evaluated as a string and not boolean #691

Open
pavelzw opened this issue Mar 1, 2024 · 6 comments · May be fixed by #801
Open

Values from variant file are always evaluated as a string and not boolean #691

pavelzw opened this issue Mar 1, 2024 · 6 comments · May be fixed by #801
Labels
bug Something isn't working

Comments

@pavelzw
Copy link
Collaborator

pavelzw commented Mar 1, 2024

# yaml-language-server: $schema=https://raw.githubusercontent.com/prefix-dev/recipe-format/main/schema.json

package:
  name: package
  version: '0.1.0'
build:
  noarch: python
  number: 0

requirements:
  host:
    - if: new_pydantic
      then:
        - pydantic >=2
      else:
        - pydantic >=1,<2
new_pydantic:
  - true
  - false

if: new_pydantic == 'true' fixes the issue.

❯ rattler-build build -r conda.recipe/recipe.yaml -m conda.recipe/variants.yaml
 Target platform: osx-arm64

 ╭─ Finding outputs from recipe
 │ Found 2 variants
 │ Build variant: package-0.1.0-pyh1a4448f_0
 │ ╭─────────────────┬─────────╮
 │ │ Variant         ┆ Version │
 │ ╞═════════════════╪═════════╡
 │ │ new_pydantic    ┆ true    │
 │ │ target_platform ┆ noarch  │
 │ ╰─────────────────┴─────────╯
 │ Build variant: package-0.1.0-pyhe8c018c_0
 │ ╭─────────────────┬─────────╮
 │ │ Variant         ┆ Version │
 │ ╞═════════════════╪═════════╡
 │ │ new_pydantic    ┆ false   │
 │ │ target_platform ┆ noarch  │
 │ ╰─────────────────┴─────────╯
 │
 ╰─────────────────── (took 0 seconds)

 ╭─ Running build for recipe: package-0.1.0-pyh1a4448f_0
 │
 │ ╭─ Fetching source code
 │ │ No sources to fetch
 │ │
 │ ╰─────────────────── (took 0 seconds)
 │
 │ ╭─ Resolving environments
 │ │ 
 │ │ Resolving environment for:
 │ │   Platform: osx-arm64
 │ │   Channels: 
 │ │    - /private/tmp/rattler-bug/output
 │ │    - conda-forge
 │ │   Specs:
 │ │    - pydantic >=2
 │ │ ✔   /private/tmp/rattler [00:00:00] Using cache
 │ │ 
 │ │ ╭───────────────────┬──────────┬────────────────────┬─────────────┬────────────╮
 │ │ │ Package           ┆ Version  ┆ Build              ┆ Channel     ┆ Size       │
 │ │ ╞═══════════════════╪══════════╪════════════════════╪═════════════╪════════════╡
 │ │ │ pydantic          ┆ 2.6.3    ┆ pyhd8ed1ab_0       ┆ conda-forge ┆ 265.53 KiB │
 │ │ │ annotated-types   ┆ 0.6.0    ┆ pyhd8ed1ab_0       ┆ conda-forge ┆ 16.63 KiB  │
 │ │ │ pydantic-core     ┆ 2.16.3   ┆ py312h5280bc4_0    ┆ conda-forge ┆ 1.40 MiB   │
 │ │ │ python_abi        ┆ 3.12     ┆ 4_cp312            ┆ conda-forge ┆ 6.36 KiB   │
 │ │ │ python            ┆ 3.12.2   ┆ hdf0ec26_0_cpython ┆ conda-forge ┆ 12.48 MiB  │
 │ │ │ xz                ┆ 5.2.6    ┆ h57fd34a_0         ┆ conda-forge ┆ 230.17 KiB │
 │ │ │ readline          ┆ 8.2      ┆ h92ec313_1         ┆ conda-forge ┆ 244.48 KiB │
 │ │ │ openssl           ┆ 3.2.1    ┆ h0d3ecfb_0         ┆ conda-forge ┆ 2.73 MiB   │
 │ │ │ libsqlite         ┆ 3.45.1   ┆ h091b4b1_0         ┆ conda-forge ┆ 805.35 KiB │
 │ │ │ libexpat          ┆ 2.5.0    ┆ hb7217d7_1         ┆ conda-forge ┆ 61.96 KiB  │
 │ │ │ libzlib           ┆ 1.2.13   ┆ h53f4e23_5         ┆ conda-forge ┆ 46.97 KiB  │
 │ │ │ tk                ┆ 8.6.13   ┆ h5083fa2_1         ┆ conda-forge ┆ 3.00 MiB   │
 │ │ │ ncurses           ┆ 6.4      ┆ h463b476_2         ┆ conda-forge ┆ 776.11 KiB │
 │ │ │ bzip2             ┆ 1.0.8    ┆ h93a5062_5         ┆ conda-forge ┆ 119.46 KiB │
 │ │ │ libffi            ┆ 3.4.2    ┆ h3422bc3_5         ┆ conda-forge ┆ 38.11 KiB  │
 │ │ │ typing-extensions ┆ 4.10.0   ┆ hd8ed1ab_0         ┆ conda-forge ┆ 9.94 KiB   │
 │ │ │ typing_extensions ┆ 4.10.0   ┆ pyha770c72_0       ┆ conda-forge ┆ 36.15 KiB  │
 │ │ │ ca-certificates   ┆ 2024.2.2 ┆ hf0a4a13_0         ┆ conda-forge ┆ 152.08 KiB │
 │ │ │ tzdata            ┆ 2024a    ┆ h0c530f3_0         ┆ conda-forge ┆ 117.01 KiB │
 │ │ ╰───────────────────┴──────────┴────────────────────┴─────────────┴────────────╯
 │ │ ✔ Successfully updated the environment
 │ │ 
 │ │ Finalized run dependencies: this output has no run dependencies
 │ │
 │ ╰─────────────────── (took 1 second)
 │
 │ ╭─ Running build script
 │ │
 │ ╰─────────────────── (took 0 seconds)
 │
 │ ╭─ Packaging new files
 │ │ Copying done!
 │ │ Post-processing done!
 │ │ Writing metadata for package
 │ │ 
 │ │ Files in package:
 │ │   - info/about.json
 │ │   - info/hash_input.json
 │ │   - info/index.json
 │ │   - info/link.json
 │ │   - info/paths.json
 │ │   - info/recipe/recipe.yaml
 │ │   - info/recipe/rendered_recipe.yaml
 │ │   - info/recipe/variant_config.yaml
 │ │   - info/recipe/variants.yaml
 │ │ Creating target folder "/private/tmp/rattler-bug/output/noarch"
 │ │ Compressing archive...
 │ │ Archive written to "/private/tmp/rattler-bug/output/noarch/package-0.1.0-pyh1a4448f_0.conda"
 │ │
 │ ╰─────────────────── (took 0 seconds)
 │
 │ ╭─ Running package tests
 │ │ Removing previously cached package "/Users/pavel/Library/Caches/rattler/cache/pkgs/package-0.1.0-pyh1a4448f_0"
 │ │ Creating test environment in "/private/tmp/rattler-bug/output/bld/rattler-build_package_1709299706/work/test"
 │ │ Collecting tests from "/Users/pavel/Library/Caches/rattler/cache/pkgs/package-0.1.0-pyh1a4448f_0"
 │ │
 │ ╰─────────────────── (took 0 seconds)
 │
 ╰─────────────────── (took 2 seconds)

 ╭─ Running build for recipe: package-0.1.0-pyhe8c018c_0
 │
 │ ╭─ Fetching source code
 │ │ No sources to fetch
 │ │
 │ ╰─────────────────── (took 0 seconds)
 │
 │ ╭─ Resolving environments
 │ │ 
 │ │ Resolving environment for:
 │ │   Platform: osx-arm64
 │ │   Channels: 
 │ │    - /private/tmp/rattler-bug/output
 │ │    - conda-forge
 │ │   Specs:
 │ │    - pydantic >=2
 │ │ ✔   /private/tmp/rattler [00:00:00] Using cache
 │ │ 
 │ │ ╭───────────────────┬──────────┬────────────────────┬─────────────┬────────────╮
 │ │ │ Package           ┆ Version  ┆ Build              ┆ Channel     ┆ Size       │
 │ │ ╞═══════════════════╪══════════╪════════════════════╪═════════════╪════════════╡
 │ │ │ pydantic          ┆ 2.6.3    ┆ pyhd8ed1ab_0       ┆ conda-forge ┆ 265.53 KiB │
 │ │ │ annotated-types   ┆ 0.6.0    ┆ pyhd8ed1ab_0       ┆ conda-forge ┆ 16.63 KiB  │
 │ │ │ pydantic-core     ┆ 2.16.3   ┆ py312h5280bc4_0    ┆ conda-forge ┆ 1.40 MiB   │
 │ │ │ python_abi        ┆ 3.12     ┆ 4_cp312            ┆ conda-forge ┆ 6.36 KiB   │
 │ │ │ python            ┆ 3.12.2   ┆ hdf0ec26_0_cpython ┆ conda-forge ┆ 12.48 MiB  │
 │ │ │ xz                ┆ 5.2.6    ┆ h57fd34a_0         ┆ conda-forge ┆ 230.17 KiB │
 │ │ │ readline          ┆ 8.2      ┆ h92ec313_1         ┆ conda-forge ┆ 244.48 KiB │
 │ │ │ openssl           ┆ 3.2.1    ┆ h0d3ecfb_0         ┆ conda-forge ┆ 2.73 MiB   │
 │ │ │ libsqlite         ┆ 3.45.1   ┆ h091b4b1_0         ┆ conda-forge ┆ 805.35 KiB │
 │ │ │ libexpat          ┆ 2.5.0    ┆ hb7217d7_1         ┆ conda-forge ┆ 61.96 KiB  │
 │ │ │ libzlib           ┆ 1.2.13   ┆ h53f4e23_5         ┆ conda-forge ┆ 46.97 KiB  │
 │ │ │ tk                ┆ 8.6.13   ┆ h5083fa2_1         ┆ conda-forge ┆ 3.00 MiB   │
 │ │ │ ncurses           ┆ 6.4      ┆ h463b476_2         ┆ conda-forge ┆ 776.11 KiB │
 │ │ │ bzip2             ┆ 1.0.8    ┆ h93a5062_5         ┆ conda-forge ┆ 119.46 KiB │
 │ │ │ libffi            ┆ 3.4.2    ┆ h3422bc3_5         ┆ conda-forge ┆ 38.11 KiB  │
 │ │ │ typing-extensions ┆ 4.10.0   ┆ hd8ed1ab_0         ┆ conda-forge ┆ 9.94 KiB   │
 │ │ │ typing_extensions ┆ 4.10.0   ┆ pyha770c72_0       ┆ conda-forge ┆ 36.15 KiB  │
 │ │ │ ca-certificates   ┆ 2024.2.2 ┆ hf0a4a13_0         ┆ conda-forge ┆ 152.08 KiB │
 │ │ │ tzdata            ┆ 2024a    ┆ h0c530f3_0         ┆ conda-forge ┆ 117.01 KiB │
 │ │ ╰───────────────────┴──────────┴────────────────────┴─────────────┴────────────╯
 │ │ ✔ Successfully updated the environment
 │ │ 
 │ │ Finalized run dependencies: this output has no run dependencies
 │ │
 │ ╰─────────────────── (took 1 second)
 │
 │ ╭─ Running build script
 │ │
 │ ╰─────────────────── (took 0 seconds)
 │
 │ ╭─ Packaging new files
 │ │ Copying done!
 │ │ Post-processing done!
 │ │ Writing metadata for package
 │ │ 
 │ │ Files in package:
 │ │   - info/about.json
 │ │   - info/hash_input.json
 │ │   - info/index.json
 │ │   - info/link.json
 │ │   - info/paths.json
 │ │   - info/recipe/recipe.yaml
 │ │   - info/recipe/rendered_recipe.yaml
 │ │   - info/recipe/variant_config.yaml
 │ │   - info/recipe/variants.yaml
 │ │ Creating target folder "/private/tmp/rattler-bug/output/noarch"
 │ │ Compressing archive...
 │ │ Archive written to "/private/tmp/rattler-bug/output/noarch/package-0.1.0-pyhe8c018c_0.conda"
 │ │
 │ ╰─────────────────── (took 0 seconds)
 │
 │ ╭─ Running package tests
 │ │ Removing previously cached package "/Users/pavel/Library/Caches/rattler/cache/pkgs/package-0.1.0-pyhe8c018c_0"
 │ │ Creating test environment in "/private/tmp/rattler-bug/output/bld/rattler-build_package_1709299707/work/test"
 │ │ Collecting tests from "/Users/pavel/Library/Caches/rattler/cache/pkgs/package-0.1.0-pyhe8c018c_0"
 │ │
 │ ╰─────────────────── (took 0 seconds)
 │
 ╰─────────────────── (took 1 second)

 ╭─ Build summary
 │
 │ ╭─ Build summary for recipe: package-0.1.0-pyh1a4448f_0
 │ │ Artifact: /private/tmp/rattler-bug/output/noarch/package-0.1.0-pyh1a4448f_0.conda (4.18 KiB)
 │ │ Variant configuration (hash: pyh1a4448f_0):
 │ │ ╭─────────────────┬────────╮
 │ │ │ new_pydantic    ┆ true   │
 │ │ │ target_platform ┆ noarch │
 │ │ ╰─────────────────┴────────╯
 │ │ 
 │ │ Host dependencies:
 │ │ ╭───────────────────┬──────────────┬──────────┬────────────────────┬─────────────┬────────────╮
 │ │ │ Package           ┆ Spec         ┆ Version  ┆ Build              ┆ Channel     ┆       Size │
 │ │ ╞═══════════════════╪══════════════╪══════════╪════════════════════╪═════════════╪════════════╡
 │ │ │ pydantic          ┆ pydantic >=2 ┆ 2.6.3    ┆ pyhd8ed1ab_0       ┆ conda-forge ┆ 265.53 KiB │
 │ │ │ annotated-types   ┆              ┆ 0.6.0    ┆ pyhd8ed1ab_0       ┆ conda-forge ┆  16.63 KiB │
 │ │ │ bzip2             ┆              ┆ 1.0.8    ┆ h93a5062_5         ┆ conda-forge ┆ 119.46 KiB │
 │ │ │ ca-certificates   ┆              ┆ 2024.2.2 ┆ hf0a4a13_0         ┆ conda-forge ┆ 152.08 KiB │
 │ │ │ libexpat          ┆              ┆ 2.5.0    ┆ hb7217d7_1         ┆ conda-forge ┆  61.96 KiB │
 │ │ │ libffi            ┆              ┆ 3.4.2    ┆ h3422bc3_5         ┆ conda-forge ┆  38.11 KiB │
 │ │ │ libsqlite         ┆              ┆ 3.45.1   ┆ h091b4b1_0         ┆ conda-forge ┆ 805.35 KiB │
 │ │ │ libzlib           ┆              ┆ 1.2.13   ┆ h53f4e23_5         ┆ conda-forge ┆  46.97 KiB │
 │ │ │ ncurses           ┆              ┆ 6.4      ┆ h463b476_2         ┆ conda-forge ┆ 776.11 KiB │
 │ │ │ openssl           ┆              ┆ 3.2.1    ┆ h0d3ecfb_0         ┆ conda-forge ┆   2.73 MiB │
 │ │ │ pydantic-core     ┆              ┆ 2.16.3   ┆ py312h5280bc4_0    ┆ conda-forge ┆   1.40 MiB │
 │ │ │ python            ┆              ┆ 3.12.2   ┆ hdf0ec26_0_cpython ┆ conda-forge ┆  12.48 MiB │
 │ │ │ python_abi        ┆              ┆ 3.12     ┆ 4_cp312            ┆ conda-forge ┆   6.36 KiB │
 │ │ │ readline          ┆              ┆ 8.2      ┆ h92ec313_1         ┆ conda-forge ┆ 244.48 KiB │
 │ │ │ tk                ┆              ┆ 8.6.13   ┆ h5083fa2_1         ┆ conda-forge ┆   3.00 MiB │
 │ │ │ typing-extensions ┆              ┆ 4.10.0   ┆ hd8ed1ab_0         ┆ conda-forge ┆   9.94 KiB │
 │ │ │ typing_extensions ┆              ┆ 4.10.0   ┆ pyha770c72_0       ┆ conda-forge ┆  36.15 KiB │
 │ │ │ tzdata            ┆              ┆ 2024a    ┆ h0c530f3_0         ┆ conda-forge ┆ 117.01 KiB │
 │ │ │ xz                ┆              ┆ 5.2.6    ┆ h57fd34a_0         ┆ conda-forge ┆ 230.17 KiB │
 │ │ ╰───────────────────┴──────────────┴──────────┴────────────────────┴─────────────┴────────────╯
 │ │ 
 │ │
 │ ╰─────────────────── (took 0 seconds)
 │
 │ ╭─ Build summary for recipe: package-0.1.0-pyhe8c018c_0
 │ │ Artifact: /private/tmp/rattler-bug/output/noarch/package-0.1.0-pyhe8c018c_0.conda (4.19 KiB)
 │ │ Variant configuration (hash: pyhe8c018c_0):
 │ │ ╭─────────────────┬────────╮
 │ │ │ new_pydantic    ┆ false  │
 │ │ │ target_platform ┆ noarch │
 │ │ ╰─────────────────┴────────╯
 │ │ 
 │ │ Host dependencies:
 │ │ ╭───────────────────┬──────────────┬──────────┬────────────────────┬─────────────┬────────────╮
 │ │ │ Package           ┆ Spec         ┆ Version  ┆ Build              ┆ Channel     ┆       Size │
 │ │ ╞═══════════════════╪══════════════╪══════════╪════════════════════╪═════════════╪════════════╡
 │ │ │ pydantic          ┆ pydantic >=2 ┆ 2.6.3    ┆ pyhd8ed1ab_0       ┆ conda-forge ┆ 265.53 KiB │
 │ │ │ annotated-types   ┆              ┆ 0.6.0    ┆ pyhd8ed1ab_0       ┆ conda-forge ┆  16.63 KiB │
 │ │ │ bzip2             ┆              ┆ 1.0.8    ┆ h93a5062_5         ┆ conda-forge ┆ 119.46 KiB │
 │ │ │ ca-certificates   ┆              ┆ 2024.2.2 ┆ hf0a4a13_0         ┆ conda-forge ┆ 152.08 KiB │
 │ │ │ libexpat          ┆              ┆ 2.5.0    ┆ hb7217d7_1         ┆ conda-forge ┆  61.96 KiB │
 │ │ │ libffi            ┆              ┆ 3.4.2    ┆ h3422bc3_5         ┆ conda-forge ┆  38.11 KiB │
 │ │ │ libsqlite         ┆              ┆ 3.45.1   ┆ h091b4b1_0         ┆ conda-forge ┆ 805.35 KiB │
 │ │ │ libzlib           ┆              ┆ 1.2.13   ┆ h53f4e23_5         ┆ conda-forge ┆  46.97 KiB │
 │ │ │ ncurses           ┆              ┆ 6.4      ┆ h463b476_2         ┆ conda-forge ┆ 776.11 KiB │
 │ │ │ openssl           ┆              ┆ 3.2.1    ┆ h0d3ecfb_0         ┆ conda-forge ┆   2.73 MiB │
 │ │ │ pydantic-core     ┆              ┆ 2.16.3   ┆ py312h5280bc4_0    ┆ conda-forge ┆   1.40 MiB │
 │ │ │ python            ┆              ┆ 3.12.2   ┆ hdf0ec26_0_cpython ┆ conda-forge ┆  12.48 MiB │
 │ │ │ python_abi        ┆              ┆ 3.12     ┆ 4_cp312            ┆ conda-forge ┆   6.36 KiB │
 │ │ │ readline          ┆              ┆ 8.2      ┆ h92ec313_1         ┆ conda-forge ┆ 244.48 KiB │
 │ │ │ tk                ┆              ┆ 8.6.13   ┆ h5083fa2_1         ┆ conda-forge ┆   3.00 MiB │
 │ │ │ typing-extensions ┆              ┆ 4.10.0   ┆ hd8ed1ab_0         ┆ conda-forge ┆   9.94 KiB │
 │ │ │ typing_extensions ┆              ┆ 4.10.0   ┆ pyha770c72_0       ┆ conda-forge ┆  36.15 KiB │
 │ │ │ tzdata            ┆              ┆ 2024a    ┆ h0c530f3_0         ┆ conda-forge ┆ 117.01 KiB │
 │ │ │ xz                ┆              ┆ 5.2.6    ┆ h57fd34a_0         ┆ conda-forge ┆ 230.17 KiB │
 │ │ ╰───────────────────┴──────────────┴──────────┴────────────────────┴─────────────┴────────────╯
 │ │ 
 │ │
 │ ╰─────────────────── (took 0 seconds)
 │
 ╰─────────────────── (took 0 seconds)

if: new_pydantic still evaluates to true even if the value is false.

IMO rattler-build should either throw an error here since new_pydantic is only a string and implicit casting to bool can cause issues (like in this example) or properly cast it to boolean.

Please also add tests for this behavior 🙏🏻

@pavelzw
Copy link
Collaborator Author

pavelzw commented Mar 1, 2024

Side note: in skip: it is evaluated as boolean correctly...

@pavelzw pavelzw added the bug Something isn't working label Mar 4, 2024
@wolfv
Copy link
Member

wolfv commented Apr 15, 2024

what should be allowed?

Strings and bools? It's not yet specified properly, I guess. I don't think we want floats. I am not sure about integers.

conda-build has some wicked magic to turn floats into version strings, but I also think we don't want that (it's lossy and not accurate, too).

@pavelzw
Copy link
Collaborator Author

pavelzw commented Apr 15, 2024

I think strings and bools (true and false, not True and False like in conda-build) would be nice. Shouldn't proper yaml parsing take care of all types?

@JeanChristopheMorinPerso

A couple of months ago I created #232. Should we just let the user decide of the type they want? Floats are more special since YAML doesn't like to have 3.10 for example. Or at least with PyYAML 3.10 resolves to 3.1. So I guess floats could accept both string and float?

@wolfv
Copy link
Member

wolfv commented Apr 15, 2024

For a float 3.10 == 3.1, so I don't think any other YAML parser would handle that differently. I still think it's more correct to parse versions as strings instead of inventing a new (non-YAML) format that treats floats as versions / strings. That also means that anyone who tries to parse variant config files with a YAML parser has to implement that special behavior.

So I would argue that we should either only allow strings or allow strings and bools and either nothing else or integers.

@pavelzw
Copy link
Collaborator Author

pavelzw commented Apr 15, 2024

I would be in favor of strings and bools. But shouldn't this kind of decision be done in a CEP?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants