From ad9bd55168eaa6555aac71f043e6b2b0481d1f92 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 2 Sep 2024 21:08:21 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- septentrion/cli.py | 3 ++- septentrion/configuration.py | 3 ++- septentrion/core.py | 1 + septentrion/db.py | 2 +- septentrion/files.py | 3 +-- septentrion/migration.py | 3 +-- septentrion/style.py | 2 +- tests/integration/test_runner.py | 4 ++-- tests/unit/test_configuration.py | 3 +-- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/septentrion/cli.py b/septentrion/cli.py index 043510e..488f8df 100644 --- a/septentrion/cli.py +++ b/septentrion/cli.py @@ -3,6 +3,7 @@ from other modules to get the information it needs, then format it and display it. """ + import functools import logging import os @@ -60,7 +61,7 @@ class CommaSeparatedMultipleString(StringParamType): envvar_list_splitter = "," def split_envvar_value(self, rv: str): - values = super(CommaSeparatedMultipleString, self).split_envvar_value(rv) + values = super().split_envvar_value(rv) return tuple(value.strip() for value in values) diff --git a/septentrion/configuration.py b/septentrion/configuration.py index e7bd35c..7eb71ee 100644 --- a/septentrion/configuration.py +++ b/septentrion/configuration.py @@ -2,6 +2,7 @@ This is the code around settings loading. For a definition of the settings, see cli.py (for now) """ + import configparser import logging import pathlib @@ -68,7 +69,7 @@ def read_default_configuration_files() -> Tuple[str, pathlib.Path]: def read_configuration_file(path: pathlib.Path) -> str: - with open(path, "r") as handler: + with open(path) as handler: logger.info(f"Reading configuration from {path}") return handler.read() diff --git a/septentrion/core.py b/septentrion/core.py index ec77f8a..5ce7c42 100644 --- a/septentrion/core.py +++ b/septentrion/core.py @@ -2,6 +2,7 @@ This is where the migration plan is computed, by merging information from the existing files (septentrion.files) and from the db (septentrion.db) """ + import logging from typing import Any, Dict, Iterable, Optional diff --git a/septentrion/db.py b/septentrion/db.py index fe7fd89..dc821b1 100644 --- a/septentrion/db.py +++ b/septentrion/db.py @@ -77,7 +77,7 @@ def execute( conn.commit() -class Query(object): +class Query: def __init__( self, settings: configuration.Settings, diff --git a/septentrion/files.py b/septentrion/files.py index 49c41ad..6cb6e7f 100644 --- a/septentrion/files.py +++ b/septentrion/files.py @@ -110,5 +110,4 @@ def list_migrations_and_paths( def file_lines_generator(path: pathlib.Path): with open(path) as f: - for line in f: - yield line + yield from f diff --git a/septentrion/migration.py b/septentrion/migration.py index b3580b1..f4a047c 100644 --- a/septentrion/migration.py +++ b/septentrion/migration.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- import io import logging import pathlib @@ -192,6 +191,6 @@ def create_fake_entries( def run_script(settings: configuration.Settings, path: pathlib.Path) -> None: logger.info("Running SQL file %s", path) - with io.open(path, "r", encoding="utf8") as f: + with open(path, encoding="utf8") as f: script = runner.Script(settings=settings, file_handler=f, path=path) script.run() diff --git a/septentrion/style.py b/septentrion/style.py index ac730ba..4dc0f7b 100644 --- a/septentrion/style.py +++ b/septentrion/style.py @@ -7,7 +7,7 @@ colorama.init() -class Stylist(object): +class Stylist: styles: Dict[str, str] = { "reset": colorama.Style.RESET_ALL, "title": colorama.Fore.CYAN + colorama.Style.BRIGHT, diff --git a/tests/integration/test_runner.py b/tests/integration/test_runner.py index fc63791..4334d51 100644 --- a/tests/integration/test_runner.py +++ b/tests/integration/test_runner.py @@ -15,7 +15,7 @@ def _run_script(script): path = tmp_path / "script.sql" path.write_text(script) - with io.open(path, "r", encoding="utf8") as f: + with open(path, encoding="utf8") as f: script = Script(settings, f, path) script.run() @@ -65,7 +65,7 @@ def test_run_integer_in_settings(db, settings_factory, env, tmp_path): settings.PORT = 5432 path = tmp_path / "script.sql" path.write_text("SELECT 1;") - with io.open(path, "r", encoding="utf8") as f: + with open(path, encoding="utf8") as f: script = Script(settings, f, path) script.run() diff --git a/tests/unit/test_configuration.py b/tests/unit/test_configuration.py index 45a8c77..5e666f2 100644 --- a/tests/unit/test_configuration.py +++ b/tests/unit/test_configuration.py @@ -92,8 +92,7 @@ def test_load_configuration_files_value(caplog, conf, expected, has_warning): def test_load_configuration_files_value_from_file(caplog, mocker): with open( - pathlib.Path(__file__).parents[2] / "tests/test_data/config_file.ini", "r" - ) as f: + pathlib.Path(__file__).parents[2] / "tests/test_data/config_file.ini") as f: configuration.load_configuration_files(value=f)