Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

main: avoid cost of importing virtualenv if not using it #636

Merged
merged 1 commit into from
Jul 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/build/env.py
Original file line number Diff line number Diff line change
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 @@
# 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 @@
:param path: The path where to create the isolated build environment
:return: The Python executable and script folder
"""
import virtualenv

Check warning on line 169 in src/build/env.py

View check run for this annotation

Codecov / codecov/patch

src/build/env.py#L169

Added line #L169 was not covered by tests

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