From aced2be1fb228f99284b5a0bca778e8769d3c7e5 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sat, 1 Feb 2020 00:30:09 +0900 Subject: [PATCH] apidoc: Add ``-q`` option for quiet mode (refs: #6772) --- CHANGES | 1 + doc/man/sphinx-apidoc.rst | 5 +++++ sphinx/ext/apidoc.py | 15 ++++++++++++--- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index 663dd160b..74032a38c 100644 --- a/CHANGES +++ b/CHANGES @@ -59,6 +59,7 @@ Features added * SphinxTranslator now calls visitor/departure method for super node class if visitor/departure method for original node class not found * #6418: Add new event: :event:`object-description-transform` +* #6772: apidoc: Add ``-q`` option for quiet mode Bugs fixed ---------- diff --git a/doc/man/sphinx-apidoc.rst b/doc/man/sphinx-apidoc.rst index 78c0735cb..30bfde0bb 100644 --- a/doc/man/sphinx-apidoc.rst +++ b/doc/man/sphinx-apidoc.rst @@ -39,6 +39,11 @@ Options Directory to place the output files. If it does not exist, it is created. +.. option:: -q + + Do not output anything on standard output, only write warnings and errors to + standard error. + .. option:: -f, --force Force overwriting of any existing generated files. diff --git a/sphinx/ext/apidoc.py b/sphinx/ext/apidoc.py index 0c70b4ec8..99cf67016 100644 --- a/sphinx/ext/apidoc.py +++ b/sphinx/ext/apidoc.py @@ -73,14 +73,19 @@ def module_join(*modnames: str) -> str: def write_file(name: str, text: str, opts: Any) -> None: """Write the output file for module/package .""" + quiet = getattr(opts, 'quiet', None) + fname = path.join(opts.destdir, '%s.%s' % (name, opts.suffix)) if opts.dryrun: - print(__('Would create file %s.') % fname) + if not quiet: + print(__('Would create file %s.') % fname) return if not opts.force and path.isfile(fname): - print(__('File %s already exists, skipping.') % fname) + if not quiet: + print(__('File %s already exists, skipping.') % fname) else: - print(__('Creating file %s.') % fname) + if not quiet: + print(__('Creating file %s.') % fname) with FileAvoidWrite(fname) as f: f.write(text) @@ -324,6 +329,8 @@ Note: By default this script will not overwrite already created files.""")) parser.add_argument('-o', '--output-dir', action='store', dest='destdir', required=True, help=__('directory to place all output')) + parser.add_argument('-q', action='store_true', dest='quiet', + help=__('no output on stdout, just warnings on stderr')) parser.add_argument('-d', '--maxdepth', action='store', dest='maxdepth', type=int, default=4, help=__('maximum depth of submodules to show in the TOC ' @@ -451,6 +458,8 @@ def main(argv: List[str] = sys.argv[1:]) -> int: } if args.extensions: d['extensions'].extend(args.extensions) + if args.quiet: + d['quiet'] = True for ext in d['extensions'][:]: if ',' in ext: