Skip to content

Commit

Permalink
Only import importlib_metadata when needed
Browse files Browse the repository at this point in the history
Similar to #395, this helps with bootstrap issues with python < 3.8.
Adjust test_pip_needs_upgrade_mac_os_11 accordingly.
  • Loading branch information
jmroot committed Feb 3, 2022
1 parent 96f9188 commit d7f6436
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/build/env.py
Expand Up @@ -18,11 +18,6 @@
import build


if sys.version_info < (3, 8):
import importlib_metadata as metadata
else:
from importlib import metadata

try:
import virtualenv
except ModuleNotFoundError:
Expand Down Expand Up @@ -260,6 +255,11 @@ def _create_isolated_env_venv(path: str) -> Tuple[str, str]:

import packaging.version

if sys.version_info < (3, 8):
import importlib_metadata as metadata
else:
from importlib import metadata

venv.EnvBuilder(with_pip=True, symlinks=_fs_supports_symlink()).create(path)
executable, script_dir, purelib = _find_executable_and_scripts(path)

Expand Down
3 changes: 2 additions & 1 deletion tests/test_env.py
Expand Up @@ -134,7 +134,8 @@ def test_pip_needs_upgrade_mac_os_11(mocker, pip_version, arch):
mocker.patch('platform.system', return_value='Darwin')
mocker.patch('platform.machine', return_value=arch)
mocker.patch('platform.mac_ver', return_value=('11.0', ('', '', ''), ''))
mocker.patch('build.env.metadata.distributions', return_value=(SimpleNamespace(version=pip_version),))
metadata_name = 'importlib_metadata' if sys.version_info < (3, 8) else 'importlib.metadata'
mocker.patch(metadata_name+'.distributions', return_value=(SimpleNamespace(version=pip_version),))

min_version = Version('20.3' if arch == 'x86_64' else '21.0.1')
with build.env.IsolatedEnvBuilder():
Expand Down

0 comments on commit d7f6436

Please sign in to comment.