|
13 | 13 | import functools |
14 | 14 | import tempfile |
15 | 15 | from contextvars import ContextVar |
16 | | -from types import SimpleNamespace |
17 | 16 |
|
18 | 17 | from typing import ( |
19 | 18 | Optional, |
@@ -453,17 +452,22 @@ def detect_euid( |
453 | 452 |
|
454 | 453 | return candidate_euid if candidate_euid is not None else current_euid |
455 | 454 |
|
456 | | - def get_pw_record(self, uid: int) -> Any: |
| 455 | + def get_pw_record(self, uid: int) -> pwd.struct_passwd: |
457 | 456 | try: |
458 | 457 | return pwd.getpwuid(uid) |
459 | 458 | except KeyError: |
460 | 459 | if uid != os.geteuid(): |
461 | 460 | raise |
462 | | - return SimpleNamespace( |
463 | | - pw_uid=uid, |
464 | | - pw_gid=os.getegid(), |
465 | | - pw_dir=os.environ.get("HOME", tempfile.gettempdir()), |
466 | | - pw_name=os.environ.get("USER") or os.environ.get("LOGNAME") or str(uid), |
| 461 | + return pwd.struct_passwd( |
| 462 | + ( |
| 463 | + os.environ.get("USER") or os.environ.get("LOGNAME") or str(uid), |
| 464 | + "x", |
| 465 | + uid, |
| 466 | + os.getegid(), |
| 467 | + "", |
| 468 | + os.environ.get("HOME", tempfile.gettempdir()), |
| 469 | + os.environ.get("SHELL", "/bin/sh"), |
| 470 | + ), |
467 | 471 | ) |
468 | 472 |
|
469 | 473 | @property |
@@ -542,7 +546,7 @@ def INSTALLER_BINARY(self, no_cache: bool = False) -> ShallowBinary: |
542 | 546 | self.INSTALLER_BIN, |
543 | 547 | ) |
544 | 548 |
|
545 | | - @computed_field |
| 549 | + @computed_field(repr=False) |
546 | 550 | @property |
547 | 551 | def is_valid(self) -> bool: |
548 | 552 | try: |
@@ -985,6 +989,7 @@ def exec( |
985 | 989 | ) |
986 | 990 | cwd_path = Path(cwd).resolve() |
987 | 991 | cmd = [str(bin_abspath), *(str(arg) for arg in cmd)] |
| 992 | + is_version_probe = len(cmd) == 2 and cmd[1] in {"--version", "-version", "-v"} |
988 | 993 | exec_log_prefix = ACTIVE_EXEC_LOG_PREFIX.get() |
989 | 994 | if should_log_command: |
990 | 995 | if exec_log_prefix: |
@@ -1033,7 +1038,7 @@ def drop_privileges(): |
1033 | 1038 | except Exception: |
1034 | 1039 | pass |
1035 | 1040 |
|
1036 | | - if self.dry_run: |
| 1041 | + if self.dry_run and not is_version_probe: |
1037 | 1042 | return subprocess.CompletedProcess(cmd, 0, "", "skipped (dry run)") |
1038 | 1043 |
|
1039 | 1044 | kwargs.setdefault("capture_output", True) |
@@ -1404,15 +1409,14 @@ def install( |
1404 | 1409 | if self.dry_run: |
1405 | 1410 | # return fake ShallowBinary if we're just doing a dry run |
1406 | 1411 | # no point trying to get real abspath or version if nothing was actually installed |
1407 | | - return ShallowBinary.model_validate( |
1408 | | - { |
1409 | | - "name": bin_name, |
1410 | | - "binprovider": self, |
1411 | | - "abspath": Path(shutil.which(bin_name) or UNKNOWN_ABSPATH), |
1412 | | - "version": UNKNOWN_VERSION, |
1413 | | - "sha256": UNKNOWN_SHA256, |
1414 | | - "binproviders": [self], |
1415 | | - }, |
| 1412 | + return ShallowBinary.model_construct( |
| 1413 | + name=bin_name, |
| 1414 | + description=bin_name, |
| 1415 | + loaded_binprovider=self, |
| 1416 | + loaded_abspath=UNKNOWN_ABSPATH, |
| 1417 | + loaded_version=UNKNOWN_VERSION, |
| 1418 | + loaded_sha256=UNKNOWN_SHA256, |
| 1419 | + binproviders=[self], |
1416 | 1420 | ) |
1417 | 1421 |
|
1418 | 1422 | self.invalidate_cache(bin_name) |
@@ -1558,15 +1562,14 @@ def update( |
1558 | 1562 | ACTIVE_EXEC_LOG_PREFIX.reset(exec_log_prefix_token) |
1559 | 1563 |
|
1560 | 1564 | if self.dry_run: |
1561 | | - return ShallowBinary.model_validate( |
1562 | | - { |
1563 | | - "name": bin_name, |
1564 | | - "binprovider": self, |
1565 | | - "abspath": Path(shutil.which(bin_name) or UNKNOWN_ABSPATH), |
1566 | | - "version": UNKNOWN_VERSION, |
1567 | | - "sha256": UNKNOWN_SHA256, |
1568 | | - "binproviders": [self], |
1569 | | - }, |
| 1565 | + return ShallowBinary.model_construct( |
| 1566 | + name=bin_name, |
| 1567 | + description=bin_name, |
| 1568 | + loaded_binprovider=self, |
| 1569 | + loaded_abspath=UNKNOWN_ABSPATH, |
| 1570 | + loaded_version=UNKNOWN_VERSION, |
| 1571 | + loaded_sha256=UNKNOWN_SHA256, |
| 1572 | + binproviders=[self], |
1570 | 1573 | ) |
1571 | 1574 |
|
1572 | 1575 | self.invalidate_cache(bin_name) |
|
0 commit comments