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

Please supported mixed mode values #73

Open
xnox opened this issue Oct 6, 2024 · 4 comments
Open

Please supported mixed mode values #73

xnox opened this issue Oct 6, 2024 · 4 comments

Comments

@xnox
Copy link

xnox commented Oct 6, 2024

If one specifies that something should be a string, please encode it in the most natural and deterministic way.

Example for something desired to be formatted as a list of strings please ensure that all form of canonical integer and floating point numbers are encoded as strings.

https://yaml.org/spec/1.2.2/#24-tags

Lists

canonical: 12345
decimal: +12345
octal: 0o14
hexadecimal: 0xC
canonical: 1.23015e+3
exponential: 12.3015e+02
fixed: 1230.15
negative infinity: -.inf
not a number: .nan

As valid representations of numbers, which upon parsing will not be strings. And thus need to be quoted to be strings.

For the purpose of melange, we can encounter something like "1.23015e+3" as a string value represetting package version or text git tag. But most commonly it is software with single major or single minor version only that can get miss-parsed.

@luhring
Copy link
Member

luhring commented Nov 6, 2024

I'm not sure I'm following what this issue is asking for yet... Are you saying that yam is mishandling YAML tags then they're specified? Are you saying that yam should define its own default behavior for when no tag is present in the input?

An example input and expected output would go a long way here! Thanks!

@xnox
Copy link
Author

xnox commented Nov 7, 2024

@luhring

When doing yam on glibc.yaml I would like it to convert

package:
  name: glibc
  version: 2.40
  epoch: 3
  description: "the GNU C library"
  copyright:
    - license: LGPL-2.1-or-later
  resources:
    cpu: 16
    memory: 16Gi

to

package:
  name: glibc
  version: "2.40"
  epoch: 3
  description: "the GNU C library"
  copyright:
    - license: LGPL-2.1-or-later
  resources:
    cpu: 16
    memory: 16Gi

As version is a string, epoch is an integer, and cpu is an integer, and memory is unambiguous string.

@luhring
Copy link
Member

luhring commented Dec 2, 2024

Sorry for the delay! 😳

Thanks for this example, it's super helpful, and I think I'm understanding what you're looking for now.

For context, yam is operating on YAML bytes. It doesn't have knowledge of application-specific types. This is by design: it's a general purpose YAML formatter.

Given that, I could see implementing this feature in one of two ways:

  1. yam's config has a couple properties that take in "path expressions" — gap and sort. This lets the user indicate preferences for how to handle type-specific aspects of the YAML structure in a way that's loosely coupled to the application domain. This has been working well for Melange files, for example. So we could add another config property that says "quote this string value if it could be interpreted as some other non-string type otherwise" for a given set of path expressions (e.g. ".package.version").

  2. If what you're wanting to do is specific to Melange, we could solve this in Melange directly instead of in yam, by adjusting the type-specific YAML marshaling to handle all string-type fields in the manner you're suggesting.

I'd also be curious to know what problems you're seeing in some specific use cases with today's behavior, to help with the discussion about how best to solve it.

@xnox
Copy link
Author

xnox commented Dec 12, 2024

Yes adding something to .yam.yaml would be great. Something like "quote:" key to always quote a given subkey.

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

No branches or pull requests

2 participants