From b9c017034b5ccd217c31ebc2b44669a92f553f16 Mon Sep 17 00:00:00 2001 From: chrysle <96722107+chrysle@users.noreply.github.com> Date: Fri, 3 May 2024 21:03:08 +0200 Subject: [PATCH 1/4] Add support for JSON output format --- piptools/scripts/compile.py | 3 ++ piptools/scripts/options.py | 4 ++ piptools/utils.py | 3 +- piptools/writer.py | 89 ++++++++++++++++++++++++++++++------- tests/test_writer.py | 19 ++++---- 5 files changed, 91 insertions(+), 27 deletions(-) diff --git a/piptools/scripts/compile.py b/piptools/scripts/compile.py index 2b4522eb..bcbb65ce 100755 --- a/piptools/scripts/compile.py +++ b/piptools/scripts/compile.py @@ -82,6 +82,7 @@ def _determine_linesep( @options.color @options.verbose @options.quiet +@options.json @options.dry_run @options.pre @options.rebuild @@ -127,6 +128,7 @@ def cli( color: bool | None, verbose: int, quiet: int, + json: bool, dry_run: bool, pre: bool, rebuild: bool, @@ -514,6 +516,7 @@ def cli( cast(BinaryIO, output_file), click_ctx=ctx, dry_run=dry_run, + json_output=json, emit_header=header, emit_index_url=emit_index_url, emit_trusted_host=emit_trusted_host, diff --git a/piptools/scripts/options.py b/piptools/scripts/options.py index 98fbbf7a..77f3a890 100644 --- a/piptools/scripts/options.py +++ b/piptools/scripts/options.py @@ -52,6 +52,10 @@ def _get_default_option(option_name: str) -> Any: help="Give less output", ) +json = click.option( + "-j", "--json", is_flag=True, default=False, help="Emit JSON output" +) + dry_run = click.option( "-n", "--dry-run", diff --git a/piptools/utils.py b/piptools/utils.py index 8d04f7a7..39a51e92 100644 --- a/piptools/utils.py +++ b/piptools/utils.py @@ -58,6 +58,7 @@ "--cache-dir", "--no-reuse-hashes", "--no-config", + "--json", } # Set of option that are only negative, i.e. --no-