Package loadable: compare case insensitive (#16234)
This commit is contained in:
parent
376d4e4fa0
commit
a14980716d
2 changed files with 6 additions and 1 deletions
|
@ -73,11 +73,13 @@ def package_loadable(package: str) -> bool:
|
||||||
# This is a zip file
|
# This is a zip file
|
||||||
req = pkg_resources.Requirement.parse(urlparse(package).fragment)
|
req = pkg_resources.Requirement.parse(urlparse(package).fragment)
|
||||||
|
|
||||||
|
req_proj_name = req.project_name.lower()
|
||||||
|
|
||||||
for path in sys.path:
|
for path in sys.path:
|
||||||
for dist in pkg_resources.find_distributions(path):
|
for dist in pkg_resources.find_distributions(path):
|
||||||
# If the project name is the same, it will be the one that is
|
# If the project name is the same, it will be the one that is
|
||||||
# loaded when we import it.
|
# loaded when we import it.
|
||||||
if dist.project_name == req.project_name:
|
if dist.project_name.lower() == req_proj_name:
|
||||||
return dist in req
|
return dist in req
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -239,3 +239,6 @@ def test_package_loadable_installed_twice():
|
||||||
|
|
||||||
with patch('pkg_resources.find_distributions', side_effect=[[v2]]):
|
with patch('pkg_resources.find_distributions', side_effect=[[v2]]):
|
||||||
assert package.package_loadable('hello==2.0.0')
|
assert package.package_loadable('hello==2.0.0')
|
||||||
|
|
||||||
|
with patch('pkg_resources.find_distributions', side_effect=[[v2]]):
|
||||||
|
assert package.package_loadable('Hello==2.0.0')
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue