Skip to content

Commit

Permalink
chore: Enable Ruff preview rules
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Apr 11, 2024
1 parent acf7b28 commit e52037a
Show file tree
Hide file tree
Showing 46 changed files with 183 additions and 149 deletions.
15 changes: 14 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,15 @@ target-version = "py38"
docstring-code-format = true

[tool.ruff.lint]
explicit-preview-rules = false
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
]
preview = true
select = [
"F", # Pyflakes
"E", # pycodestyle (error)
Expand Down Expand Up @@ -330,7 +332,18 @@ unfixable = [
"INP001", # flake8-no-pep420: implicit-namespace-package
]
"noxfile.py" = ["ANN"]
"tests/*" = ["ANN", "D1", "D2", "FBT001", "FBT003", "PLR2004", "S101", "SLF001"]
"tests/*" = [
"ANN",
"D1",
"D2",
"FBT001",
"FBT003",
"PLR2004",
"S101",
"SLF001",
"PLC2701", # Allow usage of private members in tests
"PLR6301", # Don't suggest making test methods static, etc.
]
# Disabled some checks in samples code
"samples/*" = ["ANN", "D"]
# Templates support a generic resource of type Any.
Expand Down
2 changes: 1 addition & 1 deletion samples/aapl/aapl.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AAPL(Stream):
name = "aapl"
schema_filepath = PROJECT_DIR / "fundamentals.json"

def get_records(self, _):
def get_records(self, _): # noqa: PLR6301
"""Generate a single record."""
with PROJECT_DIR.joinpath("AAPL.json").open() as f:
record = json.load(f)
Expand Down
2 changes: 1 addition & 1 deletion samples/sample_custom_sql_adapter/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions samples/sample_mapper/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

import typing as t

import singer_sdk._singerlib as singer
import singer_sdk._singerlib as singer # noqa: PLC2701
import singer_sdk.typing as th
from singer_sdk.helpers._util import utc_now
from singer_sdk.helpers._util import utc_now # noqa: PLC2701
from singer_sdk.mapper import PluginMapper, RemoveRecordTransform
from singer_sdk.mapper_base import InlineMapper

Expand Down Expand Up @@ -127,7 +127,7 @@ def map_record_message(
self.logger.info(stream_map.stream_alias)
yield record_message

def map_state_message(self, message_dict: dict) -> list[singer.Message]:
def map_state_message(self, message_dict: dict) -> list[singer.Message]: # noqa: PLR6301
"""Do nothing to the message.
Args:
Expand Down
4 changes: 2 additions & 2 deletions samples/sample_tap_bigquery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class BigQueryConnector(SQLConnector):
"""Connects to the BigQuery SQL source."""

def get_sqlalchemy_url(self, config: dict) -> str:
def get_sqlalchemy_url(self, config: dict) -> str: # noqa: PLR6301
"""Concatenate a SQLAlchemy URL for use in connecting to the source."""
return f"bigquery://{config['project_id']}"

Expand Down Expand Up @@ -59,4 +59,4 @@ class TapBigQuery(SQLTap):
default_stream_class: type[SQLStream] = BigQueryStream


__all__ = ["TapBigQuery", "BigQueryConnector", "BigQueryStream"]
__all__ = ["BigQueryConnector", "BigQueryStream", "TapBigQuery"]
8 changes: 7 additions & 1 deletion samples/sample_tap_countries/countries_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@
from __future__ import annotations

import abc
import sys

from singer_sdk import typing as th
from singer_sdk.helpers._compat import importlib_resources
from singer_sdk.streams.graphql import GraphQLStream

if sys.version_info < (3, 9):
import importlib_resources
else:
from importlib import resources as importlib_resources


SCHEMAS_DIR = importlib_resources.files(__package__) / "schemas"


Expand Down
11 changes: 9 additions & 2 deletions samples/sample_tap_gitlab/gitlab_graphql_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,16 @@

from __future__ import annotations

from singer_sdk.helpers._compat import importlib_resources
import sys

from singer_sdk.streams import GraphQLStream

if sys.version_info < (3, 9):
import importlib_resources
else:
from importlib import resources as importlib_resources


SITE_URL = "https://gitlab.com/graphql"

SCHEMAS_DIR = importlib_resources.files(__package__) / "schemas"
Expand Down Expand Up @@ -40,7 +47,7 @@ class GraphQLCurrentUserStream(GitlabGraphQLStream):
currentUser {
name
}
"""
""" # noqa: RUF027


class GraphQLProjectsStream(GitlabGraphQLStream):
Expand Down
12 changes: 9 additions & 3 deletions samples/sample_tap_gitlab/gitlab_rest_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

from __future__ import annotations

import sys
import typing as t

from singer_sdk.authenticators import SimpleAuthenticator
from singer_sdk.helpers._compat import importlib_resources
from singer_sdk.pagination import SimpleHeaderPaginator
from singer_sdk.streams.rest import RESTStream
from singer_sdk.typing import (
Expand All @@ -19,6 +19,12 @@
StringType,
)

if sys.version_info < (3, 9):
import importlib_resources
else:
from importlib import resources as importlib_resources


SCHEMAS_DIR = importlib_resources.files(__package__) / "schemas"

DEFAULT_URL_BASE = "https://gitlab.com/api/v4"
Expand Down Expand Up @@ -56,7 +62,7 @@ def get_url_params(
params["order_by"] = self.replication_key
return params

def get_new_paginator(self) -> SimpleHeaderPaginator:
def get_new_paginator(self) -> SimpleHeaderPaginator: # noqa: PLR6301
"""Return a new paginator for GitLab API endpoints.
Returns:
Expand Down Expand Up @@ -180,7 +186,7 @@ class EpicsStream(ProjectBasedStream):
),
).to_dict()

