@@ -83,7 +83,28 @@ def environment_yml(module_lint_object: ComponentLint, module: NFCoreComponent,
8383
8484 if valid_env_yml :
8585 # Check that the dependencies section is sorted alphabetically
86- if sorted (env_yml ["dependencies" ]) == env_yml ["dependencies" ]:
86+ def sort_recursively (obj ):
87+ """Simple recursive sort for nested structures."""
88+ if isinstance (obj , list ):
89+
90+ def get_key (x ):
91+ if isinstance (x , dict ):
92+ # For dicts like {"pip": [...]}, use the key "pip"
93+ return (list (x .keys ())[0 ], 1 )
94+ else :
95+ # For strings like "pip=23.3.1", use "pip" and for bioconda::samtools=1.15.1, use "bioconda::samtools"
96+ return (str (x ).split ("=" )[0 ], 0 )
97+
98+ return sorted ([sort_recursively (item ) for item in obj ], key = get_key )
99+ elif isinstance (obj , dict ):
100+ return {k : sort_recursively (v ) for k , v in obj .items ()}
101+ else :
102+ return obj
103+
104+ sorted_dependencies = sort_recursively (env_yml ["dependencies" ])
105+
106+ # Direct comparison of sorted vs original dependencies
107+ if sorted_dependencies == env_yml ["dependencies" ]:
87108 module .passed .append (
88109 (
89110 "environment_yml_sorted" ,
@@ -96,6 +117,6 @@ def environment_yml(module_lint_object: ComponentLint, module: NFCoreComponent,
96117 log .info (
97118 f"Dependencies in { module .component_name } 's environment.yml were not sorted alphabetically. Sorting them now."
98119 )
99- env_yml ["dependencies" ]. sort ()
120+ env_yml ["dependencies" ] = sorted_dependencies
100121 with open (Path (module .component_dir , "environment.yml" ), "w" ) as fh :
101122 yaml .dump (env_yml , fh , Dumper = custom_yaml_dumper ())
0 commit comments