3737else :
3838 import importlib .metadata as importlib_metadata
3939try :
40- package_map = importlib_metadata .packages_distributions () # load-once to avoid expensive calls
40+ _package_map = importlib_metadata .packages_distributions () # load-once to avoid expensive calls
4141except Exception :
42- package_map = None
42+ _package_map = None
4343
4444logger = logging .get_logger (__name__ ) # pylint: disable=invalid-name
4545
5959
6060
6161def _is_package_available (pkg_name : str , get_dist_name : bool = False ) -> Tuple [bool , str ]:
62- global package_map
62+ global _package_map
6363 pkg_exists = importlib .util .find_spec (pkg_name ) is not None
6464 pkg_version = "N/A"
6565
6666 if pkg_exists :
67- if package_map is None :
68- package_map = defaultdict (list )
67+ if _package_map is None :
68+ _package_map = defaultdict (list )
6969 try :
7070 # Fallback for Python < 3.10
7171 for dist in importlib_metadata .distributions ():
@@ -75,16 +75,16 @@ def _is_package_available(pkg_name: str, get_dist_name: bool = False) -> Tuple[b
7575 } - {None }
7676 _top_level_inferred = filter (lambda name : "." not in name , _infered_opt_names )
7777 for pkg in _top_level_declared or _top_level_inferred :
78- package_map [pkg ].append (dist .metadata ["Name" ])
78+ _package_map [pkg ].append (dist .metadata ["Name" ])
7979 except Exception as _ :
8080 pass
8181 try :
82- if get_dist_name and pkg_name in package_map and package_map [pkg_name ]:
83- if len (package_map [pkg_name ]) > 1 :
82+ if get_dist_name and pkg_name in _package_map and _package_map [pkg_name ]:
83+ if len (_package_map [pkg_name ]) > 1 :
8484 logger .warning (
85- f"Multiple distributions found for package { pkg_name } . Picked distribution: { package_map [pkg_name ][0 ]} "
85+ f"Multiple distributions found for package { pkg_name } . Picked distribution: { _package_map [pkg_name ][0 ]} "
8686 )
87- pkg_name = package_map [pkg_name ][0 ]
87+ pkg_name = _package_map [pkg_name ][0 ]
8888 pkg_version = importlib_metadata .version (pkg_name )
8989 logger .debug (f"Successfully imported { pkg_name } version { pkg_version } " )
9090 except (ImportError , importlib_metadata .PackageNotFoundError ):
0 commit comments