def get_child_context(
def get_child_context( # noqa: PLR6301
self,
record: dict,
context: dict | None, # noqa: ARG002
Expand Down
8 changes: 7 additions & 1 deletion samples/sample_tap_google_analytics/ga_tap_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@
from __future__ import annotations

import datetime
import sys
import typing as t

from singer_sdk.authenticators import OAuthJWTAuthenticator
from singer_sdk.helpers._compat import importlib_resources
from singer_sdk.streams import RESTStream

if sys.version_info < (3, 9):
import importlib_resources
else:
from importlib import resources as importlib_resources


GOOGLE_OAUTH_ENDPOINT = "https://oauth2.googleapis.com/token"
GA_OAUTH_SCOPES = "https://www.googleapis.com/auth/analytics.readonly"
SCHEMAS_DIR = importlib_resources.files(__package__) / "schemas"
Expand Down
4 changes: 2 additions & 2 deletions samples/sample_tap_sqlite/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class SQLiteConnector(SQLConnector):
This class handles all DDL and type conversions.
"""

def get_sqlalchemy_url(self, config: dict[str, t.Any]) -> str:
def get_sqlalchemy_url(self, config: dict[str, t.Any]) -> str: # noqa: PLR6301
"""Generates a SQLAlchemy URL for SQLite."""
return f"sqlite:///{config[DB_PATH_CONFIG]}"

Expand Down Expand Up @@ -55,4 +55,4 @@ class SQLiteTap(SQLTap):
).to_dict()


__all__ = ["SQLiteTap", "SQLiteConnector", "SQLiteStream"]
__all__ = ["SQLiteConnector", "SQLiteStream", "SQLiteTap"]
2 changes: 1 addition & 1 deletion samples/sample_target_parquet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
from samples.sample_target_parquet.parquet_target_sink import SampleParquetTargetSink

__all__ = [
"SampleTargetParquet",
"SampleParquetTargetSink",
"SampleTargetParquet",
]
4 changes: 2 additions & 2 deletions samples/sample_target_sqlite/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class SQLiteConnector(SQLConnector):
allow_merge_upsert = True
allow_overwrite: bool = True

def get_sqlalchemy_url(self, config: dict[str, t.Any]) -> str:
def get_sqlalchemy_url(self, config: dict[str, t.Any]) -> str: # noqa: PLR6301
"""Generates a SQLAlchemy URL for SQLite."""
return f"sqlite:///{config[DB_PATH_CONFIG]}"

Expand Down Expand Up @@ -57,4 +57,4 @@ class SQLiteTarget(SQLTarget):
).to_dict()


__all__ = ["SQLiteTarget", "SQLiteConnector", "SQLiteSink"]
__all__ = ["SQLiteConnector", "SQLiteSink", "SQLiteTarget"]
6 changes: 3 additions & 3 deletions singer_sdk/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@
"GraphQLStream",
"InlineMapper",
"PluginBase",
"RecordSink",
"RESTStream",
"Sink",
"RecordSink",
"SQLConnector",
"SQLSink",
"SQLStream",
"SQLTap",
"SQLTarget",
"Sink",
"Stream",
"streams",
"Tap",
"Target",
"streams",
]
12 changes: 6 additions & 6 deletions singer_sdk/_singerlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,22 @@
from singer_sdk._singerlib.utils import strftime, strptime_to_utc

__all__ = [
"ActivateVersionMessage",
"Catalog",
"CatalogEntry",
"Message",
"Metadata",
"MetadataMapping",
"SelectionMask",
"StreamMetadata",
"ActivateVersionMessage",
"Message",
"RecordMessage",
"Schema",
"SchemaMessage",
"SelectionMask",
"SingerMessageType",
"StateMessage",
"StreamMetadata",
"exclude_null_dict",
"write_message",
"Schema",
"resolve_schema_references",
"strftime",
"strptime_to_utc",
"write_message",
]
6 changes: 2 additions & 4 deletions singer_sdk/_singerlib/catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,8 @@ def get_standard_metadata(
root.schema_name = schema_name

for field_name in schema.get("properties", {}):
if (
key_properties
and field_name in key_properties
or (valid_replication_keys and field_name in valid_replication_keys)
if (key_properties and field_name in key_properties) or (
valid_replication_keys and field_name in valid_replication_keys
):
entry = Metadata(inclusion=Metadata.InclusionType.AUTOMATIC)
else:
Expand Down
4 changes: 2 additions & 2 deletions singer_sdk/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
from singer_sdk.helpers.capabilities import CapabilitiesEnum

__all__ = [
"AboutInfo",
"AboutFormatter",
"AboutInfo",
"JSONFormatter",
"MarkdownFormatter",
]
Expand Down Expand Up @@ -109,7 +109,7 @@ def format_about(self, about_info: AboutInfo) -> str:
class TextFormatter(AboutFormatter, format_name="text"):
"""About formatter for text output."""

def format_about(self, about_info: AboutInfo) -> str:
def format_about(self, about_info: AboutInfo) -> str: # noqa: PLR6301
"""Render about information.
Args:
Expand Down
8 changes: 4 additions & 4 deletions singer_sdk/authenticators.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,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)

Expand Down Expand Up @@ -572,9 +572,9 @@ def oauth_request_payload(self) -> dict:
Raises:
ValueError: If the private key is not set.
"""
import jwt
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import serialization
import jwt # noqa: PLC0415
from cryptography.hazmat.backends import default_backend # noqa: PLC0415
from cryptography.hazmat.primitives import serialization # noqa: PLC0415

if not self.private_key:
msg = "Missing 'private_key' property for OAuth payload."
Expand Down
2 changes: 1 addition & 1 deletion singer_sdk/batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ 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 JSONLinesBatcher # noqa: PLC0415, I001

return JSONLinesBatcher

Expand Down

0 comments on commit e52037a

Please sign in to comment.