From 41610cbd977530731111c6bad2366127a2fcfd9c Mon Sep 17 00:00:00 2001 From: Cristian Maureira-Fredes Date: Tue, 27 Apr 2021 18:08:01 +0200 Subject: doc: snippets_translate make quiet mode by default Without being 'quiet' the script was generating output to the stdout and stderr, which was triggering the cmake instruction to make the build fail This change makes the quiet mode by default, the old output that summarize each snippet file can be obtained by using the '--verbose' option. A new option called '--debug' was introduced to get even more output related to each translation happening per file. Pick-to: 6.0.4 Change-Id: I7fce09f0b60e626c957efc4fe24948e0eaf3db74 Reviewed-by: Friedemann Kleint --- sources/pyside6/doc/CMakeLists.txt | 5 +--- tools/snippets_translate/main.py | 47 +++++++++++++++++++------------------- 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/sources/pyside6/doc/CMakeLists.txt b/sources/pyside6/doc/CMakeLists.txt index e822992b1..c31765ad6 100644 --- a/sources/pyside6/doc/CMakeLists.txt +++ b/sources/pyside6/doc/CMakeLists.txt @@ -30,14 +30,11 @@ if (FULLDOCSBUILD) message(FATAL_ERROR "There is no value set on QT_SRC_DIR, the snippet conversion will fail") endif() set(PYSIDE_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/../../../") - if (QUIET_BUILD) - set(SNIPPETS_QUIET_OPTION "-q") - endif() set(SNIPPETS_TOOL "${CMAKE_CURRENT_SOURCE_DIR}/../../../tools/snippets_translate/main.py") # Note QT_SRC_DIR points to 'qtbase', # so we use the general SRC directory to copy all the other snippets execute_process(COMMAND ${PYTHON_EXECUTABLE} ${SNIPPETS_TOOL} - --qt ${QT_SRC_DIR}/.. --pyside ${PYSIDE_ROOT} -w ${SNIPPETS_QUIET_OPTION} + --qt ${QT_SRC_DIR}/.. --pyside ${PYSIDE_ROOT} -w WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR} ERROR_VARIABLE SNIPPETS_ERROR) if (SNIPPETS_ERROR) diff --git a/tools/snippets_translate/main.py b/tools/snippets_translate/main.py index c1267d22c..c5f4b9690 100644 --- a/tools/snippets_translate/main.py +++ b/tools/snippets_translate/main.py @@ -63,13 +63,12 @@ try: from rich.table import Table except ModuleNotFoundError: - print("-- 'rich' not found, falling back to default logger") + # 'rich' not found, falling back to default logger" logging.basicConfig(level=logging.INFO) have_rich = False extra = {} log = logging.getLogger("snippets_translate") -opt_quiet = False # Filter and paths configuration SKIP_END = (".pro", ".pri", ".cmake", ".qdoc", ".yaml", ".frag", ".qsb", ".vert", "CMakeLists.txt") @@ -111,13 +110,6 @@ def get_parser(): help="Actually copy over the files to the pyside-setup directory", ) - parser.add_argument( - "-q", - "--quiet", - action="store_true", - help="Quiet" - ) - parser.add_argument( "-v", "--verbose", @@ -126,6 +118,14 @@ def get_parser(): help="Generate more output", ) + parser.add_argument( + "-d", + "--debug", + action="store_true", + dest="debug", + help="Generate even more output", + ) + parser.add_argument( "-s", "--single", @@ -237,13 +237,13 @@ def get_license_from_file(filename): else: return "" -def translate_file(file_path, final_path, verbose, write): +def translate_file(file_path, final_path, debug, write): with open(str(file_path)) as f: snippets = get_snippets(f.read().splitlines()) if snippets: # TODO: Get license header first license_header = get_license_from_file(str(file_path)) - if verbose: + if debug: if have_rich: console = Console() table = Table(show_header=True, header_style="bold magenta") @@ -261,14 +261,14 @@ def translate_file(file_path, final_path, verbose, write): translated_lines.append(translated_line) # logging - if verbose: + if debug: if have_rich: table.add_row(line, translated_line) else: if not opt_quiet: print(line, translated_line) - if verbose and have_rich: + if debug and have_rich: if not opt_quiet: console.print(table) @@ -294,10 +294,10 @@ def translate_file(file_path, final_path, verbose, write): -def copy_file(file_path, py_path, category, category_path, write=False, verbose=False): +def copy_file(file_path, py_path, category, category_path, write=False, debug=False): if not category: - translate_file(file_path, Path("_translated.py"), verbose, write) + translate_file(file_path, Path("_translated.py"), debug, write) return # Get path after the directory "snippets" or "examples" # and we add +1 to avoid the same directory @@ -317,7 +317,7 @@ def copy_file(file_path, py_path, category, category_path, write=False, verbose= status_msg = " [green][New][/green]" if have_rich else "[New]" status = FileStatus.New - if verbose: + if debug: if not opt_quiet: log.info(f"From {file_path} to") log.info(f"==> {final_path}") @@ -344,7 +344,7 @@ def copy_file(file_path, py_path, category, category_path, write=False, verbose= # Translate C++ code into Python code if final_path.name.endswith(".cpp"): - translate_file(file_path, final_path, verbose, write) + translate_file(file_path, final_path, debug, write) return status @@ -373,7 +373,7 @@ def process(options): "snippets", OUT_SNIPPETS, write=options.write_files, - verbose=options.verbose, + debug=options.debug, ) elif "examples" in f.parts: status = copy_file( @@ -382,7 +382,7 @@ def process(options): "examples", OUT_EXAMPLES, write=options.write_files, - verbose=options.verbose, + debug=options.debug, ) else: log.warning("Path did not contain 'snippets' nor 'examples'." @@ -393,7 +393,7 @@ def process(options): None, None, write=options.write_files, - verbose=options.verbose, + debug=options.debug, ) else: @@ -423,7 +423,7 @@ def process(options): "snippets", OUT_SNIPPETS, write=options.write_files, - verbose=options.verbose, + debug=options.debug, ) elif "examples" in f.parts: status = copy_file( @@ -432,7 +432,7 @@ def process(options): "examples", OUT_EXAMPLES, write=options.write_files, - verbose=options.verbose, + debug=options.debug, ) # Stats @@ -457,7 +457,8 @@ def process(options): if __name__ == "__main__": parser = get_parser() options = parser.parse_args() - opt_quiet = options.quiet + opt_quiet = False if options.verbose else True + opt_quiet = False if options.debug else opt_quiet if not check_arguments(options): parser.print_help() -- cgit v1.2.3