From 32fff15a5c1bcc1123591a3e8e0a25fff5133d27 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Wed, 30 Aug 2023 13:59:35 -0300 Subject: [PATCH] Added help for the error levels --- CHANGELOG.md | 1 + docs/Makefile | 5 ++++- docs/source/errors.rst | 40 ++++++++++++++++++++++++++++++++++++++++ docs/source/usage.rst | 3 +++ docs/source/usage.txt | 2 ++ kibot/__main__.py | 8 +++++++- kibot/config_reader.py | 12 +++++++++--- kibot/misc.py | 4 ++-- setup.cfg | 2 +- 9 files changed, 69 insertions(+), 8 deletions(-) create mode 100644 docs/source/errors.rst diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d31dcde2..a7e097064 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Camera option to set the clip start (#484) - Populate: - Basic support for regular list items (#480) +- Help for the error levels ### Changed - Documentation: diff --git a/docs/Makefile b/docs/Makefile index dbc7e4e90..3aab51b0a 100755 --- a/docs/Makefile +++ b/docs/Makefile @@ -26,6 +26,9 @@ source/configuration/sup_outputs.rst: ../kibot/out_*.py ../kibot/config_reader.p source/dependencies.rst: ../kibot/out_*.py ../kibot/pre_*.py ../kibot/var_*.py ../kibot/registrable.py ../kibot/misc.py ../kibot/config_reader.py ../kibot/dep_downloader.py ../src/kibot --rst --help-dependencies > $@ +source/errors.rst: ../kibot/misc.py ../kibot/config_reader.py + ../src/kibot --rst --help-errors > $@ + source/usage.txt: ../kibot/__main__.py ../src/kibot --help > $@ @@ -48,7 +51,7 @@ help: # Catch-all target: route all unknown targets to Sphinx using the new # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). $(SPHINXTARGETS): Makefile source/configuration/sup_outputs.rst source/dependencies.rst source/usage.txt source/configuration/sup_preflights.rst \ - source/configuration/sup_filters.rst source/configuration/sup_variants.rst source/configuration/sup_globals.rst + source/configuration/sup_filters.rst source/configuration/sup_variants.rst source/configuration/sup_globals.rst source/errors.rst @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) diff --git a/docs/source/errors.rst b/docs/source/errors.rst new file mode 100644 index 000000000..183f71c3d --- /dev/null +++ b/docs/source/errors.rst @@ -0,0 +1,40 @@ +.. Automatically generated by KiBot, please don't edit this file + +Supported error levels +~~~~~~~~~~~~~~~~~~~~~~ + +- 0: NONE +- 1: INTERNAL_ERROR +- 2: WRONG_ARGUMENTS +- 3: UNSUPPORTED_OPTION +- 4: MISSING_TOOL +- 5: DRC_ERROR +- 6: EXIT_BAD_ARGS +- 7: EXIT_BAD_CONFIG +- 8: NO_PCB_FILE +- 9: NO_SCH_FILE +- 10: ERC_ERROR +- 11: BOM_ERROR +- 12: PDF_SCH_PRINT +- 13: PDF_PCB_PRINT +- 14: PLOT_ERROR +- 15: NO_YAML_MODULE +- 16: NO_PCBNEW_MODULE +- 17: CORRUPTED_PCB +- 18: KICAD2STEP_ERR +- 19: WONT_OVERWRITE +- 20: PCBDRAW_ERR +- 21: SVG_SCH_PRINT +- 22: CORRUPTED_SCH +- 23: WRONG_INSTALL +- 24: RENDER_3D_ERR +- 25: FAILED_EXECUTE +- 26: KICOST_ERROR +- 27: MISSING_WKS +- 28: MISSING_FILES +- 29: DIFF_TOO_BIG +- 30: NETLIST_DIFF +- 31: PS_SCH_PRINT +- 32: DXF_SCH_PRINT +- 33: HPGL_SCH_PRINT +- 34: CORRUPTED_PRO diff --git a/docs/source/usage.rst b/docs/source/usage.rst index 17de8ccd9..28f5fdd5a 100644 --- a/docs/source/usage.rst +++ b/docs/source/usage.rst @@ -114,3 +114,6 @@ Command line help .. literalinclude:: usage.txt + +.. include:: errors.rst + diff --git a/docs/source/usage.txt b/docs/source/usage.txt index ddabfa3a7..c8ad8d4c5 100644 --- a/docs/source/usage.txt +++ b/docs/source/usage.txt @@ -21,6 +21,7 @@ Usage: kibot [-v...] [--rst] --help-preflights kibot [-v...] [--rst] --help-variants kibot [-v...] --help-banners + kibot [-v...] [--rst] --help-errors kibot -h | --help kibot --version @@ -74,6 +75,7 @@ Help options: -h, --help Show this help message and exit --help-banners Show all available banners --help-dependencies List dependencies in human readable format + --help-errors List of error levels --help-filters List supported filters and details --help-global-options List supported global variables --help-list-outputs List supported outputs diff --git a/kibot/__main__.py b/kibot/__main__.py index e7ce5c4e1..bad343017 100644 --- a/kibot/__main__.py +++ b/kibot/__main__.py @@ -28,6 +28,7 @@ kibot [-v...] [--rst] --help-preflights kibot [-v...] [--rst] --help-variants kibot [-v...] --help-banners + kibot [-v...] [--rst] --help-errors kibot -h | --help kibot --version @@ -81,6 +82,7 @@ -h, --help Show this help message and exit --help-banners Show all available banners --help-dependencies List dependencies in human readable format + --help-errors List of error levels --help-filters List supported filters and details --help-global-options List supported global variables --help-list-outputs List supported outputs @@ -125,7 +127,8 @@ from .pre_base import BasePreFlight from .error import KiPlotConfigurationError, config_error from .config_reader import (CfgYamlReader, print_outputs_help, print_output_help, print_preflights_help, create_example, - print_filters_help, print_global_options_help, print_dependencies, print_variants_help) + print_filters_help, print_global_options_help, print_dependencies, print_variants_help, + print_errors) from .kiplot import (generate_outputs, load_actions, config_output, generate_makefile, generate_examples, solve_schematic, solve_board_file, solve_project_file, check_board_file) from .registrable import RegOutput @@ -458,6 +461,9 @@ def main(): logger.info('Banner '+str(c)) logger.info(b) sys.exit(0) + if args.help_errors: + print_errors(args.rst) + sys.exit(0) if args.example: check_board_file(args.board_file) if args.copy_options and not args.board_file: diff --git a/kibot/config_reader.py b/kibot/config_reader.py index a4d50ef0e..3bb7de134 100644 --- a/kibot/config_reader.py +++ b/kibot/config_reader.py @@ -23,7 +23,7 @@ from .error import KiPlotConfigurationError, config_error from .misc import (NO_YAML_MODULE, EXIT_BAD_ARGS, EXAMPLE_CFG, WONT_OVERWRITE, W_NOOUTPUTS, W_UNKOUT, W_NOFILTERS, - W_NOVARIANTS, W_NOGLOBALS, TRY_INSTALL_CHECK, W_NOPREFLIGHTS, W_NOGROUPS, W_NEWGROUP) + W_NOVARIANTS, W_NOGLOBALS, TRY_INSTALL_CHECK, W_NOPREFLIGHTS, W_NOGROUPS, W_NEWGROUP, error_level_to_name) from .gs import GS from .registrable import RegOutput, RegVariant, RegFilter, RegDependency from .pre_base import BasePreFlight @@ -948,7 +948,7 @@ def print_output_help(name): print_one_out_help(True, name, RegOutput.get_class_for(name)) -def make_title(rst, tp, n): +def make_title(rst, tp, n, sub='^'): global rst_mode rst_mode = rst logger.debug('{} supported {}'.format(n, tp)) @@ -957,7 +957,7 @@ def make_title(rst, tp, n): title = 'Supported '+tp print(title) if rst_mode: - print((len(title)*'^')+'\n') + print((len(title)*sub)+'\n') return 3, ' ' print() return 2, '' @@ -1348,3 +1348,9 @@ def print_dependencies(markdown=True, jsn=False, rst=False): for c, rst_img in enumerate(rst_images): print(f'.. |image{c+1}| image:: {rst_img[0]}\n :target: {rst_img[1]}') print() + + +def print_errors(rst): + make_title(rst, 'error levels', len(error_level_to_name), '~') + for c, n in enumerate(error_level_to_name): + print(f'- {c}: {n}') diff --git a/kibot/misc.py b/kibot/misc.py index 815e555e5..eafcb4b1f 100644 --- a/kibot/misc.py +++ b/kibot/misc.py @@ -13,7 +13,7 @@ # Error levels INTERNAL_ERROR = 1 # Unhandled exceptions WRONG_ARGUMENTS = 2 # This is what argsparse uses -USUPPORTED_OPTION = 3 +UNSUPPORTED_OPTION = 3 MISSING_TOOL = 4 DRC_ERROR = 5 EXIT_BAD_ARGS = 6 @@ -48,7 +48,7 @@ error_level_to_name = ['NONE', 'INTERNAL_ERROR', 'WRONG_ARGUMENTS', - 'USUPPORTED_OPTION', + 'UNSUPPORTED_OPTION', 'MISSING_TOOL', 'DRC_ERROR', 'EXIT_BAD_ARGS', diff --git a/setup.cfg b/setup.cfg index 4c17308cb..769cf76ac 100644 --- a/setup.cfg +++ b/setup.cfg @@ -38,7 +38,7 @@ ignore = E402, E226, E126, W504 # docstrings - text style (imperative, dot) D4 max-line-length = 127 -max-complexity = 30 +max-complexity = 40 exclude = experiments/kicad/v6/ experiments/JLC/ experiments/resistor_colors/