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

partial support for map based selector conversion #386

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

bamarco
Copy link
Contributor

@bamarco bamarco commented Nov 20, 2023

fixes #385

Turns out the selector parsing did not cover cases where maps have selectors.

Given this meta.yml example:

source:
  url: "https://example.com/src-code" # [not win]
  patches:
    - win-specific.patch # [win]

The existing code produces:

source:
  url: "https://example.com/src-code" # [not win]
  patches:
    - sel(win) win-specific.patch

After this pull request you will get:

source:
  - sel(not win)
    :url "https://example.com/src-code"
  patches:
    - sel(win) win-specific.patch

This example is not fully valid yaml either, but I throw a helpful error.

To fully fix the problem you would need to walk every map and make sure that if any of the map entries have a selector then every map entry is converted to a list entry. I think at that point you're halfway to writing a full yaml parser instead of a preprocessor.

A fully fixed version would produce something like:

source:
  - sel(not win)
    :url "https://example.com/src-code"
  - patches:
    - sel(win) win-specific.patch

A real world example:
https://raw.githubusercontent.com/conda-forge/cmdstan-feedstock/main/recipe/meta.yaml

@bamarco
Copy link
Contributor Author

bamarco commented Nov 21, 2023

I examined this a bit further and I think the appropriate result would actually be:

source:
  sel(not win)
    :url "https://example.com/src-code"
  patches:
    - sel(win): win-specific.patch

@bamarco
Copy link
Contributor Author

bamarco commented Nov 21, 2023

I updated the PR to produce valid yaml in more cases and remove the need for the error. It will correctly handle:

source:
  url: "https://windows.example.com/src-code" # [win]
  sha256: 42 # [win]
  url: "https://posix.example.com/src-code" # [not win]
  sha256: 43 # [not win]
  patches:
    - win-specific.patch # [win]

producing:

source:
  sel(win):
    url: "https://windows.example.com/src-code"
    sha256: 42
  sel(not win):
    url: "https://posix.example.com/src-code"
    sha256: 43
  patches:
    - sel(win): win-specific.patch

but will give a duplicate key error for the following:

source:
  url: "https://windows.example.com/src-code" # [win]
  url: "https://posix.example.com/src-code" # [not win]
  sha256: 42 # [win]
  sha256: 43 # [not win]
  patches:
    - win-specific.patch # [win]

because it produces:

source:
  sel(win):
    url: "https://windows.example.com/src-code"
  sel(not win):
    url: "https://posix.example.com/src-code"
  sel(win):
    sha256: 42
  sel(not win):
    sha256: 43
  patches:
    - sel(win): win-specific.patch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Convert complains of duplicate keys in some recipes
1 participant