From 3061545a2238ac8facce9a72d5fdb706c4e05e25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lie=20Bouttier?= Date: Wed, 1 Feb 2023 16:23:24 +0100 Subject: [PATCH] lint with black 23.1.0 --- .pre-commit-config.yaml | 2 +- backend/geonature/core/gn_commons/repositories.py | 4 +--- backend/geonature/core/gn_commons/routes.py | 2 -- backend/geonature/core/gn_meta/mtd/xml_parser.py | 1 - backend/geonature/core/gn_meta/routes.py | 2 -- backend/geonature/core/gn_permissions/tools.py | 2 -- backend/geonature/core/gn_synthese/routes.py | 2 +- backend/geonature/core/gn_synthese/utils/process.py | 2 -- backend/geonature/core/notifications/routes.py | 4 +--- backend/geonature/core/notifications/tasks.py | 1 - backend/geonature/core/ref_geo/routes.py | 7 ++++++- backend/geonature/core/users/routes.py | 2 +- ...36d0bd313a47_add_notification_schema_tables_and_data.py | 2 -- ...63b_add_index_on_id_area_for_table_cor_area_synthese.py | 2 -- backend/geonature/tests/fixtures.py | 4 ++-- backend/geonature/tests/test_gn_meta.py | 1 - backend/geonature/tests/test_notifications.py | 3 --- backend/geonature/utils/filemanager.py | 1 - backend/geonature/utils/utilssqlalchemy.py | 2 +- contrib/gn_module_occhab/backend/gn_module_occhab/query.py | 1 - contrib/occtax/backend/occtax/blueprint.py | 1 - 21 files changed, 14 insertions(+), 34 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8eed601bb7..a69db15be2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/psf/black - rev: 22.3.0 + rev: 23.1.0 hooks: - id: black language_version: python3.9 diff --git a/backend/geonature/core/gn_commons/repositories.py b/backend/geonature/core/gn_commons/repositories.py index 7694925b5b..f5e6e486d0 100644 --- a/backend/geonature/core/gn_commons/repositories.py +++ b/backend/geonature/core/gn_commons/repositories.py @@ -161,7 +161,6 @@ def test_header_content_type(self, content_type): return True def test_url(self): - try: if not self.data["media_url"]: return @@ -350,7 +349,6 @@ def delete(self): initial_path = self.media.media_path if self.media.media_path and not current_app.config["SQLALCHEMY_TRACK_MODIFICATIONS"]: - try: self.media.__before_commit_delete__() @@ -423,7 +421,7 @@ def sync_medias(): search_path = pathlib.Path( current_app.config["BASE_DIR"], current_app.config["UPLOAD_FOLDER"] ) - for (repertoire, sous_repertoires, fichiers) in os.walk(search_path): + for repertoire, sous_repertoires, fichiers in os.walk(search_path): for f in fichiers: id_media = f.split("_")[0] try: diff --git a/backend/geonature/core/gn_commons/routes.py b/backend/geonature/core/gn_commons/routes.py index 56e4de4362..219b7cfa0b 100644 --- a/backend/geonature/core/gn_commons/routes.py +++ b/backend/geonature/core/gn_commons/routes.py @@ -141,7 +141,6 @@ def get_additional_fields(): q = q.filter(TAdditionalFields.datasets.any(id_dataset=params["id_dataset"])) if "module_code" in params: if len(params["module_code"].split(",")) > 1: - ors = [ TAdditionalFields.modules.any(module_code=module_code) for module_code in params["module_code"].split(",") @@ -216,7 +215,6 @@ def get_t_mobile_apps(): @json_resp # schema_dot_table gn_commons.t_modules def api_get_id_table_location(schema_dot_table): - schema_name = schema_dot_table.split(".")[0] table_name = schema_dot_table.split(".")[1] return get_table_location_id(schema_name, table_name) diff --git a/backend/geonature/core/gn_meta/mtd/xml_parser.py b/backend/geonature/core/gn_meta/mtd/xml_parser.py index ef898462fc..98ced2625d 100644 --- a/backend/geonature/core/gn_meta/mtd/xml_parser.py +++ b/backend/geonature/core/gn_meta/mtd/xml_parser.py @@ -73,7 +73,6 @@ def parse_acquisition_framwork_xml(xml): def parse_acquisition_framework(ca): - # We extract all the required informations from the different tags of the XML file ca_uuid = get_tag_content(ca, "identifiantCadre") ca_name_max_length = TAcquisitionFramework.acquisition_framework_name.property.columns[ diff --git a/backend/geonature/core/gn_meta/routes.py b/backend/geonature/core/gn_meta/routes.py index 6de3638760..ac8c29a126 100644 --- a/backend/geonature/core/gn_meta/routes.py +++ b/backend/geonature/core/gn_meta/routes.py @@ -367,7 +367,6 @@ def sensi_report(): def my_csv_resp(filename, data, columns, _header, separator=";"): - headers = Headers() headers.add("Content-Type", "text/plain") headers.add("Content-Disposition", "attachment", filename="export_%s.csv" % filename) @@ -748,7 +747,6 @@ def delete_acquisition_framework(scope, af_id): def acquisitionFrameworkHandler(request, *, acquisition_framework): - # Test des droits d'édition du acquisition framework si modification if acquisition_framework.id_acquisition_framework is not None: user_cruved = get_scopes_by_action(module_code="META_DATA") diff --git a/backend/geonature/core/gn_permissions/tools.py b/backend/geonature/core/gn_permissions/tools.py index 9f24cad0ba..aa18562fae 100644 --- a/backend/geonature/core/gn_permissions/tools.py +++ b/backend/geonature/core/gn_permissions/tools.py @@ -90,7 +90,6 @@ class UserCruved: def __init__( self, id_role, code_filter_type, module_code=None, object_code=None, append_to_select=None ): - self._id_role = id_role self._code_filter_type = code_filter_type if module_code: @@ -103,7 +102,6 @@ def __init__( self._permission_select = self._build_permission_select_list(append_to_select) def _build_permission_select_list(self, append_to_select): - # Construction de la liste des couples module_code, object_code # a récupérer pour générer le cruved # append_to_select => Ajout de selection pour complexifié l'héritage diff --git a/backend/geonature/core/gn_synthese/routes.py b/backend/geonature/core/gn_synthese/routes.py index c9ee47bfe6..31f08fef11 100644 --- a/backend/geonature/core/gn_synthese/routes.py +++ b/backend/geonature/core/gn_synthese/routes.py @@ -214,7 +214,7 @@ def get_observations_for_web(scope): # Build final GeoJson geojson_features = [] - for (geom_as_geojson, properties) in results: + for geom_as_geojson, properties in results: geojson_features.append( Feature( geometry=json.loads(geom_as_geojson), diff --git a/backend/geonature/core/gn_synthese/utils/process.py b/backend/geonature/core/gn_synthese/utils/process.py index 3581eb3396..1c1c7c7a51 100644 --- a/backend/geonature/core/gn_synthese/utils/process.py +++ b/backend/geonature/core/gn_synthese/utils/process.py @@ -13,7 +13,6 @@ def import_from_table(schema_name, table_name, field_name, value, limit=50): for all rows satisfying the condition : = """ try: - # TODO get nb txt = """SELECT COUNT(*) FROM {}.{} WHERE {}::varchar = '{}'""".format( schema_name, table_name, field_name, value @@ -26,7 +25,6 @@ def import_from_table(schema_name, table_name, field_name, value, limit=50): # on procède ici par boucle pour traiter un nombre raisonnable de donnée à la fois while limit * i < nb_data: - txt = """SELECT gn_synthese.import_row_from_table( '{}', '{}', diff --git a/backend/geonature/core/notifications/routes.py b/backend/geonature/core/notifications/routes.py index aa38e7261e..093a5ba3c1 100644 --- a/backend/geonature/core/notifications/routes.py +++ b/backend/geonature/core/notifications/routes.py @@ -26,11 +26,11 @@ routes = Blueprint("notifications", __name__) log = logging.getLogger() + # Get all database notification for current user @routes.route("/notifications", methods=["GET"]) @permissions.login_required def list_database_notification(): - notifications = Notification.query.filter(Notification.id_role == g.current_user.id_role) notifications = notifications.order_by( Notification.code_status.desc(), Notification.creation_date.desc() @@ -56,7 +56,6 @@ def list_database_notification(): @routes.route("/count", methods=["GET"]) @permissions.login_required def count_notification(): - notificationNumber = Notification.query.filter( Notification.id_role == g.current_user.id_role, Notification.code_status == "UNREAD" ).count() @@ -67,7 +66,6 @@ def count_notification(): @routes.route("/notifications/", methods=["POST"]) @permissions.login_required def update_notification(id_notification): - notification = Notification.query.get_or_404(id_notification) if notification.id_role != g.current_user.id_role: raise Forbidden diff --git a/backend/geonature/core/notifications/tasks.py b/backend/geonature/core/notifications/tasks.py index 30d825e666..8b238178ff 100644 --- a/backend/geonature/core/notifications/tasks.py +++ b/backend/geonature/core/notifications/tasks.py @@ -8,6 +8,5 @@ @celery_app.task(bind=True) def send_notification_mail(self, subject, content, recipient): - logger.info(f"Launch mail.") mail.send_mail(recipient, subject, content) diff --git a/backend/geonature/core/ref_geo/routes.py b/backend/geonature/core/ref_geo/routes.py index 5990a41451..5cd313e6c3 100644 --- a/backend/geonature/core/ref_geo/routes.py +++ b/backend/geonature/core/ref_geo/routes.py @@ -17,7 +17,12 @@ routes = Blueprint("ref_geo", __name__) -altitude_stmt = sa.select([sa.column("altitude_min"), sa.column("altitude_max"),]).select_from( +altitude_stmt = sa.select( + [ + sa.column("altitude_min"), + sa.column("altitude_max"), + ] +).select_from( func.ref_geo.fct_get_altitude_intersection( func.ST_SetSRID( func.ST_GeomFromGeoJSON(sa.bindparam("geojson")), diff --git a/backend/geonature/core/users/routes.py b/backend/geonature/core/users/routes.py index 7c16d8c03e..77b7bfc758 100644 --- a/backend/geonature/core/users/routes.py +++ b/backend/geonature/core/users/routes.py @@ -117,7 +117,6 @@ def get_roles_by_menu_code(code_liste): @routes.route("/listes", methods=["GET"]) @json_resp def get_listes(): - q = DB.session.query(UserList) lists = q.all() return [l.as_dict() for l in lists] @@ -213,6 +212,7 @@ def get_organismes_jdd(): ### ACCOUNT_MANAGEMENT ROUTES ##### ######################### + # TODO: let frontend call UsersHub directly? @routes.route("/inscription", methods=["POST"]) def inscription(): diff --git a/backend/geonature/migrations/versions/36d0bd313a47_add_notification_schema_tables_and_data.py b/backend/geonature/migrations/versions/36d0bd313a47_add_notification_schema_tables_and_data.py index 8c898859f2..efd19159d8 100644 --- a/backend/geonature/migrations/versions/36d0bd313a47_add_notification_schema_tables_and_data.py +++ b/backend/geonature/migrations/versions/36d0bd313a47_add_notification_schema_tables_and_data.py @@ -22,7 +22,6 @@ def upgrade(): - # Create new schema logger.info("Create schema " + SCHEMA_NAME) op.execute("CREATE SCHEMA " + SCHEMA_NAME) @@ -163,6 +162,5 @@ def upgrade(): def downgrade(): - logger.info("DROP SCHEMA " + SCHEMA_NAME + " CASCADE") op.execute("DROP SCHEMA " + SCHEMA_NAME + " CASCADE") diff --git a/backend/geonature/migrations/versions/8888e5cce63b_add_index_on_id_area_for_table_cor_area_synthese.py b/backend/geonature/migrations/versions/8888e5cce63b_add_index_on_id_area_for_table_cor_area_synthese.py index 8f7c64b6fe..1ee6ae8028 100644 --- a/backend/geonature/migrations/versions/8888e5cce63b_add_index_on_id_area_for_table_cor_area_synthese.py +++ b/backend/geonature/migrations/versions/8888e5cce63b_add_index_on_id_area_for_table_cor_area_synthese.py @@ -22,10 +22,8 @@ def upgrade(): - op.create_index(INDEX_NAME, schema=SCHEMA_NAME, table_name=TABLE_NAME, columns=[COLUMN_NAME]) def downgrade(): - op.drop_index(INDEX_NAME, schema=SCHEMA_NAME, table_name=TABLE_NAME) diff --git a/backend/geonature/tests/fixtures.py b/backend/geonature/tests/fixtures.py index 7a565892fa..f548418dff 100644 --- a/backend/geonature/tests/fixtures.py +++ b/backend/geonature/tests/fixtures.py @@ -297,7 +297,7 @@ def synthese_data(app, users, datasets, source): point3 = Point(-3.486786, 48.832182) data = {} with db.session.begin_nested(): - for (name, cd_nom, point, ds) in [ + for name, cd_nom, point, ds in [ ("obs1", 713776, point1, datasets["own_dataset"]), ("obs2", 212, point2, datasets["own_dataset"]), ("obs3", 2497, point3, datasets["own_dataset"]), @@ -308,7 +308,6 @@ def synthese_data(app, users, datasets, source): ("p2_af1", 2497, point2, datasets["belong_af_1"]), ("p3_af3", 2497, point3, datasets["belong_af_3"]), ]: - unique_id_sinp = ( "f4428222-d038-40bc-bc5c-6e977bbbc92b" if not data else func.uuid_generate_v4() ) @@ -379,6 +378,7 @@ def medium(app): @pytest.fixture() def reports_data(users, synthese_data): data = [] + # do not commit directly on current transaction, as we want to rollback all changes at the end of tests def create_report(id_synthese, id_role, content, id_type, deleted): new_report = TReport( diff --git a/backend/geonature/tests/test_gn_meta.py b/backend/geonature/tests/test_gn_meta.py index 6da1c624f1..c139d87c94 100644 --- a/backend/geonature/tests/test_gn_meta.py +++ b/backend/geonature/tests/test_gn_meta.py @@ -722,7 +722,6 @@ def test_get_af_from_id_none(self): get_af_from_id(id_af=id_af, af_list=af_list) def test__get_create_scope(self, app, users): - modcode = "METADATA" with app.test_request_context(headers=logged_user_headers(users["user"])): diff --git a/backend/geonature/tests/test_notifications.py b/backend/geonature/tests/test_notifications.py index 6d20ead435..2106ab19b2 100644 --- a/backend/geonature/tests/test_notifications.py +++ b/backend/geonature/tests/test_notifications.py @@ -330,7 +330,6 @@ def test_delete_all_rules(self, users, notification_rule): ).scalar() def test_list_methods(self, users, rule_method): - # Init data for test url = "notifications.list_notification_methods" log.debug("Url d'appel %s", url_for(url)) @@ -347,7 +346,6 @@ def test_list_methods(self, users, rule_method): assert len(data) > 0 def test_list_notification_categories(self, users): - # Init data for test url = "notifications.list_notification_categories" log.debug("Url d'appel %s", url_for(url)) @@ -365,7 +363,6 @@ def test_list_notification_categories(self, users): # test only notification insertion in database whitout dispatch def test_send_db_notification(self, users): - result = utils.send_db_notification( users["admin_user"], "test creation", "no templating", "https://geonature.fr" ) diff --git a/backend/geonature/utils/filemanager.py b/backend/geonature/utils/filemanager.py index a219a1541b..27ef6a0c0f 100644 --- a/backend/geonature/utils/filemanager.py +++ b/backend/geonature/utils/filemanager.py @@ -37,7 +37,6 @@ def rename_file(old_chemin, old_title, new_title): def upload_file(file, id_media, cd_ref, titre): - filename = ("{cd_ref}_{id_media}_{title}.{ext}").format( cd_ref=str(cd_ref), id_media=str(id_media), diff --git a/backend/geonature/utils/utilssqlalchemy.py b/backend/geonature/utils/utilssqlalchemy.py index 88a2b7f1aa..195786a3bd 100644 --- a/backend/geonature/utils/utilssqlalchemy.py +++ b/backend/geonature/utils/utilssqlalchemy.py @@ -444,7 +444,7 @@ def serializefn(self, recursif=False, columns=(), relationships=()): if recursif is False: return out - for (rel, uselist) in selected_relationship: + for rel, uselist in selected_relationship: if getattr(self, rel): if uselist is True: out[rel] = [ diff --git a/contrib/gn_module_occhab/backend/gn_module_occhab/query.py b/contrib/gn_module_occhab/backend/gn_module_occhab/query.py index 224f986196..bc65ace65c 100644 --- a/contrib/gn_module_occhab/backend/gn_module_occhab/query.py +++ b/contrib/gn_module_occhab/backend/gn_module_occhab/query.py @@ -45,7 +45,6 @@ def filter_query_with_cruved( ) ) if user.value_filter in ("1", "2"): - sub_query_id_role = ( DB.session.query(CorStationObserverOccHab) .filter(CorStationObserverOccHab.id_role == user.id_role) diff --git a/contrib/occtax/backend/occtax/blueprint.py b/contrib/occtax/backend/occtax/blueprint.py index d49488a719..c123302077 100644 --- a/contrib/occtax/backend/occtax/blueprint.py +++ b/contrib/occtax/backend/occtax/blueprint.py @@ -526,7 +526,6 @@ def updateReleve(id_releve, info_role): def occurrenceHandler(request, *, occurrence, info_role): - releve = TRelevesOccurrence.query.get_or_404(occurrence.id_releve_occtax) # Test des droits d'édition du relevé si modification