Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Enable Ruff preview rules
Browse files Browse the repository at this point in the history
edgarrmondragon committed Dec 5, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 4e82c65 commit 16f0d37
Showing 29 changed files with 44 additions and 53 deletions.
14 changes: 9 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -234,6 +234,7 @@ parquet = "singer_sdk.contrib.batch_encoder_parquet:ParquetBatcher"

[tool.ruff]
line-length = 88
preview = true
src = ["samples", "singer_sdk", "tests"]
target-version = "py37"

@@ -243,11 +244,12 @@ exclude = [
"*simpleeval*",
]
ignore = [
"ANN101", # Missing type annotation for `self` in method
"ANN102", # Missing type annotation for `cls` in class method
"N818", # Exception name should be named with an Error suffix
"COM812", # missing-trailing-comma
"ISC001", # single-line-implicit-string-concatenation
"ANN101", # Missing type annotation for `self` in method
"ANN102", # Missing type annotation for `cls` in class method
"N818", # Exception name should be named with an Error suffix
"COM812", # missing-trailing-comma
"ISC001", # single-line-implicit-string-concatenation
"PLR6301", # Method {method_name} could be a function, class method, or static method
]
select = [
"F", # Pyflakes
@@ -294,6 +296,8 @@ select = [
"PLR", # pylint (refactor)
"PLW", # pylint (warning)
"PERF", # perflint
"FURB", # refurb
"LOG", # flake8-logging
"RUF", # ruff
]
unfixable = [
2 changes: 1 addition & 1 deletion samples/sample_custom_sql_adapter/connector.py
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ def __init__(self, *args, **kwargs):
@classmethod
def import_dbapi(cls):
"""Import the sqlite3 DBAPI."""
import sqlite3
import sqlite3 # noqa: PLC0415

return sqlite3

1 change: 0 additions & 1 deletion samples/sample_target_parquet/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Module test for target-parquet functionality."""


from __future__ import annotations

# Reuse the tap connection rather than create a new target connection:
1 change: 0 additions & 1 deletion singer_sdk/about.py
Original file line number Diff line number Diff line change
@@ -68,7 +68,6 @@ def format_about(self, about_info: AboutInfo) -> str:
Args:
about_info: About information.
"""
...


class TextFormatter(AboutFormatter, format_name="text"):
2 changes: 1 addition & 1 deletion singer_sdk/authenticators.py
Original file line number Diff line number Diff line change
@@ -223,7 +223,7 @@ def __init__(
super().__init__(stream=stream)
auth_credentials = {key: value}

if location not in ["header", "params"]:
if location not in {"header", "params"}:
msg = "`type` must be one of 'header' or 'params'."
raise ValueError(msg)

5 changes: 4 additions & 1 deletion singer_sdk/batch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Batching utilities for Singer SDK."""

from __future__ import annotations

import itertools
@@ -22,7 +23,9 @@ def __getattr__(name: str) -> t.Any: # noqa: ANN401 # pragma: no cover
stacklevel=2,
)

from singer_sdk.contrib.batch_encoder_jsonl import JSONLinesBatcher
from singer_sdk.contrib.batch_encoder_jsonl import ( # noqa: PLC0415
JSONLinesBatcher,
)

return JSONLinesBatcher

2 changes: 1 addition & 1 deletion singer_sdk/connectors/sql.py
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@
from sqlalchemy.engine.reflection import Inspector


class SQLConnector:
class SQLConnector: # noqa: PLR0904
"""Base class for SQLAlchemy-based connectors.
The connector class serves as a wrapper around the SQL connection.
4 changes: 2 additions & 2 deletions singer_sdk/contrib/batch_encoder_parquet.py
Original file line number Diff line number Diff line change
@@ -25,8 +25,8 @@ def get_batches(
Yields:
A list of file paths (called a manifest).
"""
import pyarrow as pa
import pyarrow.parquet as pq
import pyarrow as pa # noqa: PLC0415
import pyarrow.parquet as pq # noqa: PLC0415

sync_id = f"{self.tap_name}--{self.stream_name}-{uuid4()}"
prefix = self.batch_config.storage.prefix or ""
1 change: 1 addition & 0 deletions singer_sdk/helpers/_conformers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Helper functions for conforming identifiers."""

from __future__ import annotations

import re
2 changes: 1 addition & 1 deletion singer_sdk/helpers/_flattening.py
Original file line number Diff line number Diff line change
@@ -33,7 +33,7 @@ def get_flattening_options(
Returns:
A new FlatteningOptions object or None if flattening is disabled.
"""
if "flattening_enabled" in plugin_config and plugin_config["flattening_enabled"]:
if plugin_config.get("flattening_enabled"):
return FlatteningOptions(max_level=int(plugin_config["flattening_max_depth"]))

return None
15 changes: 5 additions & 10 deletions singer_sdk/io_base.py
Original file line number Diff line number Diff line change
@@ -111,24 +111,19 @@ def _process_lines(self, file_input: t.IO[str]) -> t.Counter[str]:
return Counter(**stats)

@abc.abstractmethod
def _process_schema_message(self, message_dict: dict) -> None:
...
def _process_schema_message(self, message_dict: dict) -> None: ...

@abc.abstractmethod
def _process_record_message(self, message_dict: dict) -> None:
...
def _process_record_message(self, message_dict: dict) -> None: ...

@abc.abstractmethod
def _process_state_message(self, message_dict: dict) -> None:
...
def _process_state_message(self, message_dict: dict) -> None: ...

@abc.abstractmethod
def _process_activate_version_message(self, message_dict: dict) -> None:
...
def _process_activate_version_message(self, message_dict: dict) -> None: ...

@abc.abstractmethod
def _process_batch_message(self, message_dict: dict) -> None:
...
def _process_batch_message(self, message_dict: dict) -> None: ...

def _process_unknown_message(self, message_dict: dict) -> None:
"""Internal method to process unknown message types from a Singer tap.
4 changes: 0 additions & 4 deletions singer_sdk/mapper_base.py
Original file line number Diff line number Diff line change
@@ -56,7 +56,6 @@ def map_schema_message(self, message_dict: dict) -> t.Iterable[singer.Message]:
Args:
message_dict: A SCHEMA message JSON dictionary.
"""
...

@abc.abstractmethod
def map_record_message(self, message_dict: dict) -> t.Iterable[singer.Message]:
@@ -65,7 +64,6 @@ def map_record_message(self, message_dict: dict) -> t.Iterable[singer.Message]:
Args:
message_dict: A RECORD message JSON dictionary.
"""
...

@abc.abstractmethod
def map_state_message(self, message_dict: dict) -> t.Iterable[singer.Message]:
@@ -74,7 +72,6 @@ def map_state_message(self, message_dict: dict) -> t.Iterable[singer.Message]:
Args:
message_dict: A STATE message JSON dictionary.
"""
...

@abc.abstractmethod
def map_activate_version_message(
@@ -86,7 +83,6 @@ def map_activate_version_message(
Args:
message_dict: An ACTIVATE_VERSION message JSON dictionary.
"""
...

def map_batch_message(
self,
2 changes: 0 additions & 2 deletions singer_sdk/metrics.py
Original file line number Diff line number Diff line change
@@ -138,7 +138,6 @@ def context(self, value: dict | None) -> None:
@abc.abstractmethod
def __enter__(self) -> Meter:
"""Enter the meter context."""
...

@abc.abstractmethod
def __exit__(
@@ -154,7 +153,6 @@ def __exit__(
exc_val: The exception value.
exc_tb: The exception traceback.
"""
...


class Counter(Meter):
5 changes: 0 additions & 5 deletions singer_sdk/pagination.py
Original file line number Diff line number Diff line change
@@ -146,7 +146,6 @@ def get_next(self, response: Response) -> TPageToken | None:
The next page token or index. Return `None` from this method to indicate
the end of pagination.
"""
...


class SinglePagePaginator(BaseAPIPaginator[None]):
@@ -234,7 +233,6 @@ def get_next_url(self, response: Response) -> str | None:
Args:
response: API response object.
"""
...

def get_next(self, response: Response) -> ParseResult | None:
"""Get the next pagination token or index from the API response.
@@ -347,7 +345,6 @@ def has_more(self, response: Response) -> bool:
Boolean flag used to indicate if the endpoint has more pages.
"""
...

def get_next(self, response: Response) -> int | None: # noqa: ARG002
"""Get the next page number.
@@ -392,7 +389,6 @@ def has_more(self, response: Response) -> bool:
Returns:
Boolean flag used to indicate if the endpoint has more pages.
"""
...

def get_next(self, response: Response) -> int | None: # noqa: ARG002
"""Get the next page offset.
@@ -420,7 +416,6 @@ def get_next_page_token(
response: API response object.
previous_token: Previous page token.
"""
... # pragma: no cover


class LegacyStreamPaginator(
2 changes: 1 addition & 1 deletion singer_sdk/plugin_base.py
Original file line number Diff line number Diff line change
@@ -109,7 +109,7 @@ def invoke(self, ctx: click.Context) -> t.Any: # noqa: ANN401
sys.exit(1)


class PluginBase(metaclass=abc.ABCMeta):
class PluginBase(metaclass=abc.ABCMeta): # noqa: PLR0904
"""Abstract base class for taps."""

#: The executable name of the tap or target plugin. e.g. tap-foo
4 changes: 2 additions & 2 deletions singer_sdk/sinks/core.py
Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@
JSONSchemaValidator = Draft7Validator


class Sink(metaclass=abc.ABCMeta):
class Sink(metaclass=abc.ABCMeta): # noqa: PLR0904
"""Abstract base class for target sinks."""

# max timestamp/datetime supported, used to reset invalid dates
@@ -550,7 +550,7 @@ def process_batch_files(
importlib.util.find_spec("pyarrow")
and encoding.format == BatchFileFormat.PARQUET
):
import pyarrow.parquet as pq
import pyarrow.parquet as pq # noqa: PLC0415

with storage.fs(create=False) as batch_fs, batch_fs.open(
tail,
2 changes: 1 addition & 1 deletion singer_sdk/streams/core.py
Original file line number Diff line number Diff line change
@@ -64,7 +64,7 @@
FactoryType = t.TypeVar("FactoryType", bound="Stream")


class Stream(metaclass=abc.ABCMeta):
class Stream(metaclass=abc.ABCMeta): # noqa: PLR0904
"""Abstract base class for tap streams."""

STATE_MSG_FREQUENCY = 10000
4 changes: 2 additions & 2 deletions singer_sdk/streams/rest.py
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@
_Auth: TypeAlias = t.Callable[[requests.PreparedRequest], requests.PreparedRequest]


class RESTStream(Stream, t.Generic[_TToken], metaclass=abc.ABCMeta):
class RESTStream(Stream, t.Generic[_TToken], metaclass=abc.ABCMeta): # noqa: PLR0904
"""Abstract base class for REST API streams."""

_page_size: int = DEFAULT_PAGE_SIZE
@@ -99,7 +99,7 @@ def __init__(
self._next_page_token_compiled_jsonpath = None

@staticmethod
def _url_encode(val: str | datetime | bool | int | list[str]) -> str:
def _url_encode(val: str | datetime | bool | int | list[str]) -> str: # noqa: FBT001
"""Encode the val argument as url-compatible string.
Args:
3 changes: 1 addition & 2 deletions singer_sdk/tap_base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Tap abstract class."""


from __future__ import annotations

import abc
@@ -46,7 +45,7 @@ class CliTestOptionValue(Enum):
Disabled = "disabled"


class Tap(PluginBase, SingerWriter, metaclass=abc.ABCMeta):
class Tap(PluginBase, SingerWriter, metaclass=abc.ABCMeta): # noqa: PLR0904
"""Abstract base class for taps.
The Tap class governs configuration, validation, and stream discovery for tap
4 changes: 2 additions & 2 deletions singer_sdk/testing/__init__.py
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ def __getattr__(name: str) -> t.Any: # noqa: ANN401
stacklevel=2,
)

from .legacy import get_standard_tap_tests
from .legacy import get_standard_tap_tests # noqa: PLC0415

return get_standard_tap_tests

@@ -40,7 +40,7 @@ def __getattr__(name: str) -> t.Any: # noqa: ANN401
stacklevel=2,
)

from .legacy import get_standard_target_tests
from .legacy import get_standard_target_tests # noqa: PLC0415

return get_standard_target_tests

1 change: 1 addition & 0 deletions singer_sdk/testing/factory.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test Class Factory."""

from __future__ import annotations

import typing as t
2 changes: 1 addition & 1 deletion singer_sdk/testing/runners.py
Original file line number Diff line number Diff line change
@@ -149,7 +149,7 @@ def sync_all(self, **kwargs: t.Any) -> None: # noqa: ARG002
Args:
kwargs: Unused keyword arguments.
"""
stdout, stderr = self._execute_sync()
stdout, _stderr = self._execute_sync()
messages = self._clean_sync_output(stdout)
self._parse_records(messages)

2 changes: 1 addition & 1 deletion singer_sdk/typing.py
Original file line number Diff line number Diff line change
@@ -524,7 +524,7 @@ def __init__(
required: bool = False, # noqa: FBT001, FBT002
default: T | None = None,
description: str | None = None,
secret: bool | None = False, # noqa: FBT002
secret: bool | None = False, # noqa: FBT002, FBT001
allowed_values: list[T] | None = None,
examples: list[T] | None = None,
) -> None:
2 changes: 1 addition & 1 deletion tests/core/test_connector_sql.py
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ def stringify(in_dict):
return {k: str(v) for k, v in in_dict.items()}


class TestConnectorSQL:
class TestConnectorSQL: # noqa: PLR0904
"""Test the SQLConnector class."""

@pytest.fixture
1 change: 0 additions & 1 deletion tests/core/test_plugin_config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Test plugin config functions."""


from __future__ import annotations

import typing as t
6 changes: 3 additions & 3 deletions tests/core/test_testing.py
Original file line number Diff line number Diff line change
@@ -9,12 +9,12 @@

def test_module_deprecations():
with pytest.deprecated_call():
from singer_sdk.testing import get_standard_tap_tests # noqa: F401
from singer_sdk.testing import get_standard_tap_tests # noqa: F401, PLC0415

with pytest.deprecated_call():
from singer_sdk.testing import get_standard_target_tests # noqa: F401
from singer_sdk.testing import get_standard_target_tests # noqa: F401, PLC0415

from singer_sdk import testing
from singer_sdk import testing # noqa: PLC0415

with pytest.raises(
AttributeError,
2 changes: 1 addition & 1 deletion tests/samples/test_tap_sqlite.py
Original file line number Diff line number Diff line change
@@ -116,7 +116,7 @@ def test_sqlite_tap_standard_tests(sqlite_sample_tap: SQLTap):

def test_sync_sqlite_to_csv(sqlite_sample_tap: SQLTap, tmp_path: Path):
_discover_and_select_all(sqlite_sample_tap)
orig_stdout, _, _, _ = tap_to_target_sync_test(
_orig_stdout, _, _, _ = tap_to_target_sync_test(
sqlite_sample_tap,
SampleTargetCSV(config={"target_folder": f"{tmp_path}/"}),
)
1 change: 1 addition & 0 deletions tests/samples/test_target_csv.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test tap-to-target sync."""

from __future__ import annotations

import datetime
1 change: 1 addition & 0 deletions tests/samples/test_target_parquet.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test class creation."""

from __future__ import annotations

import shutil

0 comments on commit 16f0d37

Please sign in to comment.