Skip to content

Commit

Permalink
Introduce ruff (#574)
Browse files Browse the repository at this point in the history
* rename location

* fixes for tests and G83

* fix job resumption tests

* linting

* initial ruff check

* update test imports

* lint

* F841 and Post-PR

* lint

* test with wip linting workflow

* test post-pr

* fix ref

* trigger build

* always-post-pr

* post-pr in separate workflow

* rename workflow

* fix lint error

* trigger pipelines

* add ruff config

* update post-pr workflow

* Update .github/workflows/linting.yml

* fix tests

---------

Co-authored-by: anikaweinmann <[email protected]>
  • Loading branch information
mmacata and anikaweinmann authored Dec 5, 2024
1 parent 43af50c commit 4dca658
Show file tree
Hide file tree
Showing 23 changed files with 263 additions and 190 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/linting.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
name: Linting and code quality check

on: [push, pull_request]
on:
push:
branches:
- main
- develop
pull_request:

jobs:
lint:
Expand Down
11 changes: 11 additions & 0 deletions .github/workflows/post-pr-reviews.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name: Post PR code suggestions

on:
workflow_run:
workflows: ["Linting and code quality check"]
types:
- completed

jobs:
post-pr-reviews:
uses: mundialis/github-workflows/.github/workflows/post-pr-reviews.yml@main
188 changes: 188 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
# Extends https://github.com/mundialis/github-workflows/blob/main/linting-config-examples/ruff.toml

lint.ignore = [
# See https://docs.astral.sh/ruff/rules/
# TODO: fix lint issues or use lint_per-file-ignores
"A001",
"A002",
"A004",
"ANN001",
"ANN002",
"ANN003",
"ANN201",
"ANN202",
"ANN204",
"ANN205",
"ANN206",
"ARG001",
"ARG002",
"B006",
"B007",
"B018",
"B904",
"BLE001",
"COM812",
"D100",
"D101",
"D102",
"D103",
"D104",
"D105",
"D107",
"D200",
"D202",
"D205",
"D208",
"D209",
"D212",
"D213",
"D214",
"D301",
"D400",
"D401",
"D402",
"D403",
"D404",
"D411",
"D412",
"D413",
"D414",
"D415",
"D417",
"D419",
"DTZ003",
"DTZ005",
"E501",
"FBT002",
"FBT003",
"FURB101",
"FURB103",
"FURB113",
"FURB118",
"FURB154",
"FURB171",
"G002",
"G003",
"G004",
"I001",
"ICN001",
"ISC001",
"ISC003",
"N802",
"N806",
"N814",
"N818",
"PERF102",
"PERF203",
"PERF401",
"PIE790",
"PLC0206",
"PLC0415",
"PLC1901",
"PLR0904",
"PLR0911",
"PLR0912",
"PLR0913",
"PLR0914",
"PLR0915",
"PLR0917",
"PLR1702",
"PLR1704",
"PLR1711",
"PLR1714",
"PLR1722",
"PLR1730",
"PLR2004",
"PLR5501",
"PLR6104",
"PLR6201",
"PLR6301",
"PLW0127",
"PLW0133",
"PLW0602",
"PLW0603",
"PLW1510",
"PLW1514",
"PLW2901",
"PT006",
"PT009",
"PT027",
"PTH100",
"PTH101",
"PTH102",
"PTH103",
"PTH104",
"PTH105",
"PTH107",
"PTH109",
"PTH110",
"PTH112",
"PTH113",
"PTH118",
"PTH119",
"PTH120",
"PTH122",
"PTH123",
"PTH202",
"RET503",
"RET504",
"RET505",
"RET506",
"RET508",
"RUF010",
"RUF012",
"RUF015",
"RUF019",
"S101",
"S102",
"S104",
"S105",
"S106",
"S107",
"S108",
"S110",
"S113",
"S301",
"S307",
"S310",
"S311",
"S314",
"S403",
"S404",
"S405",
"S603",
"S605",
"S606",
"S607",
"S608",
"SIM102",
"SIM103",
"SIM105",
"SIM108",
"SIM113",
"SIM114",
"SIM115",
"SIM118",
"SIM300",
"SIM401",
"SLF001",
"TID252",
"TRY002",
"TRY003",
"TRY201",
"TRY203",
"TRY300",
"TRY301",
"TRY400",
"UP004",
"UP008",
"UP009",
"UP015",
"UP024",
"UP031",
"UP032",
]

# [lint.per-file-ignores]
# Define file-specific linting rule ignores
# "lib_dop/r_dop_import_lib.py" = ["ERA001", "PLR2004"]
3 changes: 2 additions & 1 deletion src/actinia_core/core/common/api_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@
from fluent import sender
from fluent import event

has_fluent = True
if sender and event:
has_fluent = True
except Exception:
has_fluent = False

Expand Down
20 changes: 10 additions & 10 deletions src/actinia_core/core/common/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@
App configuration of flask, flask_restful, redis server connection
and global settings
"""
from flask_httpauth import HTTPBasicAuth
from flask_httpauth import HTTPTokenAuth
from flask_cors import CORS
from flask import Flask
from flask_restful_swagger_2 import Api

from actinia_core.core.common.config import global_config, DEFAULT_CONFIG_PATH

from actinia_api import API_VERSION, URL_PREFIX

actinia_string = """Actinia"""

actinia_description = """
Expand Down Expand Up @@ -105,16 +115,6 @@
a cloud storage for download.
"""

from flask_httpauth import HTTPBasicAuth
from flask_httpauth import HTTPTokenAuth
from flask_cors import CORS
from flask import Flask
from flask_restful_swagger_2 import Api

from actinia_core.core.common.config import global_config, DEFAULT_CONFIG_PATH

from actinia_api import API_VERSION, URL_PREFIX

__license__ = "GPLv3"
__author__ = "Sören Gebbert, Julia Haas, Anika Weinmann"
__copyright__ = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -827,7 +827,7 @@ def get_sentinel_urls(self, product_ids, bands=None):
# The whole XML content is returned as well
(
gml,
xml_metadata,
_,
bbox,
) = self._generate_sentinel2_footprint(base_url=base_url)
result[product_id]["gml_footprint"] = gml
Expand Down
4 changes: 2 additions & 2 deletions src/actinia_core/core/common/process_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def _get_landsat_import_download_commands(self, entry):
scene_id=scene,
)

download_commands, import_file_info = lp.get_download_process_list()
download_commands, _ = lp.get_download_process_list()
import_commands = lp.get_import_process_list()
atcor_commands = lp.get_i_landsat_toar_process_list(atcor)
landsat_commands = download_commands
Expand Down Expand Up @@ -332,7 +332,7 @@ def _get_sentinel_import_command(self, entry):
import_commands = sp.get_sentinel2_import_process_list()
sentinel_commands.extend(import_commands)

input_file, map_name = import_file_info[band]
_, map_name = import_file_info[band]
p = Process(
exec_type="grass",
executable="g.rename",
Expand Down
6 changes: 3 additions & 3 deletions src/actinia_core/core/common/process_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import queue as standard_queue
from multiprocessing import Process, Queue
from threading import Thread, Lock
import logging
import atexit
from actinia_core.core.resources_logger import ResourceLogger
from actinia_core.core.logging_interface import log
Expand All @@ -48,7 +47,8 @@
try:
from fluent import handler

has_fluent = True
if handler:
has_fluent = True
except Exception:
print("Fluent is not available")
has_fluent = False
Expand Down Expand Up @@ -247,7 +247,7 @@ def check_exit(self):
)

if response_data is not None:
http_code, response_model = pickle.loads(response_data)
_, response_model = pickle.loads(response_data)
if (
response_model["status"] != "error"
and response_model["status"] != "terminated"
Expand Down
2 changes: 1 addition & 1 deletion src/actinia_core/core/grass_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ def setup_tmp_region(self):
"""
# Safe the current region in a temporary region that can be overwritten
errorid, stdout_buff, stderr_buff = self.run_module(
errorid, _, _ = self.run_module(
"g.region", ["save=%s" % self.tmp_region_name, "--o"]
)

Expand Down
Loading

0 comments on commit 4dca658

Please sign in to comment.