diff --git a/man/build_class.py b/man/build_class.py index a75fe62fe58..7dc53c121bf 100644 --- a/man/build_class.py +++ b/man/build_class.py @@ -33,41 +33,39 @@ def build_class(ext): os.chdir(man_dir) filename = modclass + f".{ext}" - f = open(filename + ".tmp", "w") - - write_header( - f, - "{} modules - GRASS GIS {} Reference Manual".format( - modclass.capitalize(), grass_version - ), - template=ext, - ) - modclass_lower = modclass.lower() - modclass_visible = modclass - if modclass_lower not in no_intro_page_classes: - if modclass_visible == "raster3d": - # convert keyword to nice form - modclass_visible = "3D raster" - f.write( - modclass_intro_tmpl.substitute( - modclass=modclass_visible, modclass_lower=modclass_lower - ) + with open(filename + ".tmp", "w") as f: + write_header( + f, + "{} modules - GRASS GIS {} Reference Manual".format( + modclass.capitalize(), grass_version + ), + template=ext, ) - f.write(modclass_tmpl.substitute(modclass=to_title(modclass_visible))) + modclass_lower = modclass.lower() + modclass_visible = modclass + if modclass_lower not in no_intro_page_classes: + if modclass_visible == "raster3d": + # convert keyword to nice form + modclass_visible = "3D raster" + f.write( + modclass_intro_tmpl.substitute( + modclass=modclass_visible, modclass_lower=modclass_lower + ) + ) + f.write(modclass_tmpl.substitute(modclass=to_title(modclass_visible))) - # for all modules: - for cmd in get_files(man_dir, cls, extension=ext): - basename = os.path.splitext(cmd)[0] - desc = check_for_desc_override(basename) - if desc is None: - desc = get_desc(cmd) - f.write(desc2_tmpl.substitute(cmd=cmd, basename=basename, desc=desc)) - if ext == "html": - f.write("\n") + # for all modules: + for cmd in get_files(man_dir, cls, extension=ext): + basename = os.path.splitext(cmd)[0] + desc = check_for_desc_override(basename) + if desc is None: + desc = get_desc(cmd) + f.write(desc2_tmpl.substitute(cmd=cmd, basename=basename, desc=desc)) + if ext == "html": + f.write("\n") - write_footer(f, f"index.{ext}", year, template=ext) + write_footer(f, f"index.{ext}", year, template=ext) - f.close() replace_file(filename) diff --git a/man/build_class_graphical.py b/man/build_class_graphical.py index b1bd6eede7f..0eed97beb46 100644 --- a/man/build_class_graphical.py +++ b/man/build_class_graphical.py @@ -131,65 +131,62 @@ def generate_page_for_category( short_family, module_family, imgs, year, skip_no_image=False ): filename = module_family + "_graphical.html" - - output = open(filename + ".tmp", "w") - - output.write( - header1_tmpl.substitute( - title="GRASS GIS %s Reference Manual: Graphical index" % grass_version - ) - ) - output.write(header_graphical_index_tmpl) - - if module_family.lower() not in {"general", "postscript"}: - if module_family == "raster3d": - # covert keyword to nice form - module_family = "3D raster" + with open(filename + ".tmp", "w") as output: output.write( - modclass_intro_tmpl.substitute( - modclass=module_family, modclass_lower=module_family.lower() + header1_tmpl.substitute( + title="GRASS GIS %s Reference Manual: Graphical index" % grass_version ) ) - if module_family == "wxGUI": - output.write("
' - test_length = 0 - all_keys = len(char_list.keys()) - for k in sorted(char_list.keys()): - test_length += 1 - # toc += '
' # noqa: E501 + test_length = 0 + all_keys = len(char_list.keys()) + for k in sorted(char_list.keys()): + test_length += 1 + # toc += '
See also the corresponding keyword" + ' {key}' + " for additional references.".format( + key=key.replace("_", " ") + ) + ) + else: + # expecting markdown + keyfile.write( + "*See also the corresponding keyword" + " [{key}](keywords.md#{key})" + " for additional references.*\n".format( + key=key.replace("_", " ") + ) + ) + + write_footer(keyfile, f"index.{ext}", year, template=ext) - for key, values in sorted(keywords.items(), key=lambda s: s[0].lower()): - keyfile = open(os.path.join(man_dir, f"topic_%s.{ext}" % key), "w") - if ext == "html": - keyfile.write( - header1_tmpl.substitute( - title="GRASS GIS " - "%s Reference Manual: Topic %s" - % (grass_version, key.replace("_", " ")) - ) - ) - keyfile.write(headerkey_tmpl.substitute(keyword=key.replace("_", " "))) - num_modules = 0 - for mod, desc in sorted(values.items()): - num_modules += 1 - keyfile.write( - desc1_tmpl.substitute( - cmd=mod, desc=desc, basename=mod.replace(f".{ext}", "") - ) - ) - if num_modules >= min_num_modules_for_topic: - topicsfile.writelines( - [moduletopics_tmpl.substitute(key=key, name=key.replace("_", " "))] - ) if ext == "html": - keyfile.write("\n") - else: - keyfile.write("\n") - # link to the keywords index - # TODO: the labels in keywords index are with spaces and capitals - # this should be probably changed to lowercase with underscores - if ext == "html": - keyfile.write( - "
See also the corresponding keyword" - ' {key}' - " for additional references.".format(key=key.replace("_", " ")) - ) - else: - # expecting markdown - keyfile.write( - "*See also the corresponding keyword" - " [{key}](keywords.md#{key})" - " for additional references.*\n".format(key=key.replace("_", " ")) - ) - - write_footer(keyfile, f"index.{ext}", year, template=ext) - if ext == "html": - topicsfile.write("\n") - write_footer(topicsfile, f"index.{ext}", year, template=ext) - topicsfile.close() + topicsfile.write("\n") + write_footer(topicsfile, f"index.{ext}", year, template=ext) if __name__ == "__main__": diff --git a/pyproject.toml b/pyproject.toml index c550cf71faa..85ad3e1283e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -259,6 +259,7 @@ ignore = [ # See https://docs.astral.sh/ruff/settings/#lint_per-file-ignores # "A005", # builtin-module-shadowing # "PLW0108", # unnecessary-lambda +# "SIM115", # open-file-with-context-handler # Ignore `E402` (import violations) in all `__init__.py` files "**.py" = ["PYI066"] "*/testsuite/**.py" = ["PT009", "PT027"] @@ -299,8 +300,6 @@ ignore = [ "lib/imagery/testsuite/test_imagery_sigsetfile.py" = ["FURB152"] "lib/init/grass.py" = ["SIM115"] "locale/grass_po_stats.py" = ["SIM115"] -"man/build_*.py" = ["SIM115"] -"man/parser_standard_options.py" = ["SIM115"] "python/grass/__init__.py" = ["PYI056"] "python/grass/exp*/tests/grass_script_mapset_session_test.py" = ["SIM117"] "python/grass/exp*/tests/grass_script_tmp_mapset_session_test.py" = ["SIM117"]