Skip to content

Commit feb8cdf

Browse files
committed
Add support to change lint output format from environment
Use REUSE_OUTPUT_FORMAT to allow overriding lint output formats in certain environments (like CI).
1 parent e60c289 commit feb8cdf

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

changelog.d/added/format-env.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Added `REUSE_OUTPUT_FORMAT` environment variable to configure output for
2+
`lint`.

docs/man/reuse-lint.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,12 @@ Options
103103
.. option:: -h, --help
104104

105105
Display help and exit.
106+
107+
Environment
108+
-----------
109+
110+
.. envvar:: REUSE_OUTPUT_FORMAT
111+
112+
Specifies output format, one of ``plain``, ``lines``, ``github``, ``json``
113+
114+
It behaves same as corresponding command line options.

src/reuse/lint.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"""
1212

1313
import json
14+
import os
1415
import sys
1516
from argparse import ArgumentParser, Namespace
1617
from gettext import gettext as _
@@ -374,15 +375,26 @@ def run(args: Namespace, project: Project, out: IO[str] = sys.stdout) -> int:
374375
project, do_checksum=False, multiprocessing=not args.no_multiprocessing
375376
)
376377

377-
if args.quiet:
378-
pass
379-
elif args.json:
380-
out.write(format_json(report))
381-
elif args.lines:
382-
out.write(format_lines(report))
383-
elif args.github:
384-
out.write(format_github(report))
385-
else:
386-
out.write(format_plain(report))
378+
formatters = {
379+
"json": format_json,
380+
"lines": format_lines,
381+
"github": format_github,
382+
"plain": format_plain,
383+
}
384+
385+
if not args.quiet:
386+
output_format = os.environ.get("REUSE_OUTPUT_FORMAT")
387+
388+
if output_format is not None and output_format in formatters:
389+
formatter = formatters[output_format]
390+
out.write(formatter(report))
391+
elif args.json:
392+
out.write(format_json(report))
393+
elif args.lines:
394+
out.write(format_lines(report))
395+
elif args.github:
396+
out.write(format_github(report))
397+
else:
398+
out.write(format_plain(report))
387399

388400
return 0 if report.is_compliant else 1

0 commit comments

Comments
 (0)