Make %pyproject_buildrequires and %pyproject_save_files argparser errors nicer to macro users

Before:

    %pyproject_buildrequires bogus_arg
    usage: pyproject_buildrequires.py [-h] [-r] [-w] [--wheeldir PATH] [-R]
                                      [-e TOXENVS] [-t] [-x EXTRAS]
                                      [--generate-extras] [-p PYTHON3_PKGVERSION]
                                      [-N]
                                      [requirement_files ...]
    pyproject_buildrequires.py: error: argument requirement_files: can't open 'bogus_arg': ...

    %pyproject_save_files
    ...
    usage: pyproject_save_files.py [-h] --output-files OUTPUT_FILES
                                   --output-modules OUTPUT_MODULES --buildroot
                                   BUILDROOT --sitelib SITELIB --sitearch SITEARCH
                                   --python-version PYTHON_VERSION
                                   --pyproject-record PYPROJECT_RECORD --prefix
                                   PREFIX
                                   varargs [varargs ...]
    pyproject_save_files.py: error: the following arguments are required: varargs

After:

    %pyproject_buildrequires bogus_arg
    usage: %pyproject_buildrequires [-w] [-R] [-e TOXENVS] [-t] [-x EXTRAS] [-N]
                                    [REQUIREMENTS.TXT ...]
    %pyproject_buildrequires: error: argument REQUIREMENTS.TXT: can't open 'bogus_arg': ...

    %pyproject_save_files
    ...
    usage: %pyproject_save_files MODULE_GLOB [MODULE_GLOB ...] [+auto]
    %pyproject_save_files: error: the following arguments are required: MODULE_GLOB

Related: rhbz#2168193
This commit is contained in:
Miro Hrončok 2022-10-10 11:17:08 +02:00
parent 14b3f4b9c3
commit 9eb042c336
2 changed files with 38 additions and 17 deletions

View File

@ -424,11 +424,18 @@ def generate_requires(
def main(argv): def main(argv):
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description='Generate BuildRequires for a Python project.' description='Generate BuildRequires for a Python project.',
prog='%pyproject_buildrequires',
add_help=False,
)
parser.add_argument(
'--help', action='help',
default=argparse.SUPPRESS,
help=argparse.SUPPRESS,
) )
parser.add_argument( parser.add_argument(
'-r', '--runtime', action='store_true', default=True, '-r', '--runtime', action='store_true', default=True,
help='Generate run-time requirements (default, disable with -R)', help=argparse.SUPPRESS, # Generate run-time requirements (backwards-compatibility only)
) )
parser.add_argument( parser.add_argument(
'-w', '--wheel', action='store_true', default=False, '-w', '--wheel', action='store_true', default=False,
@ -437,7 +444,7 @@ def main(argv):
) )
parser.add_argument( parser.add_argument(
'--wheeldir', metavar='PATH', default=None, '--wheeldir', metavar='PATH', default=None,
help='The directory with wheel, used when -w.', help=argparse.SUPPRESS,
) )
parser.add_argument( parser.add_argument(
'-R', '--no-runtime', action='store_false', dest='runtime', '-R', '--no-runtime', action='store_false', dest='runtime',
@ -460,19 +467,19 @@ def main(argv):
) )
parser.add_argument( parser.add_argument(
'--generate-extras', action='store_true', '--generate-extras', action='store_true',
help='Generate build requirements on Python Extras', help=argparse.SUPPRESS,
) )
parser.add_argument( parser.add_argument(
'-p', '--python3_pkgversion', metavar='PYTHON3_PKGVERSION', '-p', '--python3_pkgversion', metavar='PYTHON3_PKGVERSION',
default="3", help=('Python version for pythonXdist()' default="3", help=argparse.SUPPRESS,
'or pythonX.Ydist() requirements'),
) )
parser.add_argument( parser.add_argument(
'-N', '--no-use-build-system', dest='use_build_system', '-N', '--no-use-build-system', dest='use_build_system',
action='store_false', help='Use -N to indicate that project does not use any build system', action='store_false', help='Use -N to indicate that project does not use any build system',
) )
parser.add_argument( parser.add_argument(
'requirement_files', nargs='*', type=argparse.FileType('r'), 'requirement_files', nargs='*', type=argparse.FileType('r'),
metavar='REQUIREMENTS.TXT',
help=('Add buildrequires from file'), help=('Add buildrequires from file'),
) )

View File

@ -742,17 +742,31 @@ def main(cli_args):
def argparser(): def argparser():
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser(
description="Create %{pyproject_files} for a Python project.",
prog="%pyproject_save_files",
add_help=False,
# custom usage to add +auto
usage="%(prog)s MODULE_GLOB [MODULE_GLOB ...] [+auto]",
)
parser.add_argument(
'--help', action='help',
default=argparse.SUPPRESS,
help=argparse.SUPPRESS,
)
r = parser.add_argument_group("required arguments") r = parser.add_argument_group("required arguments")
r.add_argument("--output-files", type=PosixPath, required=True) r.add_argument("--output-files", type=PosixPath, required=True, help=argparse.SUPPRESS)
r.add_argument("--output-modules", type=PosixPath, required=True) r.add_argument("--output-modules", type=PosixPath, required=True, help=argparse.SUPPRESS)
r.add_argument("--buildroot", type=PosixPath, required=True) r.add_argument("--buildroot", type=PosixPath, required=True, help=argparse.SUPPRESS)
r.add_argument("--sitelib", type=BuildrootPath, required=True) r.add_argument("--sitelib", type=BuildrootPath, required=True, help=argparse.SUPPRESS)
r.add_argument("--sitearch", type=BuildrootPath, required=True) r.add_argument("--sitearch", type=BuildrootPath, required=True, help=argparse.SUPPRESS)
r.add_argument("--python-version", type=str, required=True) r.add_argument("--python-version", type=str, required=True, help=argparse.SUPPRESS)
r.add_argument("--pyproject-record", type=PosixPath, required=True) r.add_argument("--pyproject-record", type=PosixPath, required=True, help=argparse.SUPPRESS)
r.add_argument("--prefix", type=PosixPath, required=True) r.add_argument("--prefix", type=PosixPath, required=True, help=argparse.SUPPRESS)
parser.add_argument("varargs", nargs="+") parser.add_argument(
"varargs", nargs="+", metavar="MODULE_GLOB",
help="Shell-like glob matching top-level module names to save into %%{pyproject_files}",
)
return parser return parser