From 171971e03c58603e8210d43f3dd6615ae52d3984 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 25 Dec 2023 19:35:35 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- septentrion/cli.py | 2 +- septentrion/configuration.py | 2 +- septentrion/core.py | 2 -- septentrion/db.py | 3 +-- septentrion/files.py | 5 +---- septentrion/metadata.py | 1 - septentrion/migration.py | 5 +---- septentrion/runner.py | 1 - septentrion/style.py | 2 +- septentrion/versions.py | 1 - tests/acceptance/test_core.py | 2 -- tests/acceptance/test_lib.py | 1 - tests/integration/test_runner.py | 4 ++-- tests/unit/test_configuration.py | 3 +-- 14 files changed, 9 insertions(+), 25 deletions(-) diff --git a/septentrion/cli.py b/septentrion/cli.py index 043510e..b86de92 100644 --- a/septentrion/cli.py +++ b/septentrion/cli.py @@ -60,7 +60,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..ecc901f 100644 --- a/septentrion/configuration.py +++ b/septentrion/configuration.py @@ -68,7 +68,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..16a737d 100644 --- a/septentrion/core.py +++ b/septentrion/core.py @@ -184,7 +184,6 @@ def build_migration_plan( def describe_migration_plan( settings: configuration.Settings, stylist: style.Stylist = style.noop_stylist ) -> None: - if not db.is_schema_initialized(settings=settings): from_version = get_best_schema_version(settings=settings) with stylist.activate("title") as echo: @@ -212,7 +211,6 @@ def describe_migration_plan( echo("Version {}".format(version)) for migration_elem in migrations: - name, applied, path, is_manual = migration_elem stylist.draw_checkbox(name, checked=applied) stylist.echo() diff --git a/septentrion/db.py b/septentrion/db.py index fe7fd89..3c4a89d 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, @@ -153,7 +153,6 @@ def get_applied_migrations( def is_schema_initialized(settings: configuration.Settings) -> bool: - try: with Query(settings=settings, query=query_is_schema_initialized) as cur: try: diff --git a/septentrion/files.py b/septentrion/files.py index 49c41ad..4470d63 100644 --- a/septentrion/files.py +++ b/septentrion/files.py @@ -47,7 +47,6 @@ def get_known_versions(settings: configuration.Settings) -> List[versions.Versio def is_manual_migration( migration_path: pathlib.Path, migration_contents: Iterable[str] ) -> bool: - if "manual" in migration_path.parts: return True @@ -100,7 +99,6 @@ def get_migrations_files_mapping( def list_migrations_and_paths( folder: pathlib.Path, ignore_symlinks: bool ) -> Iterable[Tuple[str, pathlib.Path]]: - for file in iter_files(root=folder, ignore_symlinks=ignore_symlinks): if not file.suffix == ".sql" or not file.stem[-3:] in ("ddl", "dml"): continue @@ -110,5 +108,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/metadata.py b/septentrion/metadata.py index b66c2d5..1b0aeb8 100644 --- a/septentrion/metadata.py +++ b/septentrion/metadata.py @@ -4,7 +4,6 @@ def extract_metadata(package_name: str) -> Mapping[str, str]: - # Backport of Python 3.8's future importlib.metadata() try: metadata = importlib_metadata.metadata(package_name) diff --git a/septentrion/migration.py b/septentrion/migration.py index b3580b1..dfa0e19 100644 --- a/septentrion/migration.py +++ b/septentrion/migration.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- import io import logging import pathlib @@ -23,7 +22,6 @@ def migrate( settings: configuration.Settings, stylist: style.Stylist = style.noop_stylist ) -> None: - logger.info("Starting migrations") if not db.is_schema_initialized(settings=settings): @@ -141,7 +139,6 @@ def init_schema( content="Applying {}...".format(init_version), content_after="Applied {}".format(init_version), ): - run_script(settings=settings, path=schema_path) create_fake_entries(settings=settings, version=init_version) @@ -192,6 +189,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/runner.py b/septentrion/runner.py index 1a65fd8..ecb57bc 100644 --- a/septentrion/runner.py +++ b/septentrion/runner.py @@ -41,7 +41,6 @@ def _env(self): return {key: str(value) for key, value in environment.items() if value} def _run_simple(self): - try: cmd = subprocess.run( ["psql", "--set", "ON_ERROR_STOP=on", "-f", str(self.path)], 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/septentrion/versions.py b/septentrion/versions.py index e5bdc2a..9eae022 100644 --- a/septentrion/versions.py +++ b/septentrion/versions.py @@ -5,7 +5,6 @@ @dataclasses.dataclass(order=True, unsafe_hash=True, frozen=True) class Version: - version_tuple: tuple = dataclasses.field(compare=True) original_string: str = dataclasses.field(compare=False) diff --git a/tests/acceptance/test_core.py b/tests/acceptance/test_core.py index 7eed25a..2ce72e7 100644 --- a/tests/acceptance/test_core.py +++ b/tests/acceptance/test_core.py @@ -2,7 +2,6 @@ def test_initialize(db): - settings_kwargs = { # database connection settings "host": db["host"], @@ -21,7 +20,6 @@ def test_initialize(db): def test_initialize_customize_names(db): - settings_kwargs = { # database connection settings "host": db["host"], diff --git a/tests/acceptance/test_lib.py b/tests/acceptance/test_lib.py index 59d33e9..1f6889f 100644 --- a/tests/acceptance/test_lib.py +++ b/tests/acceptance/test_lib.py @@ -4,7 +4,6 @@ def test_migrate(db): - settings_kwargs = { # database connection settings "host": db["host"], 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)