Unify common arguments in tagging/apps (#2230)

This commit is contained in:
Ayaz Salikhov
2025-02-21 16:28:36 +00:00
committed by GitHub
parent db4e9efecb
commit 80f4426b8e
5 changed files with 44 additions and 35 deletions

View File

@@ -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)

View File

@@ -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

View File

@@ -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()

View File

@@ -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()

View File

@@ -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()