From 80f4426b8ec76445f9b275ee80e013b8873c1c95 Mon Sep 17 00:00:00 2001 From: Ayaz Salikhov Date: Fri, 21 Feb 2025 16:28:36 +0000 Subject: [PATCH] Unify common arguments in tagging/apps (#2230) --- tagging/apps/apply_tags.py | 10 +++----- tagging/apps/common_cli_arguments.py | 34 ++++++++++++++++++++++++---- tagging/apps/merge_tags.py | 8 ++----- tagging/apps/write_manifest.py | 19 ++++++---------- tagging/apps/write_tags_file.py | 8 ++----- 5 files changed, 44 insertions(+), 35 deletions(-) diff --git a/tagging/apps/apply_tags.py b/tagging/apps/apply_tags.py index 34166029..d26ea734 100755 --- a/tagging/apps/apply_tags.py +++ b/tagging/apps/apply_tags.py @@ -42,7 +42,9 @@ def apply_tags( if __name__ == "__main__": logging.basicConfig(level=logging.INFO) - arg_parser = common_arguments_parser() + arg_parser = common_arguments_parser( + registry=True, owner=True, short_image_name=True, variant=True, tags_dir=True + ) arg_parser.add_argument( "--platform", required=True, @@ -50,12 +52,6 @@ if __name__ == "__main__": choices=["x86_64", "aarch64", "arm64"], help="Image platform", ) - arg_parser.add_argument( - "--tags-dir", - required=True, - type=Path, - help="Directory with saved tags file", - ) args = arg_parser.parse_args() args.platform = unify_aarch64(args.platform) diff --git a/tagging/apps/common_cli_arguments.py b/tagging/apps/common_cli_arguments.py index f15927c3..a00507fc 100644 --- a/tagging/apps/common_cli_arguments.py +++ b/tagging/apps/common_cli_arguments.py @@ -1,13 +1,18 @@ # Copyright (c) Jupyter Development Team. # Distributed under the terms of the Modified BSD License. import argparse +from pathlib import Path def common_arguments_parser( - registry: bool = True, - owner: bool = True, - short_image_name: bool = True, - variant: bool = True, + *, + registry: bool = False, + owner: bool = False, + short_image_name: bool = False, + variant: bool = False, + tags_dir: bool = False, + hist_lines_dir: bool = False, + manifests_dir: bool = False, ) -> argparse.ArgumentParser: """Add common CLI arguments to parser""" @@ -37,5 +42,26 @@ def common_arguments_parser( required=True, help="Variant tag prefix", ) + if tags_dir: + parser.add_argument( + "--tags-dir", + required=True, + type=Path, + help="Directory for tags file", + ) + if hist_lines_dir: + parser.add_argument( + "--hist-lines-dir", + required=True, + type=Path, + help="Directory for hist_lines file", + ) + if manifests_dir: + parser.add_argument( + "--manifests-dir", + required=True, + type=Path, + help="Directory for manifests file", + ) return parser diff --git a/tagging/apps/merge_tags.py b/tagging/apps/merge_tags.py index d9f0432b..2352a5a5 100755 --- a/tagging/apps/merge_tags.py +++ b/tagging/apps/merge_tags.py @@ -61,12 +61,8 @@ def merge_tags( if __name__ == "__main__": logging.basicConfig(level=logging.INFO) - arg_parser = common_arguments_parser(registry=False, owner=False) - arg_parser.add_argument( - "--tags-dir", - required=True, - type=Path, - help="Directory with saved tags file", + arg_parser = common_arguments_parser( + short_image_name=True, variant=True, tags_dir=True ) args = arg_parser.parse_args() diff --git a/tagging/apps/write_manifest.py b/tagging/apps/write_manifest.py index 30d07648..1002fb76 100755 --- a/tagging/apps/write_manifest.py +++ b/tagging/apps/write_manifest.py @@ -119,18 +119,13 @@ def write_manifest( if __name__ == "__main__": logging.basicConfig(level=logging.INFO) - arg_parser = common_arguments_parser() - arg_parser.add_argument( - "--hist-lines-dir", - required=True, - type=Path, - help="Directory to save history line", - ) - arg_parser.add_argument( - "--manifests-dir", - required=True, - type=Path, - help="Directory to save manifest file", + arg_parser = common_arguments_parser( + registry=True, + owner=True, + short_image_name=True, + variant=True, + hist_lines_dir=True, + manifests_dir=True, ) args = arg_parser.parse_args() diff --git a/tagging/apps/write_tags_file.py b/tagging/apps/write_tags_file.py index f32ad925..8192ba6e 100755 --- a/tagging/apps/write_tags_file.py +++ b/tagging/apps/write_tags_file.py @@ -51,12 +51,8 @@ def write_tags_file( if __name__ == "__main__": logging.basicConfig(level=logging.INFO) - arg_parser = common_arguments_parser() - arg_parser.add_argument( - "--tags-dir", - required=True, - type=Path, - help="Directory to save tags file", + arg_parser = common_arguments_parser( + registry=True, owner=True, short_image_name=True, variant=True, tags_dir=True ) args = arg_parser.parse_args()