Skip to content

Commit ef3f8e3

Browse files
committed
apply fix from FHPythonUtils/LicenseCheck#149; remove stdin support
1 parent 26d204d commit ef3f8e3

3 files changed

Lines changed: 31 additions & 38 deletions

File tree

attestationcheck/io/cli.py

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44

55
import argparse
66
from dataclasses import fields
7+
from enum import Enum
78
from pathlib import Path
89
from sys import exit as sysexit
9-
from sys import stdin, stdout
10+
from sys import stdout
1011

1112
from configurator import Config
1213
from configurator.node import ConfigNode
@@ -19,6 +20,12 @@
1920
stdout.reconfigure(encoding="utf-8") # type: ignore[general-type-issues]
2021

2122

23+
class ExitCode(Enum):
24+
SUCCESS = 0
25+
UNVERIFIED_PACKAGE = 1
26+
NO_PACKAGES = 3
27+
28+
2229
def cli() -> None: # pragma: no cover
2330
"""Cli entry point."""
2431
parser = argparse.ArgumentParser(description=__doc__, argument_default=argparse.SUPPRESS)
@@ -80,12 +87,8 @@ def cli() -> None: # pragma: no cover
8087
)
8188
args = vars(parser.parse_args())
8289

83-
stdin_path = Path("__stdin__")
8490
if not args.get("requirements_paths"):
85-
if stdin.isatty():
86-
args["requirements_paths"] = ["pyproject.toml"]
87-
else:
88-
stdin_path.write_text("\n".join(stdin.readlines()), encoding="utf-8")
91+
args["requirements_paths"] = ["pyproject.toml"]
8992

9093
config: ConfigNode = Config()
9194

@@ -105,14 +108,13 @@ def cli() -> None: # pragma: no cover
105108
attestationcheckConf: LC_Config = LC_Config.model_validate({**scopedData.data, **args})
106109

107110
ec = main(attestationcheckConf)
108-
stdin_path.unlink(missing_ok=True)
109111

110-
sysexit(ec)
112+
sysexit(ec.value)
111113

112114

113-
def main(attestationcheckConf: LC_Config) -> int:
115+
def main(attestationcheckConf: LC_Config) -> ExitCode:
114116
"""Test entry point."""
115-
exitCode = 0
117+
exitCode = ExitCode.SUCCESS
116118

117119
# File
118120
requirements_paths = attestationcheckConf.requirements_paths or {"__stdin__"}
@@ -148,23 +150,22 @@ def main(attestationcheckConf: LC_Config) -> int:
148150
)
149151
raise ValueError(msg)
150152

151-
format_ = attestationcheckConf.format or "simple"
152-
if attestationcheckConf.format in fmt.formatMap:
153-
print(
154-
fmt.fmt(
155-
format_,
156-
sorted(all_packages),
157-
hide_output_parameters,
158-
show_only_failing=attestationcheckConf.show_only_failing,
159-
),
160-
file=output_file,
161-
)
162-
else:
163-
exitCode = 2
153+
print(
154+
fmt.fmt(
155+
attestationcheckConf.format,
156+
sorted(all_packages),
157+
hide_output_parameters,
158+
show_only_failing=attestationcheckConf.show_only_failing,
159+
),
160+
file=output_file,
161+
)
164162

165163
# Exit code of 1 if args.zero
166-
if attestationcheckConf.zero and incompatible:
167-
exitCode = 1
164+
if attestationcheckConf.zero:
165+
if len(all_packages) == 0:
166+
exitCode = ExitCode.NO_PACKAGES
167+
if incompatible:
168+
exitCode = ExitCode.UNVERIFIED_PACKAGE
168169

169170
# Cleanup + exit
170171
if attestationcheckConf.file not in [None, ""]:

attestationcheck/session.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@
44
dirs = PlatformDirs("attestationcheck", "fredhappyface")
55

66

7-
session = requests_cache.CachedSession(dirs.user_cache_dir)
7+
session = requests_cache.CachedSession(
8+
dirs.user_cache_dir,
9+
busy_timeout=5000,
10+
)

pyproject.toml

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "attestationcheck"
3-
version = "0.2.1"
3+
version = "0.2.2"
44
description = "Output the attestation status used by dependencies. e.g. Verified, Valid, Supported by package host etc."
55
authors = [{ name = "FredHappyface" }]
66
requires-python = ">=3.12"
@@ -95,17 +95,6 @@ venvPath = "."
9595
venv = ".venv"
9696
typeCheckingMode = "standard"
9797

98-
[tool.attestationcheck]
99-
format = "simple" # Output format (e.g., "json", "csv", etc.)
100-
requirements_paths = [] # List of filenames to read from
101-
groups = [] # List of selected groups
102-
extras = [] # List of selected extras
103-
file = "" # Output file (leave empty for stdout)
104-
skip_dependencies = [] # Dependencies to skip (compatibility = True)
105-
hide_output_parameters = [] # Parameters to hide from output
106-
show_only_failing = false # Show only incompatible/failing packages
107-
pypi_api = "https://pypi.org" # Custom PyPI API endpoint
108-
zero = false # Return non-zero exit code
10998

11099

111100
[tool.tox]

0 commit comments

Comments
 (0)