diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5cf7b8e..a2da1cc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -32,17 +32,17 @@ repos: args: ["--py310-plus"] - repo: "https://github.com/sirosen/slyp" - rev: "0.8.2" + rev: "0.9.0" hooks: - id: "slyp" - repo: "https://github.com/psf/black-pre-commit-mirror" - rev: "25.12.0" + rev: "26.5.1" hooks: - id: "black" - repo: "https://github.com/pycqa/isort" - rev: "7.0.0" + rev: "9.0.0a3" hooks: - id: "isort" @@ -55,18 +55,18 @@ repos: - "flake8-bugbear==25.11.29" - repo: "https://github.com/editorconfig-checker/editorconfig-checker" - rev: "v3.6.0" + rev: "v3.8.0" hooks: - id: "editorconfig-checker" - repo: "https://github.com/python-jsonschema/check-jsonschema" - rev: "0.36.0" + rev: "0.37.4" hooks: - id: "check-dependabot" - id: "check-readthedocs" - repo: "https://github.com/rhysd/actionlint" - rev: "v1.7.9" + rev: "v1.7.12" hooks: - id: "actionlint" additional_dependencies: @@ -86,6 +86,6 @@ repos: ] - repo: "https://github.com/zizmorcore/zizmor-pre-commit" - rev: "v1.18.0" + rev: "v1.26.1" hooks: - id: "zizmor" diff --git a/docs/ruff/assets/F401/example.py b/docs/ruff/assets/F401/example.py index 9861f8d..d95e1aa 100644 --- a/docs/ruff/assets/F401/example.py +++ b/docs/ruff/assets/F401/example.py @@ -6,7 +6,6 @@ import boto3 import requests - # Hidden from rendering in the docs. # # This list does not include 'sqliteimport', above, diff --git a/src/sqliteimport/accessor.py b/src/sqliteimport/accessor.py index 66557fc..05a88b3 100644 --- a/src/sqliteimport/accessor.py +++ b/src/sqliteimport/accessor.py @@ -41,8 +41,7 @@ def get_tables(self) -> list[str]: def initialize_database(self) -> None: """Create database tables and insert basic information about the database.""" - self.connection.executescript( - """ + self.connection.executescript(""" CREATE TABLE sqliteimport ( field TEXT, value TEXT @@ -67,8 +66,7 @@ def initialize_database(self) -> None: magic_number INTEGER, python_identifier TEXT ); - """ - ) + """) @staticmethod def get_database_path(database: sqlite3.Connection) -> str: @@ -84,16 +82,14 @@ def get_database_path(database: sqlite3.Connection) -> str: def get_magic_numbers(self) -> dict[int, str]: """Get the magic numbers of the already-compiled bytecodes in the database.""" - magic_numbers = self.connection.execute( - """ + magic_numbers = self.connection.execute(""" SELECT magic_number, python_identifier FROM magic_numbers ; - """ - ).fetchall() + """).fetchall() return {row[0]: row[1] for row in magic_numbers} def add_directory(self, directory: pathlib.Path) -> None: @@ -154,8 +150,7 @@ def create_bytecode_table(self, magic_number: int) -> None: """Create a compiled bytecode table.""" table_name = self.get_bytecode_table_name(magic_number) - self.connection.executescript( - f""" + self.connection.executescript(f""" CREATE TABLE {table_name} ( fullname TEXT, @@ -165,8 +160,7 @@ def create_bytecode_table(self, magic_number: int) -> None: ); CREATE INDEX {table_name}_fullname_index ON {table_name} (fullname); - """ - ) + """) def add_bytecode( self, magic_number: int, fullname: str, path: str, is_package: bool, code: bytes @@ -361,8 +355,7 @@ def list_directory(self, path_like: str) -> list[str]: def iter_source_code(self) -> typing.Generator[tuple[str, str, bool, bytes]]: cursor = self.connection.cursor() - iterable = cursor.execute( - """ + iterable = cursor.execute(""" SELECT fullname, path, @@ -371,8 +364,7 @@ def iter_source_code(self) -> typing.Generator[tuple[str, str, bool, bytes]]: FROM code WHERE path LIKE '%.py' ; - """ - ) + """) row: tuple[str, str, bool, bytes] for row in iterable: fullname, path, is_package, contents = row @@ -382,15 +374,13 @@ def iter_package_metadata(self) -> typing.Generator[bytes]: """Find and return all METADATA files in `.dist-info/` directories.""" cursor = self.connection.cursor() - iterable = cursor.execute( - """ + iterable = cursor.execute(""" SELECT contents FROM code WHERE path LIKE '%.dist-info/METADATA' ; - """ - ) + """) row: tuple[bytes] for row in iterable: contents = row[0] diff --git a/src/sqliteimport/cli.py b/src/sqliteimport/cli.py index f53d90d..29b7d89 100644 --- a/src/sqliteimport/cli.py +++ b/src/sqliteimport/cli.py @@ -175,21 +175,18 @@ def describe(database: pathlib.Path) -> None: type=click.Path( exists=True, dir_okay=False, file_okay=True, path_type=pathlib.Path ), - help=( - """ + help=(""" The Python code file to inject sqliteimport and the `--database` of packages into. The target file WILL NOT be overwritten by default; it can only be overwritten if it is specified again as the `--output-file`. - """ - ), + """), ) @click.option( "--marker", default=DEFAULT_MARKER, - help=( - f""" + help=(f""" The marker to search for in the `--target-file`. The marker must exist in the `--target-file`, @@ -200,29 +197,24 @@ def describe(database: pathlib.Path) -> None: \b # {DEFAULT_MARKER} \b - """ - ), + """), ) @click.option( "--output-file", type=click.Path(dir_okay=False, file_okay=True, path_type=pathlib.Path), - help=( - """ + help=(""" The output file to write, containing the code of the `--target-file` combined with the sqliteimport source code and database of dependencies. - """ - ), + """), ) @click.option( "--overwrite", is_flag=True, - help=( - """ + help=(""" If set, the `--output-file` will be overwritten if it exists. By default, the `--output-file` will never be overwritten. - """ - ), + """), ) def inject( database: pathlib.Path, diff --git a/src/sqliteimport/injector.py b/src/sqliteimport/injector.py index 305cd66..c62b5b6 100644 --- a/src/sqliteimport/injector.py +++ b/src/sqliteimport/injector.py @@ -8,14 +8,12 @@ def generate_prologue(database_path: pathlib.Path) -> str: - header = textwrap.dedent( - """\ + header = textwrap.dedent("""\ # The code in this block was generated by sqliteimport. # https://github.com/kurtmckee/sqliteimport # Copyright Kurt McKee # SPDX-License-Identifier: MIT - """ - ).rstrip() + """).rstrip() lines: list[str] = [header] # Add code variables. @@ -39,8 +37,7 @@ def generate_prologue(database_path: pathlib.Path) -> str: continue lines.append(line) - wrapper = textwrap.dedent( - """ + wrapper = textwrap.dedent(""" # BEGIN GENERATED CODE BLOCK. DO NOT EDIT! def __sqliteimport_setup(database: bytes) -> None: {function_block} @@ -49,8 +46,7 @@ def __sqliteimport_setup(database: bytes) -> None: del __sqliteimport_database del __sqliteimport_setup # END GENERATED CODE BLOCK. - """ - ) + """) function_block = textwrap.indent("\n".join(lines), " ") database = database_path.read_bytes() return wrapper.format(function_block=function_block, database=database)