Skip to content

Commit 5526786

Browse files
committed
Comment out non-default environments
1 parent 5701540 commit 5526786

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

scripts/generate-pixi-toml.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -234,12 +234,7 @@ def comment_out_environments_that_wont_solve(
234234
"""
235235
Comment out the lines defining environments that won't solve.
236236
237-
TODO: Understand why these environments won't solve.
238-
This happens when I set everything to use the default solve group.
239-
Ordinarily the dependencies in each environment would just be subsets
240-
of the dependencies in the full default environment. Perhaps there's
241-
some non-monotonic constraint like a run-constrained dependency. But
242-
this needs to be investigated.
237+
Reference: <https://github.com/prefix-dev/pixi/issues/2725>
243238
244239
>>> input_data = tomlkit.loads('''
245240
... [environments]
@@ -252,23 +247,32 @@ def comment_out_environments_that_wont_solve(
252247
dev = {features = ["dev"]}
253248
# tests = {features = ["tests"]}
254249
"""
255-
TO_COMMENT_OUT = ["conda-dev", "numba", "rtd", "tests"]
256250
environments_item = pixi_toml_data.get("environments")
257251
assert isinstance(environments_item, tomlkit.items.Table)
258252

259-
# Modify the table in-place to preserve comments and formatting
260-
for key, value in list(environments_item.items()):
261-
if key in TO_COMMENT_OUT:
262-
# Create a comment with the key-value pair
253+
# Create a new table to rebuild with the desired order
254+
new_environments_table = tomlkit.table()
255+
256+
COMMENT_TEXT = "Disable non-default environments pending <https://github.com/prefix-dev/pixi/issues/2725>"
257+
# Process each key-value pair in the original table
258+
for key, value in environments_item.items():
259+
if key == "default":
260+
# Keep the default environment as-is
261+
new_environments_table.append(key, value)
262+
263+
# Add explanatory comment at the beginning
264+
new_environments_table.append(None, tomlkit.nl())
265+
new_environments_table.append(None, tomlkit.comment(COMMENT_TEXT))
266+
else:
267+
# Convert other environments to comments
263268
comment_text = f"{key} = {value.as_string()}"
264269

265-
# If the original value had a comment, append it to the comment text
266-
if hasattr(value, "trivia") and value.trivia.comment:
267-
comment_text += f" {value.trivia.comment}"
270+
# Note: We don't preserve original comments here since they
271+
# don't make sense in the commented-out context
272+
new_environments_table.append(None, tomlkit.comment(comment_text))
268273

269-
# Remove the original key-value pair and add a comment
270-
del environments_item[key]
271-
environments_item.add(tomlkit.comment(comment_text))
274+
# Replace the original environments table with the new one
275+
pixi_toml_data["environments"] = new_environments_table
272276

273277
return pixi_toml_data
274278

0 commit comments

Comments
 (0)