Skip to content

Commit f5d7cb4

Browse files
[pre-commit.ci] pre-commit autoupdate (#2799)
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]>
1 parent be19526 commit f5d7cb4

File tree

28 files changed

+124
-76
lines changed

28 files changed

+124
-76
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ repos:
2424
hooks:
2525
- id: pyproject-fmt
2626
- repo: https://github.com/astral-sh/ruff-pre-commit
27-
rev: "v0.7.2"
27+
rev: "v0.8.0"
2828
hooks:
2929
- id: ruff-format
3030
- id: ruff

src/virtualenv/__main__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import sys
66
from timeit import default_timer
77

8+
LOGGER = logging.getLogger(__name__)
9+
810

911
def run(args=None, options=None, env=None):
1012
env = os.environ if env is None else env
@@ -16,7 +18,7 @@ def run(args=None, options=None, env=None):
1618
args = sys.argv[1:]
1719
try:
1820
session = cli_run(args, options, env)
19-
logging.warning(LogSession(session, start))
21+
LOGGER.warning(LogSession(session, start))
2022
except ProcessCallFailedError as exception:
2123
print(f"subprocess call failed for {exception.cmd} with code {exception.code}") # noqa: T201
2224
print(exception.out, file=sys.stdout, end="") # noqa: T201
@@ -59,11 +61,11 @@ def run_with_catch(args=None, env=None):
5961
if getattr(options, "with_traceback", False):
6062
raise
6163
if not (isinstance(exception, SystemExit) and exception.code == 0):
62-
logging.error("%s: %s", type(exception).__name__, exception) # noqa: TRY400
64+
LOGGER.error("%s: %s", type(exception).__name__, exception) # noqa: TRY400
6365
code = exception.code if isinstance(exception, SystemExit) else 1
6466
sys.exit(code)
6567
finally:
66-
logging.shutdown() # force flush of log messages before the trace is printed
68+
LOGGER.shutdown() # force flush of log messages before the trace is printed
6769

6870

6971
if __name__ == "__main__": # pragma: no cov

src/virtualenv/app_data/__init__.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
from .via_disk_folder import AppDataDiskFolder
1313
from .via_tempdir import TempAppData
1414

15+
LOGGER = logging.getLogger(__name__)
16+
1517

1618
def _default_app_data_dir(env):
1719
key = "VIRTUALENV_OVERRIDE_APP_DATA"
@@ -37,13 +39,13 @@ def make_app_data(folder, **kwargs):
3739
if not os.path.isdir(folder):
3840
try:
3941
os.makedirs(folder)
40-
logging.debug("created app data folder %s", folder)
42+
LOGGER.debug("created app data folder %s", folder)
4143
except OSError as exception:
42-
logging.info("could not create app data folder %s due to %r", folder, exception)
44+
LOGGER.info("could not create app data folder %s due to %r", folder, exception)
4345

4446
if os.access(folder, os.W_OK):
4547
return AppDataDiskFolder(folder)
46-
logging.debug("app data folder %s has no write access", folder)
48+
LOGGER.debug("app data folder %s has no write access", folder)
4749
return TempAppData()
4850

4951

src/virtualenv/app_data/via_disk_folder.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737

3838
from .base import AppData, ContentStore
3939

40+
LOGGER = logging.getLogger(__name__)
41+
4042

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

5658
def reset(self):
57-
logging.debug("reset app data folder %s", self.lock.path)
59+
LOGGER.debug("reset app data folder %s", self.lock.path)
5860
safe_delete(self.lock.path)
5961

6062
def close(self):
@@ -128,7 +130,7 @@ def read(self):
128130
except Exception: # noqa: BLE001, S110
129131
pass
130132
else:
131-
logging.debug("got %s from %s", self.msg, self.msg_args)
133+
LOGGER.debug("got %s from %s", self.msg, self.msg_args)
132134
return data
133135
if bad_format:
134136
with suppress(OSError): # reading and writing on the same file may cause race on multiple processes
@@ -137,7 +139,7 @@ def read(self):
137139

138140
def remove(self):
139141
self.file.unlink()
140-
logging.debug("removed %s at %s", self.msg, self.msg_args)
142+
LOGGER.debug("removed %s at %s", self.msg, self.msg_args)
141143

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

153155

154156
class PyInfoStoreDisk(JSONStoreDisk):

src/virtualenv/app_data/via_tempdir.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,22 @@
77

88
from .via_disk_folder import AppDataDiskFolder
99

