Skip to content

Commit 7b4a62e

Browse files
committed
Improve performance on Python 3.11
1 parent 3f23f8b commit 7b4a62e

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

CHANGELOG.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
Release History
33
---------------
44

5+
2.4.3
6+
7+
- Improves performance on Python 3.11.
8+
59
2.4.2
610

711
- Added support for Python 3.11.

pip_check_reqs/find_extra_reqs.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import sys
99
from pathlib import Path
1010
from typing import Callable, Iterable, List, Optional, Union
11+
from unittest import mock
1112

1213
from packaging.utils import canonicalize_name
1314
from pip._internal.commands.show import search_packages_info
@@ -43,7 +44,13 @@ def find_extra_reqs(
4344
dist.metadata["Name"] for dist in importlib.metadata.distributions()
4445
]
4546

46-
for package in search_packages_info(all_pkgs):
47+
# On Python 3.11 (and maybe higher), setting this environment variable
48+
# dramatically improves speeds.
49+
# See https://github.com/r1chardj0n3s/pip-check-reqs/issues/123.
50+
with mock.patch.dict(os.environ, {"_PIP_USE_IMPORTLIB_METADATA": "False"}):
51+
packages_info = list(search_packages_info(all_pkgs))
52+
53+
for package in packages_info:
4754
package_name = package.name
4855
package_location = package.location
4956
package_files = []

pip_check_reqs/find_missing_reqs.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import sys
99
from pathlib import Path
1010
from typing import Callable, Iterable, List, Optional, Tuple
11+
from unittest import mock
1112

1213
from packaging.utils import NormalizedName, canonicalize_name
1314
from pip._internal.commands.show import search_packages_info
@@ -41,7 +42,13 @@ def find_missing_reqs(
4142
dist.metadata["Name"] for dist in importlib.metadata.distributions()
4243
]
4344

44-
for package in search_packages_info(all_pkgs):
45+
# On Python 3.11 (and maybe higher), setting this environment variable
46+
# dramatically improves speeds.
47+
# See https://github.com/r1chardj0n3s/pip-check-reqs/issues/123.
48+
with mock.patch.dict(os.environ, {"_PIP_USE_IMPORTLIB_METADATA": "False"}):
49+
packages_info = list(search_packages_info(all_pkgs))
50+
51+
for package in packages_info:
4552
package_name = package.name
4653
package_location = package.location
4754
package_files = []

0 commit comments

Comments
 (0)