Skip to content

Commit

Permalink
fix: avoid importing virtualenv if not using it (#636)
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
  • Loading branch information
henryiii committed Jul 3, 2023
1 parent 9a695f5 commit 7a4b1bf
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/build/env.py
Expand Up @@ -2,6 +2,7 @@

import abc
import functools
import importlib.util
import logging
import os
import platform
Expand All @@ -19,11 +20,6 @@
from ._util import check_dependency


try:
import virtualenv
except ModuleNotFoundError:
virtualenv = None

if sys.version_info >= (3, 8):
from typing import Protocol
elif typing.TYPE_CHECKING:
Expand Down Expand Up @@ -55,7 +51,7 @@ def _should_use_virtualenv() -> bool:
# virtualenv might be incompatible if it was installed separately
# from build. This verifies that virtualenv and all of its
# dependencies are installed as specified by build.
return virtualenv is not None and not any(
return importlib.util.find_spec('virtualenv') is not None and not any(
packaging.requirements.Requirement(d[1]).name == 'virtualenv'
for d in check_dependency('build[virtualenv]')
if len(d) > 1
Expand Down Expand Up @@ -170,6 +166,8 @@ def _create_isolated_env_virtualenv(path: str) -> tuple[str, str]:
:param path: The path where to create the isolated build environment
:return: The Python executable and script folder
"""
import virtualenv

cmd = [str(path), '--no-setuptools', '--no-wheel', '--activators', '']
result = virtualenv.cli_run(cmd, setup_logging=False)
executable = str(result.creator.exe)
Expand Down

0 comments on commit 7a4b1bf

Please sign in to comment.