Skip to content

Commit

Permalink
[pre-commit.ci] pre-commit autoupdate (#2799)
Browse files Browse the repository at this point in the history
Signed-off-by: Bernát Gábor <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Bernát Gábor <[email protected]>
  • Loading branch information
pre-commit-ci[bot] and gaborbernat authored Nov 26, 2024
1 parent be19526 commit f5d7cb4
Show file tree
Hide file tree
Showing 28 changed files with 124 additions and 76 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ repos:
hooks:
- id: pyproject-fmt
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.7.2"
rev: "v0.8.0"
hooks:
- id: ruff-format
- id: ruff
Expand Down
8 changes: 5 additions & 3 deletions src/virtualenv/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import sys
from timeit import default_timer

LOGGER = logging.getLogger(__name__)


def run(args=None, options=None, env=None):
env = os.environ if env is None else env
Expand All @@ -16,7 +18,7 @@ def run(args=None, options=None, env=None):
args = sys.argv[1:]
try:
session = cli_run(args, options, env)
logging.warning(LogSession(session, start))
LOGGER.warning(LogSession(session, start))
except ProcessCallFailedError as exception:
print(f"subprocess call failed for {exception.cmd} with code {exception.code}") # noqa: T201
print(exception.out, file=sys.stdout, end="") # noqa: T201
Expand Down Expand Up @@ -59,11 +61,11 @@ def run_with_catch(args=None, env=None):
if getattr(options, "with_traceback", False):
raise
if not (isinstance(exception, SystemExit) and exception.code == 0):
logging.error("%s: %s", type(exception).__name__, exception) # noqa: TRY400
LOGGER.error("%s: %s", type(exception).__name__, exception) # noqa: TRY400
code = exception.code if isinstance(exception, SystemExit) else 1
sys.exit(code)
finally:
logging.shutdown() # force flush of log messages before the trace is printed
LOGGER.shutdown() # force flush of log messages before the trace is printed


if __name__ == "__main__": # pragma: no cov
Expand Down
8 changes: 5 additions & 3 deletions src/virtualenv/app_data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from .via_disk_folder import AppDataDiskFolder
from .via_tempdir import TempAppData

LOGGER = logging.getLogger(__name__)


def _default_app_data_dir(env):
key = "VIRTUALENV_OVERRIDE_APP_DATA"
Expand All @@ -37,13 +39,13 @@ def make_app_data(folder, **kwargs):
if not os.path.isdir(folder):
try:
os.makedirs(folder)
logging.debug("created app data folder %s", folder)
LOGGER.debug("created app data folder %s", folder)
except OSError as exception:
logging.info("could not create app data folder %s due to %r", folder, exception)
LOGGER.info("could not create app data folder %s due to %r", folder, exception)

if os.access(folder, os.W_OK):
return AppDataDiskFolder(folder)
logging.debug("app data folder %s has no write access", folder)
LOGGER.debug("app data folder %s has no write access", folder)
return TempAppData()


Expand Down
10 changes: 6 additions & 4 deletions src/virtualenv/app_data/via_disk_folder.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@

from .base import AppData, ContentStore

LOGGER = logging.getLogger(__name__)


class AppDataDiskFolder(AppData):
"""Store the application data on the disk within a folder layout."""
Expand All @@ -54,7 +56,7 @@ def __str__(self) -> str:
return str(self.lock.path)

def reset(self):
logging.debug("reset app data folder %s", self.lock.path)
LOGGER.debug("reset app data folder %s", self.lock.path)
safe_delete(self.lock.path)

def close(self):
Expand Down Expand Up @@ -128,7 +130,7 @@ def read(self):
except Exception: # noqa: BLE001, S110
pass
else:
logging.debug("got %s from %s", self.msg, self.msg_args)
LOGGER.debug("got %s from %s", self.msg, self.msg_args)
return data
if bad_format:
with suppress(OSError): # reading and writing on the same file may cause race on multiple processes
Expand All @@ -137,7 +139,7 @@ def read(self):

def remove(self):
self.file.unlink()
logging.debug("removed %s at %s", self.msg, self.msg_args)
LOGGER.debug("removed %s at %s", self.msg, self.msg_args)

@contextmanager
def locked(self):
Expand All @@ -148,7 +150,7 @@ def write(self, content):
folder = self.file.parent
folder.mkdir(parents=True, exist_ok=True)
self.file.write_text(json.dumps(content, sort_keys=True, indent=2), encoding="utf-8")
logging.debug("wrote %s at %s", self.msg, self.msg_args)
LOGGER.debug("wrote %s at %s", self.msg, self.msg_args)


class PyInfoStoreDisk(JSONStoreDisk):
Expand Down
6 changes: 4 additions & 2 deletions src/virtualenv/app_data/via_tempdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,22 @@

from .via_disk_folder import AppDataDiskFolder

LOGGER = logging.getLogger(__name__)


class TempAppData(AppDataDiskFolder):
transient = True
can_update = False

def __init__(self) -> None:
super().__init__(folder=mkdtemp())
logging.debug("created temporary app data folder %s", self.lock.path)
LOGGER.debug("created temporary app data folder %s", self.lock.path)

def reset(self):
"""This is a temporary folder, is already empty to start with."""

def close(self):
logging.debug("remove temporary app data folder %s", self.lock.path)
LOGGER.debug("remove temporary app data folder %s", self.lock.path)
safe_delete(self.lock.path)

def embed_update_log(self, distribution, for_py_version):
Expand Down
4 changes: 3 additions & 1 deletion src/virtualenv/config/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import os
from typing import ClassVar

LOGGER = logging.getLogger(__name__)


class TypeData:
def __init__(self, default_type, as_type) -> None:
Expand Down Expand Up @@ -81,7 +83,7 @@ def convert(value, as_type, source):
try:
return as_type.convert(value)
except Exception as exception:
logging.warning("%s failed to convert %r as %r because %r", source, value, as_type, exception)
LOGGER.warning("%s failed to convert %r as %r because %r", source, value, as_type, exception)
raise


Expand Down
4 changes: 3 additions & 1 deletion src/virtualenv/config/ini.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

from .convert import convert

LOGGER = logging.getLogger(__name__)


class IniConfig:
VIRTUALENV_CONFIG_FILE_ENV_VAR: ClassVar[str] = "VIRTUALENV_CONFIG_FILE"
Expand Down Expand Up @@ -44,7 +46,7 @@ def __init__(self, env=None) -> None:
except Exception as exc: # noqa: BLE001
exception = exc
if exception is not None:
logging.error("failed to read config file %s because %r", config_file, exception)
LOGGER.error("failed to read config file %s because %r", config_file, exception)

def _load(self):
with self.config_file.open("rt", encoding="utf-8") as file_handler:
Expand Down
5 changes: 3 additions & 2 deletions src/virtualenv/create/creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

HERE = Path(os.path.abspath(__file__)).parent
DEBUG_SCRIPT = HERE / "debug.py"
LOGGER = logging.getLogger(__name__)


class CreatorMeta:
Expand Down Expand Up @@ -154,7 +155,7 @@ def non_write_able(dest, value):

def run(self):
if self.dest.exists() and self.clear:
logging.debug("delete %s", self.dest)
LOGGER.debug("delete %s", self.dest)
safe_delete(self.dest)
self.create()
self.add_cachedir_tag()
Expand Down Expand Up @@ -219,7 +220,7 @@ def get_env_debug_info(env_exe, debug_script, app_data, env):

with app_data.ensure_extracted(debug_script) as debug_script_extracted:
cmd = [str(env_exe), str(debug_script_extracted)]
logging.debug("debug via %r", LogCmd(cmd))
LOGGER.debug("debug via %r", LogCmd(cmd))
code, out, err = run_cmd(cmd)

try:
Expand Down
6 changes: 4 additions & 2 deletions src/virtualenv/create/pyenv_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import os
from collections import OrderedDict

LOGGER = logging.getLogger(__name__)


class PyEnvCfg:
def __init__(self, content, path) -> None:
Expand All @@ -30,12 +32,12 @@ def _read_values(path):
return content

def write(self):
logging.debug("write %s", self.path)
LOGGER.debug("write %s", self.path)
text = ""
for key, value in self.content.items():
normalized_value = os.path.realpath(value) if value and os.path.exists(value) else value
line = f"{key} = {normalized_value}"
logging.debug("\t%s", line)
LOGGER.debug("\t%s", line)
text += line
text += "\n"
self.path.write_text(text, encoding="utf-8")
Expand Down
6 changes: 4 additions & 2 deletions src/virtualenv/create/via_global_ref/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
from virtualenv.create.creator import Creator, CreatorMeta
from virtualenv.info import fs_supports_symlink

LOGGER = logging.getLogger(__name__)


class ViaGlobalRefMeta(CreatorMeta):
def __init__(self) -> None:
Expand Down Expand Up @@ -88,10 +90,10 @@ def install_patch(self):
text = self.env_patch_text()
if text:
pth = self.purelib / "_virtualenv.pth"
logging.debug("create virtualenv import hook file %s", pth)
LOGGER.debug("create virtualenv import hook file %s", pth)
pth.write_text("import _virtualenv", encoding="utf-8")
dest_path = self.purelib / "_virtualenv.py"
logging.debug("create %s", dest_path)
LOGGER.debug("create %s", dest_path)
dest_path.write_text(text, encoding="utf-8")

def env_patch_text(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
from .common import CPython, CPythonPosix, is_mac_os_framework, is_macos_brew
from .cpython3 import CPython3

LOGGER = logging.getLogger(__name__)


class CPythonmacOsFramework(CPython, ABC):
@classmethod
Expand Down Expand Up @@ -115,10 +117,10 @@ def fix_mach_o(exe, current, new, max_size):
unneeded bits of information, however Mac OS X 10.5 and earlier cannot read this new Link Edit table format.
"""
try:
logging.debug("change Mach-O for %s from %s to %s", exe, current, new)
LOGGER.debug("change Mach-O for %s from %s to %s", exe, current, new)
_builtin_change_mach_o(max_size)(exe, current, new)
except Exception as e: # noqa: BLE001
logging.warning("Could not call _builtin_change_mac_o: %s. Trying to call install_name_tool instead.", e)
LOGGER.warning("Could not call _builtin_change_mac_o: %s. Trying to call install_name_tool instead.", e)
try:
cmd = ["install_name_tool", "-change", current, new, exe]
subprocess.check_call(cmd)
Expand Down
4 changes: 3 additions & 1 deletion src/virtualenv/create/via_global_ref/venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
from .builtin.cpython.mac_os import CPython3macOsBrew
from .builtin.pypy.pypy3 import Pypy3Windows

LOGGER = logging.getLogger(__name__)


class Venv(ViaGlobalRefApi):
def __init__(self, options, interpreter) -> None:
Expand Down Expand Up @@ -70,7 +72,7 @@ def create_inline(self):

def create_via_sub_process(self):
cmd = self.get_host_create_cmd()
logging.info("using host built-in venv to create via %s", " ".join(cmd))
LOGGER.info("using host built-in venv to create via %s", " ".join(cmd))
code, out, err = run_cmd(cmd)
if code != 0:
raise ProcessCallFailedError(code, out, err, cmd)
Expand Down
9 changes: 5 additions & 4 deletions src/virtualenv/discovery/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from collections.abc import Generator, Iterable, Mapping, Sequence

from virtualenv.app_data.base import AppData
LOGGER = logging.getLogger(__name__)


class Builtin(Discover):
Expand Down Expand Up @@ -70,16 +71,16 @@ def get_interpreter(
key, try_first_with: Iterable[str], app_data: AppData | None = None, env: Mapping[str, str] | None = None
) -> PythonInfo | None:
spec = PythonSpec.from_string_spec(key)
logging.info("find interpreter for spec %r", spec)
LOGGER.info("find interpreter for spec %r", spec)
proposed_paths = set()
env = os.environ if env is None else env
for interpreter, impl_must_match in propose_interpreters(spec, try_first_with, app_data, env):
key = interpreter.system_executable, impl_must_match
if key in proposed_paths:
continue
logging.info("proposed %s", interpreter)
LOGGER.info("proposed %s", interpreter)
if interpreter.satisfies(spec, impl_must_match):
logging.debug("accepted %s", interpreter)
LOGGER.debug("accepted %s", interpreter)
return interpreter
proposed_paths.add(key)
return None
Expand Down Expand Up @@ -146,7 +147,7 @@ def propose_interpreters( # noqa: C901, PLR0912, PLR0915
# finally just find on path, the path order matters (as the candidates are less easy to control by end user)
find_candidates = path_exe_finder(spec)
for pos, path in enumerate(get_paths(env)):
logging.debug(LazyPathDump(pos, path, env))
LOGGER.debug(LazyPathDump(pos, path, env))
for exe, impl_must_match in find_candidates(path):
exe_raw = str(exe)
exe_id = fs_path_id(exe_raw)
Expand Down
5 changes: 3 additions & 2 deletions src/virtualenv/discovery/cached_py_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

_CACHE = OrderedDict()
_CACHE[Path(sys.executable)] = PythonInfo()
LOGGER = logging.getLogger(__name__)


def from_exe(cls, app_data, exe, env=None, raise_on_error=True, ignore_cache=False): # noqa: FBT002, PLR0913
Expand All @@ -31,7 +32,7 @@ def from_exe(cls, app_data, exe, env=None, raise_on_error=True, ignore_cache=Fal
if isinstance(result, Exception):
if raise_on_error:
raise result
logging.info("%s", result)
LOGGER.info("%s", result)
result = None
return result

Expand Down Expand Up @@ -109,7 +110,7 @@ def _run_subprocess(cls, exe, app_data, env):
# prevent sys.prefix from leaking into the child process - see https://bugs.python.org/issue22490
env = env.copy()
env.pop("__PYVENV_LAUNCHER__", None)
logging.debug("get interpreter info via cmd: %s", LogCmd(cmd))
LOGGER.debug("get interpreter info via cmd: %s", LogCmd(cmd))
try:
process = Popen(
cmd,
Expand Down
Loading

0 comments on commit f5d7cb4

Please sign in to comment.