10+
LOGGER = logging.getLogger(__name__)
11+
1012

1113
class TempAppData(AppDataDiskFolder):
1214
transient = True
1315
can_update = False
1416

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

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

2224
def close(self):
23-
logging.debug("remove temporary app data folder %s", self.lock.path)
25+
LOGGER.debug("remove temporary app data folder %s", self.lock.path)
2426
safe_delete(self.lock.path)
2527

2628
def embed_update_log(self, distribution, for_py_version):

src/virtualenv/config/convert.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import os
55
from typing import ClassVar
66

7+
LOGGER = logging.getLogger(__name__)
8+
79

810
class TypeData:
911
def __init__(self, default_type, as_type) -> None:
@@ -81,7 +83,7 @@ def convert(value, as_type, source):
8183
try:
8284
return as_type.convert(value)
8385
except Exception as exception:
84-
logging.warning("%s failed to convert %r as %r because %r", source, value, as_type, exception)
86+
LOGGER.warning("%s failed to convert %r as %r because %r", source, value, as_type, exception)
8587
raise
8688

8789

src/virtualenv/config/ini.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
from .convert import convert
1212

13+
LOGGER = logging.getLogger(__name__)
14+
1315

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

4951
def _load(self):
5052
with self.config_file.open("rt", encoding="utf-8") as file_handler:

src/virtualenv/create/creator.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

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

2425

2526
class CreatorMeta:
@@ -154,7 +155,7 @@ def non_write_able(dest, value):
154155

155156
def run(self):
156157
if self.dest.exists() and self.clear:
157-
logging.debug("delete %s", self.dest)
158+
LOGGER.debug("delete %s", self.dest)
158159
safe_delete(self.dest)
159160
self.create()
160161
self.add_cachedir_tag()
@@ -219,7 +220,7 @@ def get_env_debug_info(env_exe, debug_script, app_data, env):
219220

220221
with app_data.ensure_extracted(debug_script) as debug_script_extracted:
221222
cmd = [str(env_exe), str(debug_script_extracted)]
222-
logging.debug("debug via %r", LogCmd(cmd))
223+
LOGGER.debug("debug via %r", LogCmd(cmd))
223224
code, out, err = run_cmd(cmd)
224225

225226
try:

src/virtualenv/create/pyenv_cfg.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import os
55
from collections import OrderedDict
66

7+
LOGGER = logging.getLogger(__name__)
8+
79

810
class PyEnvCfg:
911
def __init__(self, content, path) -> None:
@@ -30,12 +32,12 @@ def _read_values(path):
3032
return content
3133

3234
def write(self):
33-
logging.debug("write %s", self.path)
35+
LOGGER.debug("write %s", self.path)
3436
text = ""
3537
for key, value in self.content.items():
3638
normalized_value = os.path.realpath(value) if value and os.path.exists(value) else value
3739
line = f"{key} = {normalized_value}"
38-
logging.debug("\t%s", line)
40+
LOGGER.debug("\t%s", line)
3941
text += line
4042
text += "\n"
4143
self.path.write_text(text, encoding="utf-8")

src/virtualenv/create/via_global_ref/api.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
from virtualenv.create.creator import Creator, CreatorMeta
99
from virtualenv.info import fs_supports_symlink
1010

11+
LOGGER = logging.getLogger(__name__)
12+
1113

1214
class ViaGlobalRefMeta(CreatorMeta):
1315
def __init__(self) -> None:
@@ -88,10 +90,10 @@ def install_patch(self):
8890
text = self.env_patch_text()
8991
if text:
9092
pth = self.purelib / "_virtualenv.pth"
91-
logging.debug("create virtualenv import hook file %s", pth)
93+
LOGGER.debug("create virtualenv import hook file %s", pth)
9294
pth.write_text("import _virtualenv", encoding="utf-8")
9395
dest_path = self.purelib / "_virtualenv.py"
94-
logging.debug("create %s", dest_path)
96+
LOGGER.debug("create %s", dest_path)
9597
dest_path.write_text(text, encoding="utf-8")
9698

9799
def env_patch_text(self):

src/virtualenv/create/via_global_ref/builtin/cpython/mac_os.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
from .common import CPython, CPythonPosix, is_mac_os_framework, is_macos_brew
2121
from .cpython3 import CPython3
2222

23+
LOGGER = logging.getLogger(__name__)
24+
2325

