From 602118adcc4baf69f6441f964f68fd3f34ec3874 Mon Sep 17 00:00:00 2001 From: Arohan Ajit Date: Sat, 16 Nov 2024 17:28:56 -0500 Subject: [PATCH] init: Fix F401 Linter Warnings by Replacing Wildcard Imports with Explicit Imports in __init__.py (#4647) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fixed F401 in app * experimental update * update * fixed * removed comment * removed duplicates * added Popen * fix setup * fixed * Remove fixed F401 and F403 from .flake8 exclusions --------- Co-authored-by: Edouard Choinière <27212526+echoix@users.noreply.github.com> --- .flake8 | 6 +- python/grass/app/__init__.py | 18 ++- python/grass/experimental/__init__.py | 11 +- python/grass/script/__init__.py | 211 +++++++++++++++++++++++++- python/grass/temporal/stds_import.py | 2 +- 5 files changed, 232 insertions(+), 16 deletions(-) diff --git a/.flake8 b/.flake8 index fc8dd9cb65e..0ea1b48ae68 100644 --- a/.flake8 +++ b/.flake8 @@ -18,7 +18,6 @@ per-file-ignores = # F821 undefined name 'unicode' # F841 local variable assigned to but never used # E741 ambiguous variable name 'l' - __init__.py: F403 man/build_html.py: E501 man/build_md.py: E501 doc/python/m.distance.py: E501 @@ -60,7 +59,6 @@ per-file-ignores = python/grass/pygrass/raster/__init__.py: E402 python/grass/pygrass/vector/__init__.py: E402 python/grass/pygrass/raster/category.py: E721 - python/grass/pygrass/rpc/__init__.py: F403 python/grass/pygrass/utils.py: E402 python/grass/temporal/abstract_space_time_dataset.py: E722 python/grass/temporal/c_libraries_interface.py: E722 @@ -78,9 +76,7 @@ per-file-ignores = python/grass/imaging/images2gif.py: E226 # Unused imports in init files # F403 star import used; unable to detect undefined names - python/grass/*/__init__.py: F401, F403 - python/grass/*/*/__init__.py: F403 - python/grass/*/*/*/__init__.py: F403 + python/grass/temporal/__init__.py: F401, F403 # E402 module level import not at top of file scripts/r.semantic.label/r.semantic.label.py: E501 scripts/g.extension/g.extension.py: E501 diff --git a/python/grass/app/__init__.py b/python/grass/app/__init__.py index df22d8bbb44..b7ff0ce08c0 100644 --- a/python/grass/app/__init__.py +++ b/python/grass/app/__init__.py @@ -1 +1,17 @@ -from .data import * +from .data import ( + get_possible_database_path, + create_database_directory, + create_startup_location_in_grassdb, + ensure_default_data_hierarchy, + MapsetLockingException, + lock_mapset, +) + +__all__ = [ + "MapsetLockingException", + "create_database_directory", + "create_startup_location_in_grassdb", + "ensure_default_data_hierarchy", + "get_possible_database_path", + "lock_mapset", +] diff --git a/python/grass/experimental/__init__.py b/python/grass/experimental/__init__.py index 1253d09df0a..8ccb44413bb 100644 --- a/python/grass/experimental/__init__.py +++ b/python/grass/experimental/__init__.py @@ -1,4 +1,11 @@ """Experimental code, all can change""" -from .create import * -from .mapset import * +from .create import require_create_ensure_mapset, create_temporary_mapset +from .mapset import MapsetSession, TemporaryMapsetSession + +__all__ = [ + "MapsetSession", + "TemporaryMapsetSession", + "create_temporary_mapset", + "require_create_ensure_mapset", +] diff --git a/python/grass/script/__init__.py b/python/grass/script/__init__.py index ea82c2fe451..e7ec1d99e2b 100644 --- a/python/grass/script/__init__.py +++ b/python/grass/script/__init__.py @@ -1,10 +1,207 @@ """Python interface to launch GRASS GIS modules in scripts """ -from .core import * -from .db import * -from .raster import * -from .raster3d import * -from .vector import * -from .utils import * -from . import setup # noqa: F401 +from . import setup +from .core import ( + PIPE, + Popen, + call, + compare_key_value_text_files, + create_environment, + create_location, + create_project, + debug, + debug_level, + del_temp_region, + error, + exec_command, + fatal, + feed_command, + find_file, + find_program, + get_capture_stderr, + get_commands, + get_raise_on_error, + get_real_command, + gisenv, + handle_errors, + info, + legal_name, + list_grouped, + list_pairs, + list_strings, + locn_is_latlong, + make_command, + mapsets, + message, + overwrite, + parse_color, + parse_command, + parser, + percent, + pipe_command, + read_command, + region, + region_env, + run_command, + sanitize_mapset_environment, + set_capture_stderr, + set_raise_on_error, + start_command, + tempdir, + tempfile, + tempname, + use_temp_region, + verbose, + verbosity, + version, + warning, + write_command, +) +from .db import ( + db_begin_transaction, + db_commit_transaction, + db_connection, + db_describe, + db_select, + db_table_exist, + db_table_in_vector, +) +from .raster import mapcalc, mapcalc_start, raster_history, raster_info, raster_what +from .raster3d import mapcalc3d, raster3d_info +from .utils import ( + KeyValue, + append_node_pid, + append_random, + append_uuid, + basename, + clock, + decode, + diff_files, + encode, + float_or_dms, + get_lib_path, + get_num_suffix, + legalize_vector_name, + natural_sort, + naturally_sorted, + parse_key_val, + separator, + set_path, + split, + text_to_string, + try_remove, + try_rmdir, +) +from .vector import ( + vector_columns, + vector_db, + vector_db_select, + vector_history, + vector_info, + vector_info_topo, + vector_layer_db, + vector_what, +) + +__all__ = [ + "PIPE", + "KeyValue", + "Popen", + "append_node_pid", + "append_random", + "append_uuid", + "basename", + "call", + "clock", + "compare_key_value_text_files", + "create_environment", + "create_location", + "create_project", + "db_begin_transaction", + "db_commit_transaction", + "db_connection", + "db_describe", + "db_select", + "db_table_exist", + "db_table_in_vector", + "debug", + "debug_level", + "decode", + "del_temp_region", + "diff_files", + "encode", + "error", + "exec_command", + "fatal", + "feed_command", + "find_file", + "find_program", + "float_or_dms", + "get_capture_stderr", + "get_commands", + "get_lib_path", + "get_num_suffix", + "get_raise_on_error", + "get_real_command", + "gisenv", + "handle_errors", + "info", + "legal_name", + "legalize_vector_name", + "list_grouped", + "list_pairs", + "list_strings", + "locn_is_latlong", + "make_command", + "mapcalc", + "mapcalc3d", + "mapcalc_start", + "mapsets", + "message", + "natural_sort", + "naturally_sorted", + "overwrite", + "parse_color", + "parse_command", + "parse_key_val", + "parser", + "percent", + "pipe_command", + "raster3d_info", + "raster_history", + "raster_info", + "raster_what", + "read_command", + "region", + "region_env", + "run_command", + "sanitize_mapset_environment", + "separator", + "set_capture_stderr", + "set_path", + "set_raise_on_error", + "setup", + "split", + "start_command", + "tempdir", + "tempfile", + "tempname", + "text_to_string", + "try_remove", + "try_rmdir", + "use_temp_region", + "vector_columns", + "vector_db", + "vector_db_select", + "vector_history", + "vector_info", + "vector_info_topo", + "vector_layer_db", + "vector_what", + "verbose", + "verbosity", + "version", + "warning", + "write_command", +] diff --git a/python/grass/temporal/stds_import.py b/python/grass/temporal/stds_import.py index 0f9215a84cb..f7030b66d31 100644 --- a/python/grass/temporal/stds_import.py +++ b/python/grass/temporal/stds_import.py @@ -247,7 +247,7 @@ def import_stds( :param memory: Cache size for raster rows, used in r.in.gdal """ - old_state = gs.raise_on_error + old_state = gs.get_raise_on_error() gs.set_raise_on_error(True) # Check if input file and extraction directory exits