From 37b0e9a58f1b0bcb217fe0e3adb71e74154c9776 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 4 Nov 2024 21:36:40 +0000 Subject: [PATCH] chore(pre-commit): autofix run --- config.py | 2 +- runner/__init__.py | 1 + runner/model.py | 1 - runner/scripts/em_cmd.py | 1 - runner/scripts/em_code.py | 1 - runner/scripts/em_date.py | 1 - runner/scripts/em_ftp.py | 1 - runner/scripts/em_messages.py | 1 - runner/scripts/em_python.py | 1 - runner/scripts/em_sftp.py | 17 +- runner/scripts/em_ssh.py | 1 + runner/scripts/smb_fix.py | 1 + runner/scripts/task_runner.py | 8 +- runner/tests/__init__.py | 1 + runner/tests/conftest.py | 1 + runner/tests/test_filters.py | 1 + runner/tests/test_scripts_code.py | 1 - runner/tests/test_scripts_date.py | 1 - runner/tests/test_scripts_postgres.py | 1 + runner/tests/test_scripts_sftp.py | 1 + runner/tests/test_scripts_system.py | 1 - runner/web/__init__.py | 1 + scheduler/__init__.py | 1 - scheduler/model.py | 1 - scheduler/tests/__init__.py | 1 + scheduler/tests/conftest.py | 1 + scheduler/tests/test_api.py | 1 + scheduler/tests/test_events.py | 1 + scripts/crypto.py | 1 - web/cli.py | 1 + web/extensions.py | 1 + web/model.py | 1 - web/seed.py | 1 + web/tests/__init__.py | 1 + web/tests/test_auth.py | 1 - web/tests/test_dashboard.py | 1 - web/tests/test_filters.py | 1 + web/tests/test_projects.py | 1 + web/tests/test_tables.py | 1 + web/tests/test_task_controls.py | 1 + web/tests/test_task_edit.py | 1 + web/web/admin.py | 1 - web/web/assets.py | 1 - web/web/ldap_auth.py | 1 + web/web/saml_auth.py | 1 - web/web/table.py | 285 +++++++++++++++----------- 46 files changed, 199 insertions(+), 155 deletions(-) diff --git a/config.py b/config.py index 017d38f7..0a3a52bd 100644 --- a/config.py +++ b/config.py @@ -348,7 +348,7 @@ class TestConfig(DevConfig): # pylint: disable=too-few-public-methods SQLALCHEMY_DATABASE_URI = os.environ.get( "DATABASE_URL", - "postgresql+psycopg2://postgres@localhost/atlas_hub_scrap_test" + "postgresql+psycopg2://postgres@localhost/atlas_hub_scrap_test", # "sqlite:///../test.sqlite", ).replace("postgres://", "postgresql://") diff --git a/runner/__init__.py b/runner/__init__.py index 501e881a..40483ce3 100644 --- a/runner/__init__.py +++ b/runner/__init__.py @@ -34,6 +34,7 @@ cp web/model.py scheduler/ """ + import logging import os diff --git a/runner/model.py b/runner/model.py index 1ce36e25..2a271103 100644 --- a/runner/model.py +++ b/runner/model.py @@ -20,7 +20,6 @@ """ - import datetime from dataclasses import dataclass from typing import Optional diff --git a/runner/scripts/em_cmd.py b/runner/scripts/em_cmd.py index 22de03ec..c09af627 100644 --- a/runner/scripts/em_cmd.py +++ b/runner/scripts/em_cmd.py @@ -1,6 +1,5 @@ """Functions used to run system commands.""" - import os import re import subprocess diff --git a/runner/scripts/em_code.py b/runner/scripts/em_code.py index 838cef55..f271a6cd 100644 --- a/runner/scripts/em_code.py +++ b/runner/scripts/em_code.py @@ -1,6 +1,5 @@ """Task source code handler.""" - import re import urllib.parse from typing import Optional diff --git a/runner/scripts/em_date.py b/runner/scripts/em_date.py index 9862108a..1b7821b0 100644 --- a/runner/scripts/em_date.py +++ b/runner/scripts/em_date.py @@ -20,7 +20,6 @@ years """ - import calendar import datetime import re diff --git a/runner/scripts/em_ftp.py b/runner/scripts/em_ftp.py index b2f70022..808d7b9e 100644 --- a/runner/scripts/em_ftp.py +++ b/runner/scripts/em_ftp.py @@ -1,6 +1,5 @@ """FTP connection manager.""" - import csv import fnmatch import ftplib # noqa: S402 diff --git a/runner/scripts/em_messages.py b/runner/scripts/em_messages.py index 41fd6d77..9ec0eae1 100644 --- a/runner/scripts/em_messages.py +++ b/runner/scripts/em_messages.py @@ -1,6 +1,5 @@ """Exception and logging messages.""" - import datetime import sys from dataclasses import dataclass diff --git a/runner/scripts/em_python.py b/runner/scripts/em_python.py index 8af2a99d..abcb95e4 100644 --- a/runner/scripts/em_python.py +++ b/runner/scripts/em_python.py @@ -1,6 +1,5 @@ """Python script runner.""" - import ast import datetime import sys diff --git a/runner/scripts/em_sftp.py b/runner/scripts/em_sftp.py index 0f7c3759..c483b998 100644 --- a/runner/scripts/em_sftp.py +++ b/runner/scripts/em_sftp.py @@ -1,6 +1,5 @@ """SFTP connection manager.""" - import csv import fnmatch import os @@ -39,9 +38,11 @@ def connection_key(connection: ConnectionSftp) -> Optional[paramiko.pkey.PKey]: key = paramiko.RSAKey.from_private_key_file( key_file.name, - password=em_decrypt(connection.key_password, app.config["PASS_KEY"]) - if connection.key_password - else None, + password=( + em_decrypt(connection.key_password, app.config["PASS_KEY"]) + if connection.key_password + else None + ), ) return key @@ -81,9 +82,11 @@ def connect(connection: ConnectionSftp) -> Tuple[Transport, SFTPClient]: transport.auth_publickey(connection.username, key, event=None) transport.auth_password( connection.username, - em_decrypt(connection.password, app.config["PASS_KEY"]) - if connection.password - else "", + ( + em_decrypt(connection.password, app.config["PASS_KEY"]) + if connection.password + else "" + ), event=None, ) diff --git a/runner/scripts/em_ssh.py b/runner/scripts/em_ssh.py index 09989ca4..234a4721 100644 --- a/runner/scripts/em_ssh.py +++ b/runner/scripts/em_ssh.py @@ -1,4 +1,5 @@ """SSH connection handler.""" + import select import sys import time diff --git a/runner/scripts/smb_fix.py b/runner/scripts/smb_fix.py index 7cdaaede..5c6891c0 100644 --- a/runner/scripts/smb_fix.py +++ b/runner/scripts/smb_fix.py @@ -1,4 +1,5 @@ """Update to an older version of https://github.com/miketeo/pysmb. Waiting for next release.""" + # flake8: noqa # type: ignore # mypy: ignore-errors diff --git a/runner/scripts/task_runner.py b/runner/scripts/task_runner.py index acea1e1e..407e3245 100644 --- a/runner/scripts/task_runner.py +++ b/runner/scripts/task_runner.py @@ -710,9 +710,11 @@ def __process(self) -> None: run_id=self.run_id, directory=self.temp_path, source_files=self.source_files, - script=self.task.processing_command or processing_script_name.name - if self.task.processing_type_id != 6 # source code - else processing_script_name.name, + script=( + self.task.processing_command or processing_script_name.name + if self.task.processing_type_id != 6 # source code + else processing_script_name.name + ), params=self.param_loader, ).run() except BaseException as e: diff --git a/runner/tests/__init__.py b/runner/tests/__init__.py index 3a49a28b..ddedae7e 100644 --- a/runner/tests/__init__.py +++ b/runner/tests/__init__.py @@ -5,6 +5,7 @@ poetry run pytest runner/tests/ \ --cov --cov-append --cov-branch --cov-report=term-missing --disable-warnings """ + import sys from pathlib import Path diff --git a/runner/tests/conftest.py b/runner/tests/conftest.py index 40d32a76..d5123d34 100644 --- a/runner/tests/conftest.py +++ b/runner/tests/conftest.py @@ -1,4 +1,5 @@ """Setyp pytest.""" + import os import pytest diff --git a/runner/tests/test_filters.py b/runner/tests/test_filters.py index 930c4d8c..0e8a192c 100644 --- a/runner/tests/test_filters.py +++ b/runner/tests/test_filters.py @@ -11,6 +11,7 @@ """ + import datetime from pytest import fixture diff --git a/runner/tests/test_scripts_code.py b/runner/tests/test_scripts_code.py index e6d1ff6d..1e4efe3d 100644 --- a/runner/tests/test_scripts_code.py +++ b/runner/tests/test_scripts_code.py @@ -11,7 +11,6 @@ """ - from pytest import fixture from runner.extensions import db diff --git a/runner/tests/test_scripts_date.py b/runner/tests/test_scripts_date.py index 68e09451..f957871f 100644 --- a/runner/tests/test_scripts_date.py +++ b/runner/tests/test_scripts_date.py @@ -11,7 +11,6 @@ """ - import calendar import datetime diff --git a/runner/tests/test_scripts_postgres.py b/runner/tests/test_scripts_postgres.py index 1f60c7b4..630d9eb4 100644 --- a/runner/tests/test_scripts_postgres.py +++ b/runner/tests/test_scripts_postgres.py @@ -10,6 +10,7 @@ --cov --cov-append --cov-branch --cov-report=term-missing --disable-warnings """ + from pathlib import Path import pytest diff --git a/runner/tests/test_scripts_sftp.py b/runner/tests/test_scripts_sftp.py index bbce4263..3a22d470 100644 --- a/runner/tests/test_scripts_sftp.py +++ b/runner/tests/test_scripts_sftp.py @@ -10,6 +10,7 @@ --cov --cov-append --cov-branch --cov-report=term-missing --disable-warnings """ + import sys import tempfile from pathlib import Path diff --git a/runner/tests/test_scripts_system.py b/runner/tests/test_scripts_system.py index 29802606..1ad5aff7 100644 --- a/runner/tests/test_scripts_system.py +++ b/runner/tests/test_scripts_system.py @@ -11,7 +11,6 @@ """ - import pytest from pytest import fixture diff --git a/runner/web/__init__.py b/runner/web/__init__.py index a1b3397c..e90350ac 100644 --- a/runner/web/__init__.py +++ b/runner/web/__init__.py @@ -1,2 +1,3 @@ """Import web modules.""" + print(__name__) # noqa: T201 diff --git a/scheduler/__init__.py b/scheduler/__init__.py index 098bdcd7..ce51a944 100644 --- a/scheduler/__init__.py +++ b/scheduler/__init__.py @@ -41,7 +41,6 @@ """ - import contextlib import logging import os diff --git a/scheduler/model.py b/scheduler/model.py index 1ce36e25..2a271103 100644 --- a/scheduler/model.py +++ b/scheduler/model.py @@ -20,7 +20,6 @@ """ - import datetime from dataclasses import dataclass from typing import Optional diff --git a/scheduler/tests/__init__.py b/scheduler/tests/__init__.py index f8616900..50a87b88 100644 --- a/scheduler/tests/__init__.py +++ b/scheduler/tests/__init__.py @@ -5,6 +5,7 @@ poetry run pytest tests/ \ --cov --cov-append --cov-branch --cov-report=term-missing --disable-warnings """ + import sys from pathlib import Path diff --git a/scheduler/tests/conftest.py b/scheduler/tests/conftest.py index 608a05fe..613651b8 100644 --- a/scheduler/tests/conftest.py +++ b/scheduler/tests/conftest.py @@ -1,4 +1,5 @@ """Setyp pytest.""" + import os import sys from pathlib import Path diff --git a/scheduler/tests/test_api.py b/scheduler/tests/test_api.py index 3bf21543..1304b707 100644 --- a/scheduler/tests/test_api.py +++ b/scheduler/tests/test_api.py @@ -9,6 +9,7 @@ --cov --cov-append --cov-branch --cov-report=term-missing --disable-warnings """ + # flake8: noqa, # pylint: skip-file # check all admin links diff --git a/scheduler/tests/test_events.py b/scheduler/tests/test_events.py index 510d1ab6..55aab48f 100644 --- a/scheduler/tests/test_events.py +++ b/scheduler/tests/test_events.py @@ -9,6 +9,7 @@ --cov --cov-append --cov-branch --cov-report=term-missing --disable-warnings """ + print("importing tests") import time from datetime import datetime, timedelta diff --git a/scripts/crypto.py b/scripts/crypto.py index b97bb6ac..55b1d3e6 100644 --- a/scripts/crypto.py +++ b/scripts/crypto.py @@ -1,6 +1,5 @@ """Password encryption and decryption.""" - from base64 import b64decode, b64encode from cryptography.fernet import Fernet diff --git a/web/cli.py b/web/cli.py index a30360da..dc7f1e23 100644 --- a/web/cli.py +++ b/web/cli.py @@ -1,4 +1,5 @@ """EM Web Custom CLI.""" + import sys from pathlib import Path diff --git a/web/extensions.py b/web/extensions.py index 090e1f3a..e4c4a1d8 100644 --- a/web/extensions.py +++ b/web/extensions.py @@ -9,6 +9,7 @@ scripts after running :obj:`web.create_app` """ + import logging from flask_assets import Environment diff --git a/web/model.py b/web/model.py index 1ce36e25..2a271103 100644 --- a/web/model.py +++ b/web/model.py @@ -20,7 +20,6 @@ """ - import datetime from dataclasses import dataclass from typing import Optional diff --git a/web/seed.py b/web/seed.py index f63b57cf..91bed61b 100644 --- a/web/seed.py +++ b/web/seed.py @@ -14,6 +14,7 @@ flask seed_demo """ + # pylint: disable=C0301 import sys diff --git a/web/tests/__init__.py b/web/tests/__init__.py index f8616900..50a87b88 100644 --- a/web/tests/__init__.py +++ b/web/tests/__init__.py @@ -5,6 +5,7 @@ poetry run pytest tests/ \ --cov --cov-append --cov-branch --cov-report=term-missing --disable-warnings """ + import sys from pathlib import Path diff --git a/web/tests/test_auth.py b/web/tests/test_auth.py index 6348cfee..8939c23d 100644 --- a/web/tests/test_auth.py +++ b/web/tests/test_auth.py @@ -11,7 +11,6 @@ """ - from flask import url_for from flask.wrappers import Response from flask_login import current_user diff --git a/web/tests/test_dashboard.py b/web/tests/test_dashboard.py index aaa35bb3..69a9fe21 100644 --- a/web/tests/test_dashboard.py +++ b/web/tests/test_dashboard.py @@ -12,7 +12,6 @@ """ - from pytest import fixture from web.extensions import db diff --git a/web/tests/test_filters.py b/web/tests/test_filters.py index 7c9ad2ef..a9fa7bfd 100644 --- a/web/tests/test_filters.py +++ b/web/tests/test_filters.py @@ -11,6 +11,7 @@ """ + import datetime diff --git a/web/tests/test_projects.py b/web/tests/test_projects.py index 97690484..8b81d03e 100644 --- a/web/tests/test_projects.py +++ b/web/tests/test_projects.py @@ -11,6 +11,7 @@ """ + import time from datetime import datetime diff --git a/web/tests/test_tables.py b/web/tests/test_tables.py index 180d9b52..5aa820ad 100644 --- a/web/tests/test_tables.py +++ b/web/tests/test_tables.py @@ -11,6 +11,7 @@ """ + import json from pytest import fixture diff --git a/web/tests/test_task_controls.py b/web/tests/test_task_controls.py index 9f3517de..ce92d129 100644 --- a/web/tests/test_task_controls.py +++ b/web/tests/test_task_controls.py @@ -11,6 +11,7 @@ """ + import json import time diff --git a/web/tests/test_task_edit.py b/web/tests/test_task_edit.py index 067ca8d7..8db9311d 100644 --- a/web/tests/test_task_edit.py +++ b/web/tests/test_task_edit.py @@ -11,6 +11,7 @@ """ + from flask import request, url_for from pytest import fixture diff --git a/web/web/admin.py b/web/web/admin.py index 54cc38ea..f26fe27c 100644 --- a/web/web/admin.py +++ b/web/web/admin.py @@ -1,6 +1,5 @@ """Admin web views.""" - import json import platform from pathlib import Path diff --git a/web/web/assets.py b/web/web/assets.py index f98f3927..e21ac62e 100644 --- a/web/web/assets.py +++ b/web/web/assets.py @@ -3,7 +3,6 @@ CSS assets are compiles from scss to css with gulp. Webassets combines the output css and versions them nicely. """ - from flask_assets import Bundle from webassets.filter import register_filter from webassets_rollup import Rollup diff --git a/web/web/ldap_auth.py b/web/web/ldap_auth.py index acd59874..fd44b8c8 100644 --- a/web/web/ldap_auth.py +++ b/web/web/ldap_auth.py @@ -2,6 +2,7 @@ Modification of Flask-SimpleLDAP script by https://github.com/alexferl/flask-simpleldap. """ + # mypy: ignore-errors import re diff --git a/web/web/saml_auth.py b/web/web/saml_auth.py index 8236617d..2b315f8a 100644 --- a/web/web/saml_auth.py +++ b/web/web/saml_auth.py @@ -1,6 +1,5 @@ """SAML Login/Logout web views.""" - from flask import Blueprint, Flask, abort from flask import current_app as app from flask import flash, make_response, redirect, request, session, url_for diff --git a/web/web/table.py b/web/web/table.py index e18eee61..4532baa1 100644 --- a/web/web/table.py +++ b/web/web/table.py @@ -116,14 +116,15 @@ def project_list(my_type: str = "all") -> Response: me.append( { "Name": f'{status_icon}{proj["Name"]}', - "Last Run": relative_to_now(proj["Last Run"]) - if proj["Last Run"] - else "", - "Next Run": datetime.datetime.strftime( - proj["Next Run"], " %m/%-d/%y %H:%M" - ) - if proj["Next Run"] and isinstance(proj["Next Run"], datetime.datetime) - else (proj["Next Run"] if proj["Next Run"] else "None"), + "Last Run": ( + relative_to_now(proj["Last Run"]) if proj["Last Run"] else "" + ), + "Next Run": ( + datetime.datetime.strftime(proj["Next Run"], " %m/%-d/%y %H:%M") + if proj["Next Run"] + and isinstance(proj["Next Run"], datetime.datetime) + else (proj["Next Run"] if proj["Next Run"] else "None") + ), "Tasks": str((proj["Tasks"] or 0)), } ) @@ -176,13 +177,15 @@ def tasklog_userevents() -> Response: me.append( { - "Task Name": '' - + log["Task Name"] - + "" - if log["Task Name"] - else "N/A", + "Task Name": ( + '' + + log["Task Name"] + + "" + if log["Task Name"] + else "N/A" + ), "Run Id": ( "' + task["Task Name"] + "", - "Project Name": '' - + task["Project Name"] - + "" - if task["Project Id"] - else "Orphan :'(", + "Project Name": ( + '' + + task["Project Name"] + + "" + if task["Project Id"] + else "Orphan :'(" + ), "Connection": task["Connection"], - "Enabled": "Disable" - if task["Enabled"] == 1 - else "Enable", - "Last Run": datetime.datetime.strftime( - task["Last Run"], "%a, %b %-d, %Y %H:%M:%S" - ) - if task["Last Run"] and isinstance(task["Last Run"], datetime.datetime) - else (task["Last Run"] if task["Last Run"] else "Never"), + "Enabled": ( + "Disable" + if task["Enabled"] == 1 + else "Enable" + ), + "Last Run": ( + datetime.datetime.strftime( + task["Last Run"], "%a, %b %-d, %Y %H:%M:%S" + ) + if task["Last Run"] + and isinstance(task["Last Run"], datetime.datetime) + else (task["Last Run"] if task["Last Run"] else "Never") + ), "Run Now": "Run Now", "Status": task["Status"] if task["Status"] else "None", - "Next Run": datetime.datetime.strftime( - task["Next Run"], "%a, %b %-d, %Y %H:%M:%S" - ) - if task["Next Run"] and isinstance(task["Next Run"], datetime.datetime) - else (task["Next Run"] if task["Next Run"] else "None"), - "class": "error" - if task["Status Id"] == 2 - or (not task["Next Run"] and task["Enabled"] == 1) - else "", + "Next Run": ( + datetime.datetime.strftime( + task["Next Run"], "%a, %b %-d, %Y %H:%M:%S" + ) + if task["Next Run"] + and isinstance(task["Next Run"], datetime.datetime) + else (task["Next Run"] if task["Next Run"] else "None") + ), + "class": ( + "error" + if task["Status Id"] == 2 + or (not task["Next Run"] and task["Enabled"] == 1) + else "" + ), } ) @@ -620,17 +637,18 @@ def dash_tasks(task_type: str) -> Response: if task["Owner Id"] else "" ), - "Last Run": relative_to_now(task["Last Run"]) - if task["Last Run"] - else "Never", - "Started": relative_to_now(task["Last Run"]) - if task["Last Run"] - else "Never", - "Next Run": datetime.datetime.strftime( - task["Next Run"], "%m/%-d/%y %H:%M" - ) - if task["Next Run"] and isinstance(task["Next Run"], datetime.datetime) - else (task["Next Run"] if task["Next Run"] else "None"), + "Last Run": ( + relative_to_now(task["Last Run"]) if task["Last Run"] else "Never" + ), + "Started": ( + relative_to_now(task["Last Run"]) if task["Last Run"] else "Never" + ), + "Next Run": ( + datetime.datetime.strftime(task["Next Run"], "%m/%-d/%y %H:%M") + if task["Next Run"] + and isinstance(task["Next Run"], datetime.datetime) + else (task["Next Run"] if task["Next Run"] else "None") + ), "Actions": ( ( "{enabled}{status_icon}{task["Name"]}', "Last Run": relative_to_now(task["Last Run"]) if task["Last Run"] else "", - "Next Run": datetime.datetime.strftime(task["Next Run"], "%m/%-d/%y %H:%M") - if task["Next Run"] and isinstance(task["Next Run"], datetime.datetime) - else (task["Next Run"] if task["Next Run"] else ""), + "Next Run": ( + datetime.datetime.strftime(task["Next Run"], "%m/%-d/%y %H:%M") + if task["Next Run"] and isinstance(task["Next Run"], datetime.datetime) + else (task["Next Run"] if task["Next Run"] else "") + ), } if my_type == "all": @@ -829,17 +849,18 @@ def project_all_tasks(project_id: int) -> Response: me.append( { "Name": f'