Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 128 additions & 28 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ ignore = [
"PLW0604", # global-at-module-level
"PLW1508", # invalid-envvar-default
"PLW1510", # subprocess-run-without-check
"PLW1514", # unspecified-encoding
"PLW1641", # eq-without-hash
"PLW2901", # redefined-loop-name
"PLW3201", # bad-dunder-method-name
Expand Down Expand Up @@ -288,62 +287,163 @@ ignore = [
"gui/**" = ["PLW0108"] # See https://github.com/OSGeo/grass/issues/4124
# Other ignores:
"**.py" = ["PYI066"]
"*/testsuite/**.py" = ["PT009", "PT027"]
"*/testsuite/**.py" = ["PT009", "PT027", "PLW1514"]
"display/d.mon/render_cmd.py" = ["PLW1514"]
"display/d.text/test.py" = ["PLW1514"]
"gui/wxpython/animation/temporal_manager.py" = ["PLW1514"]
"gui/wxpython/core/gconsole.py" = ["PLW1514"]
"gui/wxpython/core/render.py" = ["PLW1514"]
"gui/wxpython/core/settings.py" = ["PLW1514"]
"gui/wxpython/core/toolboxes.py" = ["PLW1514"]
"gui/wxpython/core/utils.py" = ["PLW1514"]
"gui/wxpython/core/watchdog.py" = ["PLW1514"]
"gui/wxpython/core/workspace.py" = ["PLW1514"]
"gui/wxpython/dbmgr/base.py" = ["PLW1514"]
"gui/wxpython/docs/wxgui_sphinx/conf.py" = ["PLW1514"]
"gui/wxpython/gcp/manager.py" = ["PLW1514"]
"gui/wxpython/gmodeler/model.py" = ["PLW1514"]
"gui/wxpython/gmodeler/panels.py" = ["PLW1514"]
"gui/wxpython/gui_core/forms.py" = ["PLW1514"]
"gui/wxpython/gui_core/ghelp.py" = ["PLW1514"]
"gui/wxpython/gui_core/goutput.py" = ["PLW1514"]
"gui/wxpython/gui_core/gselect.py" = ["PLW1514"]
"gui/wxpython/gui_core/pyedit.py" = ["PLW1514"]
"gui/wxpython/gui_core/widgets.py" = ["PLW1514"]
"gui/wxpython/iclass/frame.py" = ["PLW1514"]
"gui/wxpython/iclass/statistics.py" = ["A005"]
"gui/wxpython/wxplot/profile.py" = ["A005", "SIM115"]
"gui/wxpython/image2target/ii2t_gis_set.py" = ["PLW1514"]
"gui/wxpython/image2target/ii2t_manager.py" = ["PLW1514"]
"gui/wxpython/location_wizard/wizard.py" = ["PLW1514"]
"gui/wxpython/mapdisp/main.py" = ["PLW1514"]
"gui/wxpython/modules/colorrules.py" = ["PLW1514"]
"gui/wxpython/modules/mcalc_builder.py" = ["PLW1514"]
"gui/wxpython/photo2image/ip2i_manager.py" = ["PLW1514"]
"gui/wxpython/psmap/instructions.py" = ["PLW1514"]
"gui/wxpython/rdigit/controller.py" = ["PLW1514"]
"gui/wxpython/rlisetup/frame.py" = ["PLW1514"]
"gui/wxpython/rlisetup/wizard.py" = ["PLW1514"]
"gui/wxpython/tools/update_menudata.py" = ["PLW1514"]
"gui/wxpython/tplot/frame.py" = ["PLW1514"]
"gui/wxpython/vdigit/mapwindow.py" = ["PLW1514"]
"gui/wxpython/vnet/vnet_core.py" = ["PLW1514"]
"gui/wxpython/vnet/vnet_data.py" = ["PLW1514"]
"gui/wxpython/web_services/dialogs.py" = ["PLW1514"]
"gui/wxpython/wxplot/profile.py" = ["A005", "PLW1514", "SIM115"]
"imagery/i.atcorr/create_iwave.py" = ["PLW1514"]
"lib/imagery/testsuite/test_imagery_sigsetfile.py" = ["FURB152"]
"lib/init/grass.py" = ["SIM115"]
"lib/init/grass.py" = ["PLW1514", "SIM115"]
"lib/init/testsuite/test_grass_tmp_mapset.py" = ["PTH208"]
"locale/grass_po_stats.py" = ["SIM115"]
"man/build.py" = ["PTH208"]
"man/build_class_graphical.py" = ["PTH208"]
"man/build_manual_gallery.py" = ["PTH208"]
"man/build_rest.py" = ["PTH208"]
"man/build.py" = ["PLW1514", "PTH208"]
"man/build_class.py" = ["PLW1514"]
"man/build_class_graphical.py" = ["PLW1514", "PTH208"]
"man/build_full_index.py" = ["PLW1514"]
"man/build_graphical_index.py" = ["PLW1514"]
"man/build_html.py" = ["PLW1514"]
"man/build_index.py" = ["PLW1514"]
"man/build_index_rest.py" = ["PLW1514"]
"man/build_keywords.py" = ["PLW1514"]
"man/build_manual_gallery.py" = ["PLW1514", "PTH208"]
"man/build_md.py" = ["PLW1514"]
"man/build_rest.py" = ["PLW1514", "PTH208"]
"man/build_topics.py" = ["PLW1514"]
"man/parser_standard_options.py" = ["PLW1514"]
"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"]
"python/grass/gunittest/case.py" = ["PT009"]
"python/grass/gunittest/case.py" = ["PLW1514", "PT009"]
"python/grass/gunittest/checkers.py" = ["PLW1514"]
"python/grass/gunittest/invoker.py" = ["PLW1514"]
"python/grass/gunittest/loader.py" = ["PTH208"]
"python/grass/gunittest/reporters.py" = ["PLW1514"]
"python/grass/gunittest/testsu*/d*/s*/s*/subsub*/t*/test_segfaut.py" = ["B018"]
"python/grass/imaging/images2ims.py" = ["PTH208"]
"python/grass/jupyter/testsuite/interactivemap_test.py" = ["PGH004"]
"python/grass/jupyter/testsuite/map_test.py" = ["PGH004"]
"python/grass/jupyter/utils.py" = ["PLW1514"]
"python/grass/pydispatch/signal.py" = ["A005"]
"python/grass/pygrass/gis/__init__.py" = ["PTH208"]
"python/grass/pygrass/modules/grid/grid.py" = ["PTH208", "SIM115"]
"python/grass/pygrass/gis/__init__.py" = ["PLW1514", "PTH208"]
"python/grass/pygrass/modules/grid/grid.py" = ["PLW1514", "PTH208", "SIM115"]
"python/grass/pygrass/modules/grid/testsuite/test_*_modules_grid_doctests.py" = ["F401"]
"python/grass/pygrass/modules/interface/env.py" = ["SIM115"]
"python/grass/pygrass/modules/interface/env.py" = ["PLW1514", "SIM115"]
"python/grass/pygrass/modules/testsuite/test_pygrass_modules_doctests.py" = ["F401"]
"python/grass/pygrass/raster/category.py" = ["FURB189"]
"python/grass/pygrass/raster/segment.py" = ["SIM115"]
"python/grass/pygrass/raster/category.py" = ["FURB189", "PLW1514"]
"python/grass/pygrass/raster/segment.py" = ["PLW1514", "SIM115"]
"python/grass/pygrass/tests/*.py" = ["SIM115"]
"python/grass/pygrass/tests/set_mapset.py" = ["PLW1514"]
"python/grass/pygrass/utils.py" = ["PTH208"]
"python/grass/pygrass/vector/geometry.py" = ["PYI024"]
"python/grass/pygrass/vector/testsuite/test_table.py" = ["PLW0108"]
"python/grass/script/array.py" = ["A005"]
"python/grass/script/core.py" = ["PTH208"]
"python/grass/script/utils.py" = ["FURB189"]
"python/grass/temporal/aggregation.py" = ["SIM115"]
"python/grass/temporal/register.py" = ["SIM115"]
"python/grass/temporal/stds_export.py" = ["SIM115"]
"python/grass/temporal/stds_import.py" = ["SIM115"]
"python/grass/script/core.py" = ["PLW1514", "PTH208"]
"python/grass/script/db.py" = ["PLW1514"]
"python/grass/script/raster.py" = ["PLW1514"]
"python/grass/script/setup.py" = ["PLW1514"]
"python/grass/script/utils.py" = ["FURB189", "PLW1514"]
"python/grass/semantic_label/reader.py" = ["PLW1514"]
"python/grass/temporal/abstract_space_time_dataset.py" = ["PLW1514"]
"python/grass/temporal/aggregation.py" = ["PLW1514", "SIM115"]
"python/grass/temporal/register.py" = ["PLW1514", "SIM115"]
"python/grass/temporal/stds_export.py" = ["PLW1514", "SIM115"]
"python/grass/temporal/stds_import.py" = ["PLW1514", "SIM115"]
"python/grass/temporal/temporal_algebra.py" = ["D300"]
"python/grass/temporal/temporal_operator.py" = ["D300"]
"python/grass/temporal/univar_statistics.py" = ["SIM115"]
"python/grass/temporal/univar_statistics.py" = ["PLW1514", "SIM115"]
"python/grass/utils/download.py" = ["PTH208", "SIM115"]
"raster/r.*/testsuite/*.py" = ["SIM115"]
"raster/r.mfilter/benchmark/benchmark_r_mfilter_nprocs.py" = ["PLW1514"]
"raster/r.topidx/*.py" = ["SIM115"]
"scripts/d.correlate/d.correlate.py" = ["SIM115"]
"scripts/d.frame/d.frame.py" = ["SIM115"]
"scripts/d.polar/d.polar.py" = ["FURB154", "SIM115"]
"scripts/db.test/db.test.py" = ["SIM115"]
"raster/r.topidx/arc_to_gridatb.py" = ["PLW1514"]
"raster/r.topidx/gridatb_to_arc.py" = ["PLW1514"]
"scripts/d.correlate/d.correlate.py" = ["PLW1514", "SIM115"]
"scripts/d.frame/d.frame.py" = ["PLW1514", "SIM115"]
"scripts/d.out.file/d.out.file.py" = ["PLW1514"]
"scripts/d.polar/d.polar.py" = ["FURB154", "PLW1514", "SIM115"]
"scripts/d.to.rast/d.to.rast.py" = ["PLW1514"]
"scripts/d.what.rast/d.what.rast.py" = ["PLW1514"]
"scripts/d.what.vect/d.what.vect.py" = ["PLW1514"]
"scripts/db.in.ogr/db.in.ogr.py" = ["PLW1514"]
"scripts/db.test/db.test.py" = ["PLW1514", "SIM115"]
"scripts/db.univar/db.univar.py" = ["PLW1514"]
"scripts/g.download.project/g.download.project.py" = ["PTH208"]
"scripts/g.extension.all/g.extension.all.py" = ["SIM115"]
"scripts/g.extension/g.extension.py" = ["PTH208", "SIM115"]
"scripts/g.extension.all/g.extension.all.py" = ["PLW1514", "SIM115"]
"scripts/g.extension/g.extension.py" = ["PLW1514", "PTH208", "SIM115"]
"scripts/g.search.modules/g.search.modules.py" = ["PLW1514"]
"scripts/i.in.spotvgt/i.in.spotvgt.py" = ["PLW1514"]
"scripts/i.oif/i.oif.py" = ["PLW1514"]
"scripts/i.oif/i.oif*.py" = ["SIM115"]
"scripts/m.proj/m.proj.py" = ["SIM115"]
"scripts/i.pansharpen/i.pansharpen.py" = ["PLW1514"]
"scripts/i.spectral/i.spectral.py" = ["PLW1514"]
"scripts/m.proj/m.proj.py" = ["PLW1514", "SIM115"]
"scripts/r.fillnulls/r.fillnulls.py" = ["PLW1514"]
"scripts/r.in.srtm/r.in.srtm.py" = ["PLW1514"]
"scripts/r.in.wms/wms_*.py" = ["SIM115"]
"scripts/r.in.wms/wms_base.py" = ["PLW1514"]
"scripts/r.in.wms/wms_gdal_drv.py" = ["PLW1514"]
"scripts/r.pack/r.pack.py" = ["PLW1514"]
"scripts/r.tileset/r.tileset.py" = ["PLW1514"]
"scripts/r.unpack/r.unpack.py" = ["PLW1514"]
"scripts/v.*/v.*.py" = ["SIM115"]
"scripts/v.db.addcolumn/v.db.addcolumn.py" = ["PLW1514"]
"scripts/v.db.addtable/v.db.addtable.py" = ["PLW1514"]
"scripts/v.db.droptable/v.db.droptable.py" = ["PLW1514"]
"scripts/v.db.reconnect.all/v.db.reconnect.all.py" = ["PLW1514"]
"scripts/v.db.univar/v.db.univar.py" = ["PLW1514"]
"scripts/v.import/v.import.py" = ["PLW1514"]
"scripts/v.in.e00/v.in.e00.py" = ["PLW1514"]
"scripts/v.in.lines/v.in.lines.py" = ["PLW1514"]
"scripts/v.in.mapgen/v.in.mapgen.py" = ["PLW1514"]
"scripts/v.in.wfs/v.in.wfs.py" = ["PLW1514"]
"scripts/v.rast.stats/v.rast.stats.py" = ["PLW1514"]
"scripts/v.report/v.report.py" = ["PLW1514"]
"scripts/v.unpack/v.unpack.py" = ["PLW1514"]
"temporal/t.list/t.list.py" = ["PLW1514"]
"temporal/t.rast.colors/t.rast.colors.py" = ["PLW1514"]
"temporal/t.rast.series/t.rast.series.py" = ["PLW1514"]
"temporal/t.rast.what/t.rast.what.py" = ["PLW1514"]
"temporal/t.remove/t.remove.py" = ["PLW1514"]
"temporal/t.unregister/t.unregister.py" = ["PLW1514"]
"utils/*.py" = ["PLW1514"]

[tool.ruff.lint.flake8-import-conventions.extend-aliases]
# Declare a custom aliases, checked with rule ICN001
Expand Down
7 changes: 4 additions & 3 deletions python/grass/gunittest/invoker.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
# TODO: this might be more extend then update
def update_keyval_file(filename, module, returncode):
if os.path.exists(filename):
keyval = text_to_keyvalue(Path(filename).read_text(), sep="=")
keyval = text_to_keyvalue(Path(filename).read_text(encoding="utf-8"), sep="=")
else:
keyval = {}

Expand All @@ -66,7 +66,7 @@ def update_keyval_file(filename, module, returncode):
keyval["returncode"] = returncode
keyval["test_file_authors"] = test_file_authors

Path(filename).write_text(keyvalue_to_text(keyval))
Path(filename).write_text(keyvalue_to_text(keyval), encoding="utf-8")
return keyval


Expand Down Expand Up @@ -351,7 +351,8 @@ def run_in_location(
" (testsuite directories)</li>"
'<li><a href="testfiles.html">Results by test files</a></li>'
"<ul>"
"</body></html>".format(location=location, type=location_type)
"</body></html>".format(location=location, type=location_type),
encoding="utf-8",
)

testsuite_dir_reporter = TestsuiteDirReporter(
Expand Down
2 changes: 1 addition & 1 deletion python/grass/gunittest/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def __init__(
text_result = TextTestResult(
stream=_WritelnDecorator(sys.stderr), descriptions=True, verbosity=verbosity
)
with open("test_keyvalue_result.txt", "w") as keyval_file:
with open("test_keyvalue_result.txt", "w", encoding="utf-8") as keyval_file:
keyval_result = KeyValueTestResult(stream=keyval_file)
result = MultiTestResult(results=[text_result, keyval_result])

Expand Down
10 changes: 7 additions & 3 deletions python/grass/gunittest/multireport.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ def main_page(
directory: StrPath | None = None,
) -> None:
filename = os.path.join(directory, filename)
with open(filename, "w") as page:
with open(filename, "w", encoding="utf-8") as page:
page.write(
"<html><body>"
"<h1>{title}</h1>"
Expand Down Expand Up @@ -507,7 +507,9 @@ def main():
# skipping incomplete reports
# use only results list for further processing
continue
summary = text_to_keyvalue(Path(summary_file).read_text(), sep="=")
summary = text_to_keyvalue(
Path(summary_file).read_text(encoding="utf-8"), sep="="
)
if use_timestamps:
test_timestamp = datetime.datetime.fromtimestamp(
os.path.getmtime(summary_file)
Expand Down Expand Up @@ -551,7 +553,9 @@ def main():
except KeyError as e:
print("File %s does not have right values (%s)" % (report, e.message))

with open(os.path.join(output, "index.html"), "w") as locations_main_page:
with open(
os.path.join(output, "index.html"), "w", encoding="utf-8"
) as locations_main_page:
locations_main_page.write(
"<html><body>"
"<h1>Test reports grouped by location type</h1>"
Expand Down
18 changes: 10 additions & 8 deletions python/grass/gunittest/reporters.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ def wrap_stdstream_to_html(
) -> None:
before = "<html><body><h1>%s</h1><pre>" % (module.name + " " + stream)
after = "</pre></body></html>"
with open(outfile, "w") as html, open(infile) as text:
with open(outfile, "w", encoding="utf-8") as html, open(infile) as text:
html.write(before)
html.writelines(color_error_line(html_escape(line)) for line in text)
html.write(after)
Expand All @@ -483,7 +483,7 @@ def html_file_preview(filename):
html = StringIO()
html.write(before)
if size < max_size:
with open(filename) as text:
with open(filename, encoding="utf-8") as text:
for line in text:
html.write(color_error_line(html_escape(line)))
elif size < 10 * max_size:
Expand Down Expand Up @@ -568,7 +568,7 @@ def start(self, results_dir):
# having all variables public although not really part of API
main_page_name = os.path.join(results_dir, self._main_page_name)
# TODO: Ensure file is closed in all situations
self.main_index = open(main_page_name, "w") # noqa: SIM115
self.main_index = open(main_page_name, "w", encoding="utf-8") # noqa: SIM115

# TODO: this can be moved to the counter class
self.failures = 0
Expand Down Expand Up @@ -794,7 +794,7 @@ def end_file_test(
# using constructors as seems advantageous for counting
self._file_anonymizer.anonymize(supplementary_files)

with open(file_index_path, "w") as file_index:
with open(file_index_path, "w", encoding="utf-8") as file_index:
file_index.write(header)
file_index.write(summary_section)
if modules:
Expand Down Expand Up @@ -897,7 +897,7 @@ def finish(self):

summary_filename = os.path.join(self.result_dir, "test_keyvalue_result.txt")
text = keyvalue_to_text(summary, sep="=", vsep="\n", isep=",")
Path(summary_filename).write_text(text)
Path(summary_filename).write_text(text, encoding="utf-8")

def end_file_test(
self, module, cwd, returncode, stdout, stderr, test_summary, timed_out=None
Expand Down Expand Up @@ -1084,7 +1084,7 @@ def report_for_dir(self, root: StrPath, directory: StrPath, test_files) -> str:
"<th>Failed</th><th>Percent successful</th>"
"</tr></thead><tbody>"
)
with open(page_name, "w") as page:
with open(page_name, "w", encoding="utf-8") as page:
page.write(head)
page.write(tests_table_head)
for test_file_name in test_files:
Expand All @@ -1093,7 +1093,9 @@ def report_for_dir(self, root: StrPath, directory: StrPath, test_files) -> str:
root, directory, test_file_name, "test_keyvalue_result.txt"
)
# if os.path.exists(summary_filename):
summary = text_to_keyvalue(Path(summary_filename).read_text(), sep="=")
summary = text_to_keyvalue(
Path(summary_filename).read_text(encoding="utf-8"), sep="="
)
# else:
# TODO: write else here
# summary = None
Expand Down Expand Up @@ -1253,7 +1255,7 @@ def report_for_dirs(self, root: StrPath, directories) -> None:
)
)

with open(page_name, "w") as page:
with open(page_name, "w", encoding="utf-8") as page:
page.write(head)
page.write(tests_table_head)

Expand Down
2 changes: 1 addition & 1 deletion python/grass/gunittest/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def ensure_dir(directory: StrOrBytesPath) -> None:
def add_gitignore_to_dir(directory: StrPath) -> None:
gitignore_path = Path(directory) / ".gitignore"
if not Path(gitignore_path).exists():
Path(gitignore_path).write_text("*")
Path(gitignore_path).write_text("*", encoding="utf-8")


def silent_rmtree(filename: StrOrBytesPath) -> None:
Expand Down
Loading