@@ -234,12 +234,7 @@ def comment_out_environments_that_wont_solve(
234
234
"""
235
235
Comment out the lines defining environments that won't solve.
236
236
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>
243
238
244
239
>>> input_data = tomlkit.loads('''
245
240
... [environments]
@@ -252,23 +247,32 @@ def comment_out_environments_that_wont_solve(
252
247
dev = {features = ["dev"]}
253
248
# tests = {features = ["tests"]}
254
249
"""
255
- TO_COMMENT_OUT = ["conda-dev" , "numba" , "rtd" , "tests" ]
256
250
environments_item = pixi_toml_data .get ("environments" )
257
251
assert isinstance (environments_item , tomlkit .items .Table )
258
252
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
263
268
comment_text = f"{ key } = { value .as_string ()} "
264
269
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 ))
268
273
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
272
276
273
277
return pixi_toml_data
274
278
0 commit comments