@@ -34,11 +34,17 @@ class Extra(enum.Enum):
3434
3535@lru_cache ()
3636def is_package_available (package : str | Requirement | Extra ):
37+ """
38+ Check if a package is installed in the environment. Returns True if that's the case, False otherwise.
39+ """
3740 deps , deps_by_extra = required_dependencies ()
3841
42+ # If the package is a string, it will get the potential required version from the pyproject.toml
3943 if isinstance (package , str ):
4044 package = deps [package ]
4145
46+ # If the specified package is an "Extra", we will iterate through each required dependency of that extra
47+ # and their version and check their existence.
4248 if isinstance (package , Extra ):
4349 dependencies = deps_by_extra [package .value ]
4450 return all (is_package_available (_package ) for _package in dependencies )
@@ -57,6 +63,9 @@ def is_package_available(package: str | Requirement | Extra):
5763
5864@lru_cache ()
5965def required_dependencies () -> Tuple [Dict [str , Requirement ], Dict [str , List [Requirement ]]]:
66+ """
67+ Parse the pyproject.toml file and return a dictionary mapping package names to requirements.
68+ """
6069 md = metadata ("lighteval" )
6170 requires_dist = md .get_all ("Requires-Dist" ) or []
6271 deps_by_extra = defaultdict (list )
@@ -101,6 +110,10 @@ def raise_if_package_not_available(package: Requirement | Extra, *, language: st
101110
102111
103112def not_installed_error_message (package : Requirement ) -> str :
113+ """
114+ Custom error messages if need be.
115+ """
116+
104117 if package == Extra .MULTILINGUAL .value :
105118 return "You are trying to run an evaluation requiring multilingual capabilities. Please install the required extra: `pip install lighteval[multilingual]`"
106119 elif package == Extra .EXTENDED .value :
0 commit comments