2426
class CPythonmacOsFramework(CPython, ABC):
2527
@classmethod
@@ -115,10 +117,10 @@ def fix_mach_o(exe, current, new, max_size):
115117
unneeded bits of information, however Mac OS X 10.5 and earlier cannot read this new Link Edit table format.
116118
"""
117119
try:
118-
logging.debug("change Mach-O for %s from %s to %s", exe, current, new)
120+
LOGGER.debug("change Mach-O for %s from %s to %s", exe, current, new)
119121
_builtin_change_mach_o(max_size)(exe, current, new)
120122
except Exception as e: # noqa: BLE001
121-
logging.warning("Could not call _builtin_change_mac_o: %s. Trying to call install_name_tool instead.", e)
123+
LOGGER.warning("Could not call _builtin_change_mac_o: %s. Trying to call install_name_tool instead.", e)
122124
try:
123125
cmd = ["install_name_tool", "-change", current, new, exe]
124126
subprocess.check_call(cmd)

src/virtualenv/create/via_global_ref/venv.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
from .builtin.cpython.mac_os import CPython3macOsBrew
1414
from .builtin.pypy.pypy3 import Pypy3Windows
1515

16+
LOGGER = logging.getLogger(__name__)
17+
1618

1719
class Venv(ViaGlobalRefApi):
1820
def __init__(self, options, interpreter) -> None:
@@ -70,7 +72,7 @@ def create_inline(self):
7072

7173
def create_via_sub_process(self):
7274
cmd = self.get_host_create_cmd()
73-
logging.info("using host built-in venv to create via %s", " ".join(cmd))
75+
LOGGER.info("using host built-in venv to create via %s", " ".join(cmd))
7476
code, out, err = run_cmd(cmd)
7577
if code != 0:
7678
raise ProcessCallFailedError(code, out, err, cmd)

src/virtualenv/discovery/builtin.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from collections.abc import Generator, Iterable, Mapping, Sequence
1919

2020
from virtualenv.app_data.base import AppData
21+
LOGGER = logging.getLogger(__name__)
2122

2223

2324
class Builtin(Discover):
@@ -70,16 +71,16 @@ def get_interpreter(
7071
key, try_first_with: Iterable[str], app_data: AppData | None = None, env: Mapping[str, str] | None = None
7172
) -> PythonInfo | None:
7273
spec = PythonSpec.from_string_spec(key)
73-
logging.info("find interpreter for spec %r", spec)
74+
LOGGER.info("find interpreter for spec %r", spec)
7475
proposed_paths = set()
7576
env = os.environ if env is None else env
7677
for interpreter, impl_must_match in propose_interpreters(spec, try_first_with, app_data, env):
7778
key = interpreter.system_executable, impl_must_match
7879
if key in proposed_paths:
7980
continue
80-
logging.info("proposed %s", interpreter)
81+
LOGGER.info("proposed %s", interpreter)
8182
if interpreter.satisfies(spec, impl_must_match):
82-
logging.debug("accepted %s", interpreter)
83+
LOGGER.debug("accepted %s", interpreter)
8384
return interpreter
8485
proposed_paths.add(key)
8586
return None
@@ -146,7 +147,7 @@ def propose_interpreters( # noqa: C901, PLR0912, PLR0915
146147
# finally just find on path, the path order matters (as the candidates are less easy to control by end user)
147148
find_candidates = path_exe_finder(spec)
148149
for pos, path in enumerate(get_paths(env)):
149-
logging.debug(LazyPathDump(pos, path, env))
150+
LOGGER.debug(LazyPathDump(pos, path, env))
150151
for exe, impl_must_match in find_candidates(path):
151152
exe_raw = str(exe)
152153
exe_id = fs_path_id(exe_raw)

src/virtualenv/discovery/cached_py_info.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
_CACHE = OrderedDict()
2525
_CACHE[Path(sys.executable)] = PythonInfo()
26+
LOGGER = logging.getLogger(__name__)
2627

2728

2829
def from_exe(cls, app_data, exe, env=None, raise_on_error=True, ignore_cache=False): # noqa: FBT002, PLR0913
@@ -31,7 +32,7 @@ def from_exe(cls, app_data, exe, env=None, raise_on_error=True, ignore_cache=Fal
3132
if isinstance(result, Exception):
3233
if raise_on_error:
3334
raise result
34-
logging.info("%s", result)
35+
LOGGER.info("%s", result)
3536
result = None
3637
return result
3738

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

0 commit comments

Comments
 (0)