@@ -233,14 +233,16 @@ def normalize_pip(name):
233233 return REGEX_PIP_NORMALIZE .sub ('-' , name ).lower ()
234234
235235
236- def run_pip_list (pkgs , python_cmd = None , unversioned_packages = None , strict_check = None ):
236+ def run_pip_list (pkgs , python_cmd = None , unversioned_packages = None , check_names_versions = True , strict_check = None ):
237237 """
238238 Run pip list to verify normalized names and versions of installed Python packages
239239
240240 :param pkgs: list of package tuples (name, version) as specified in the easyconfig
241241 :param python_cmd: Python command to use (if None, 'python' is used)
242242 :param unversioned_packages: set of Python packages to exclude in the version existence check
243- :param strict_check: boolean to indicate whether to raise an error if package names or versions don’t match
243+ :param check_names_versions: boolean to indicate whether name and versions of Python packages should be checked
244+ :param strict_check: boolean to indicate whether to raise an error if package names or versions don’t match,
245+ or emit a warning
244246 """
245247
246248 log = fancylogger .getLogger ('run_pip_list' , fname = False )
@@ -318,54 +320,55 @@ def run_pip_list(pkgs, python_cmd=None, unversioned_packages=None, strict_check=
318320 msg += "required (check the source for a pyproject.toml and see PEP517 for details on that)."
319321 pip_list_errors .append (msg )
320322
321- normalized_pkgs = [(normalize_pip (name ), version ) for name , version in pkgs ]
322-
323- missing_names = []
324- missing_versions = []
325-
326- for name , version in normalized_pkgs :
327- # Skip packages in the unversioned list: they have already been checked
328- if name in normalized_unversioned :
329- continue
330-
331- # Skip packages in the zero_pkg_names list: they have already been added to pip_list_errors
332- if name in zero_pkg_names :
333- continue
334-
335- # Check for missing (likely wrong) packages names and propose close matches
336- if name not in normalized_pip_pkgs :
337- close_matches = difflib .get_close_matches (name , normalized_pip_pkgs .keys ())
338- if close_matches :
339- msg = f"{ name } (close matches in 'pip list' output: " + ', ' .join (close_matches ) + ")"
323+ if check_names_versions :
324+ normalized_pkgs = [(normalize_pip (name ), version ) for name , version in pkgs ]
325+
326+ missing_names = []
327+ missing_versions = []
328+
329+ for name , version in normalized_pkgs :
330+ # Skip packages in the unversioned list: they have already been checked
331+ if name in normalized_unversioned :
332+ continue
333+
334+ # Skip packages in the zero_pkg_names list: they have already been added to pip_list_errors
335+ if name in zero_pkg_names :
336+ continue
337+
338+ # Check for missing (likely wrong) packages names and propose close matches
339+ if name not in normalized_pip_pkgs :
340+ close_matches = difflib .get_close_matches (name , normalized_pip_pkgs .keys ())
341+ if close_matches :
342+ msg = f"{ name } (close matches in 'pip list' output: " + ', ' .join (close_matches ) + ")"
343+ else :
344+ msg = f"{ name } (no close matches found in 'pip list' output)"
345+ missing_names .append (msg )
346+
347+ # Check for missing (likely wrong) package versions
348+ elif version != normalized_pip_pkgs [name ]:
349+ missing_versions .append (f"{ name } { version } (version in 'pip list' output: { normalized_pip_pkgs [name ]} )" )
350+
351+ log .info (f"Found { len (missing_names )} missing names and { len (missing_versions )} missing versions "
352+ f"out of { len (pkgs )} packages" )
353+
354+ if missing_names :
355+ missing_names_str = '\n ' .join (missing_names )
356+ msg = "The following Python packages were likely specified with a wrong name because they are missing "
357+ msg += f"in the 'pip list' output (causes failure if --upload-test-report is set):\n { missing_names_str } "
358+ if strict_check :
359+ pip_list_errors .append (msg )
340360 else :
341- msg = f"{ name } (no close matches found in 'pip list' output)"
342- missing_names .append (msg )
343-
344- # Check for missing (likely wrong) package versions
345- elif version != normalized_pip_pkgs [name ]:
346- missing_versions .append (f"{ name } { version } (version in 'pip list' output: { normalized_pip_pkgs [name ]} )" )
347-
348- log .info (f"Found { len (missing_names )} missing names and { len (missing_versions )} missing versions "
349- f"out of { len (pkgs )} packages" )
350-
351- if missing_names :
352- missing_names_str = '\n ' .join (missing_names )
353- msg = "The following Python packages were likely specified with a wrong name because they are missing "
354- msg += f"in the 'pip list' output (causes failure if --upload-test-report is set):\n { missing_names_str } "
355- if strict_check :
356- pip_list_errors .append (msg )
357- else :
358- pip_list_warnings .append (msg )
359-
360- if missing_versions :
361- missing_versions_str = '\n ' .join (missing_versions )
362- msg = "The following Python packages were likely specified with a wrong version because they have "
363- msg += "another version in the 'pip list' output (causes failure if --upload-test-report is set):\n "
364- msg += missing_versions_str
365- if strict_check :
366- pip_list_errors .append (msg )
367- else :
368- pip_list_warnings .append (msg )
361+ pip_list_warnings .append (msg )
362+
363+ if missing_versions :
364+ missing_versions_str = '\n ' .join (missing_versions )
365+ msg = "The following Python packages were likely specified with a wrong version because they have "
366+ msg += "another version in the 'pip list' output (causes failure if --upload-test-report is set):\n "
367+ msg += missing_versions_str
368+ if strict_check :
369+ pip_list_errors .append (msg )
370+ else :
371+ pip_list_warnings .append (msg )
369372
370373 if pip_list_warnings :
371374 print_warning (msg , log = log )
0 commit comments