diff --git a/.github/workflows/pull-request.yaml b/.github/workflows/pull-request.yaml index c6b6e83..ca9c00c 100644 --- a/.github/workflows/pull-request.yaml +++ b/.github/workflows/pull-request.yaml @@ -23,7 +23,7 @@ jobs: - windows-latest - macos-latest python-version: - - "3.9" + - "3.10" - "3.12" steps: - name: Checkout diff --git a/pyproject.toml b/pyproject.toml index f78f320..1207575 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -94,9 +94,20 @@ requires = ["poetry-core>=1.3.0"] [tool.ruff] fix = true -lint.ignore = [ - # Line length — black handles - "E5", # - # No lambdas — too strict - "E731", +[tool.ruff.lint] +# E402: module level import not at top of file +# E501: line too long - let black worry about that +# E731: do not assign a lambda expression, use a def +extend-safe-fixes = [ + "TID252", # absolute imports +] +ignore = ["E402", "E501", "E731", "UP007"] +extend-select = [ + "B", # flake8-bugbear + "F", # Pyflakes + "E", # Pycodestyle + "W", + "TID", # flake8-tidy-imports (absolute imports) + "I", # isort + "UP", # Pyupgrade ] diff --git a/pyprql/magic/prql.py b/pyprql/magic/prql.py index 7e97584..f6afc5b 100644 --- a/pyprql/magic/prql.py +++ b/pyprql/magic/prql.py @@ -2,13 +2,14 @@ from __future__ import annotations +import re + from IPython.core.magic import cell_magic, line_magic, magics_class, needs_local_scope from IPython.core.magic_arguments import argument, magic_arguments, parse_argstring -from prqlc import compile, CompileOptions +from prqlc import CompileOptions, compile from sql.magic import SqlMagic from sql.parse import parse from traitlets import Bool, Unicode -import re @magics_class @@ -110,7 +111,7 @@ def prql( _pattern = re.sub(r"\\\s", r"\\s+", _escaped_prql) line = re.sub(_pattern, "", line) if self.args.file: - with open(self.args.file, "r") as infile: + with open(self.args.file) as infile: cell = infile.read() line = re.sub(r"(\-f|\-\-file)\s+" + self.args.file, "", line) # If cell is occupied, parsed to SQL diff --git a/pyprql/polars_namespace/prql.py b/pyprql/polars_namespace/prql.py index 4b0c1c0..e7a34ae 100644 --- a/pyprql/polars_namespace/prql.py +++ b/pyprql/polars_namespace/prql.py @@ -1,9 +1,9 @@ from __future__ import annotations -import polars as pl -import prqlc -from typing import TypeVar, Generic +from typing import Generic, TypeVar +import polars as pl +import prqlc T_DF = TypeVar("T_DF", pl.DataFrame, pl.LazyFrame) @@ -12,7 +12,7 @@ @pl.api.register_lazyframe_namespace("prql") class PrqlNamespace(Generic[T_DF]): def __init__(self, df: T_DF): - self._df = df + self._df: T_DF = df def query(self, prql_query: str, *, table_name: str | None = None) -> T_DF: prepended_query: str = f"from self \n {prql_query}" diff --git a/pyprql/tests/__init__.py b/pyprql/tests/__init__.py index 36acc02..96a803a 100644 --- a/pyprql/tests/__init__.py +++ b/pyprql/tests/__init__.py @@ -8,7 +8,7 @@ def run_sql(ip_session: "IPython.core.interactiveshell.InteractiveShell", statem if isinstance(statements, str): statements = [statements] for statement in statements: - result = ip_session.run_line_magic("sql", "sqlite:// %s" % statement) + result = ip_session.run_line_magic("sql", f"sqlite:// {statement}") return result # returns only last result @@ -16,5 +16,5 @@ def run_prql(ip_session: "IPython.core.interactiveshell.InteractiveShell", state if isinstance(statements, str): statements = [statements] for statement in statements: - result = ip_session.run_line_magic("prql", "sqlite:// %s" % statement) + result = ip_session.run_line_magic("prql", f"sqlite:// {statement}") return result # returns only last result diff --git a/pyprql/tests/conftest.py b/pyprql/tests/conftest.py index 78b3151..c2f6f80 100644 --- a/pyprql/tests/conftest.py +++ b/pyprql/tests/conftest.py @@ -3,8 +3,7 @@ from pathlib import Path import pytest -from sql import connection -from sql import _current +from sql import _current, connection from sql._testing import TestingShell from sql.connection import ConnectionManager from sql.magic import RenderMagic, SqlMagic