-
Notifications
You must be signed in to change notification settings - Fork 6
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
Python recipe render improvements #57
Changes from 13 commits
8f91f4e
d5a06d8
325f8a5
5d6a800
d8311cf
cf170df
b0171dc
5dc6735
c9ac681
28e5649
973ca39
a6314af
90a6a4e
49b3a06
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,6 @@ jobs: | |
- py311 | ||
- py310 | ||
- py39 | ||
- py38 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: prefix-dev/[email protected] | ||
|
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ build-backend = "hatchling.build" | |
[project] | ||
name = "rattler-build-conda-compat" | ||
description = "A package for exposing rattler-build API for conda-smithy" | ||
version = "1.2.2" | ||
version = "1.3.0" | ||
readme = "README.md" | ||
authors = [{ name = "Nichita Morcotilo", email = "[email protected]" }] | ||
license = { file = "LICENSE.txt" } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from __future__ import annotations | ||
|
||
from itertools import product | ||
|
||
|
||
def variant_combinations(data: dict[str, str | list[str]]) -> list[dict[str, str]]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could definitely use a function docstring and explain what the inputs and outputs are. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does it make sense to add a few test cases specifically for this? |
||
zip_keys = data.pop("zip_keys", []) | ||
# Separate the keys that need to be zipped from the rest | ||
zip_keys_flat = [item for sublist in zip_keys for item in sublist] | ||
other_keys = [key for key in data if key not in zip_keys_flat] | ||
|
||
# Create combinations for non-zipped keys | ||
other_combinations = list(product(*[data[key] for key in other_keys])) | ||
|
||
# Create zipped combinations | ||
zipped_combinations = [list(zip(*[data[key] for key in zip_group])) for zip_group in zip_keys] | ||
|
||
# Combine zipped combinations | ||
zipped_product = list(product(*zipped_combinations)) | ||
|
||
# Combine all results into dictionaries | ||
final_combinations = [] | ||
for other_combo in other_combinations: | ||
for zipped_combo in zipped_product: | ||
combined = {} | ||
# Add non-zipped items | ||
for key, value in zip(other_keys, other_combo): | ||
combined[key] = str(value) | ||
# Add zipped items | ||
for zip_group, zip_values in zip(zip_keys, zipped_combo): | ||
for key, value in zip(zip_group, zip_values): | ||
combined[key] = str(value) | ||
final_combinations.append(combined) | ||
|
||
return final_combinations |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,24 @@ | |
from typing import Any | ||
|
||
from ruamel.yaml import YAML | ||
from ruamel.yaml.comments import CommentedMap, CommentedSeq | ||
|
||
|
||
# Custom constructor for loading floats as strings | ||
def float_as_string_constructor(loader, node) -> str: # noqa: ANN001 | ||
return loader.construct_scalar(node) | ||
|
||
|
||
def convert_to_plain_types(data: Any) -> Any: # noqa: ANN401 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add a docstring? What is a plain type? |
||
if isinstance(data, CommentedMap): | ||
return {convert_to_plain_types(k): convert_to_plain_types(v) for k, v in data.items()} | ||
if isinstance(data, (CommentedSeq, list)): | ||
return [convert_to_plain_types(item) for item in data] | ||
if isinstance(data, dict): | ||
return {convert_to_plain_types(k): convert_to_plain_types(v) for k, v in data.items()} | ||
return data | ||
|
||
|
||
def _yaml_object() -> YAML: | ||
yaml = YAML(typ="rt") | ||
yaml.Constructor.add_constructor("tag:yaml.org,2002:float", float_as_string_constructor) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incomplete docstring