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 8e94e48
Show file tree
Hide file tree
Showing 46 changed files with 214 additions and 204 deletions.
101 changes: 45 additions & 56 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@ readme = "README.md"
homepage = "https://sdk.meltano.com/en/latest/"
repository = "https://github.com/meltano/sdk"
documentation = "https://sdk.meltano.com/en/latest/"
keywords = [
"Meltano",
"Singer",
"Meltano SDK",
"Singer SDK",
"ELT",
]
keywords = ["Meltano", "Singer", "Meltano SDK", "Singer SDK", "ELT"]
classifiers = [
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
Expand Down Expand Up @@ -44,8 +38,8 @@ backports-datetime-fromisoformat = { version = ">=2.0.1", python = "<3.11" }
click = "~=8.0"
cryptography = ">=3.4.6"
fs = ">=2.4.16"
importlib-metadata = {version = "<8.0.0", python = "<3.12"}
importlib-resources = {version = ">=5.12.0,!=6.2.0,!=6.3.0,!=6.3.1", python = "<3.9"}
importlib-metadata = { version = "<8.0.0", python = "<3.12" }
importlib-resources = { version = ">=5.12.0,!=6.2.0,!=6.3.0,!=6.3.1", python = "<3.9" }
inflection = ">=0.5.1"
joblib = ">=1.3.0"
jsonpath-ng = ">=1.5.3"
Expand All @@ -67,17 +61,17 @@ urllib3 = ">=1.26,<2"

# Sphinx dependencies installed as optional 'docs' extras
# https://github.com/readthedocs/readthedocs.org/issues/4912#issuecomment-664002569
sphinx = {version = ">=4.5", optional = true}
furo = {version = ">=2022.12.7", optional = true}
sphinx-copybutton = {version = ">=0.3.1", optional = true}
myst-parser = {version = ">=1", optional = true}
sphinx-autobuild = {version = ">=2021.3.14", optional = true}
sphinx-inline-tabs = {version = ">=2023.4.21", optional = true}
sphinx-notfound-page = {version = ">=1.0.0", optional = true}
sphinx-reredirects = {version = ">=0.1.1", optional = true}
sphinx = { version = ">=4.5", optional = true }
furo = { version = ">=2022.12.7", optional = true }
sphinx-copybutton = { version = ">=0.3.1", optional = true }
myst-parser = { version = ">=1", optional = true }
sphinx-autobuild = { version = ">=2021.3.14", optional = true }
sphinx-inline-tabs = { version = ">=2023.4.21", optional = true }
sphinx-notfound-page = { version = ">=1.0.0", optional = true }
sphinx-reredirects = { version = ">=0.1.1", optional = true }

# File storage dependencies installed as optional 'filesystem' extras
fs-s3fs = {version = ">=1.1.1", optional = true}
fs-s3fs = { version = ">=1.1.1", optional = true }

# Parquet file dependencies installed as optional 'parquet' extras
numpy = [
Expand All @@ -87,11 +81,11 @@ numpy = [
pyarrow = { version = ">=13", optional = true }

# Testing dependencies installed as optional 'testing' extras
pytest = {version=">=7.2.1", optional = true}
pytest-durations = {version = ">=1.2.0", optional = true}
pytest = { version = ">=7.2.1", optional = true }
pytest-durations = { version = ">=1.2.0", optional = true }

# installed as optional 'faker' extra
faker = {version = ">=22.5,<25.0", optional = true}
faker = { version = ">=22.5,<25.0", optional = true }

[tool.poetry.extras]
# TODO: Add 'cryptography' and 'PyJWT' to the 'jwt' when we want to remove them
Expand All @@ -109,15 +103,12 @@ docs = [
"sphinx-reredirects",
]
s3 = ["fs-s3fs"]
testing = [
"pytest",
"pytest-durations"
]
testing = ["pytest", "pytest-durations"]
parquet = ["numpy", "pyarrow"]
faker = ["faker"]

[tool.poetry.group.dev.dependencies]
coverage = {extras = ["toml"], version = ">=7.4"}
coverage = { extras = ["toml"], version = ">=7.4" }

# TODO: Remove the Python 3.12 marker when DuckDB supports it
duckdb = { version = ">=0.8.0", python = "<3.12" }
Expand Down Expand Up @@ -187,24 +178,14 @@ version_files = [
]

[tool.coverage.paths]
source = [
"singer_sdk/",
"*/singer_sdk",
]
tests = [
"tests/",
"*/tests",
]
source = ["singer_sdk/", "*/singer_sdk"]
tests = ["tests/", "*/tests"]

[tool.coverage.run]
branch = true
source = ["singer_sdk", "tests"]
relative_files = true # This allows coverage to be measured in Windows
omit = [
"tests/*",
"samples/*",
"singer_sdk/helpers/_compat.py",
]
relative_files = true # This allows coverage to be measured in Windows
omit = ["tests/*", "samples/*", "singer_sdk/helpers/_compat.py"]

[tool.coverage.report]
exclude_also = [
Expand Down Expand Up @@ -232,9 +213,9 @@ warn_unused_ignores = true
ignore_missing_imports = true
module = [
"backports.datetime_fromisoformat.*",
"joblib.*", # TODO: Remove when https://github.com/joblib/joblib/issues/1516 is shipped
"joblib.*", # TODO: Remove when https://github.com/joblib/joblib/issues/1516 is shipped
"jsonpath_ng.*",
"pyarrow.*", # TODO: Remove when https://github.com/apache/arrow/issues/32609 if implemented and released
"pyarrow.*", # TODO: Remove when https://github.com/apache/arrow/issues/32609 if implemented and released
]

[tool.poetry-dynamic-versioning]
Expand All @@ -253,10 +234,7 @@ jsonl = "singer_sdk.contrib.batch_encoder_jsonl:JSONLinesBatcher"
parquet = "singer_sdk.contrib.batch_encoder_parquet:ParquetBatcher"

[tool.ruff]
extend-exclude = [
"cookiecutter/*",
"*simpleeval*",
]
extend-exclude = ["cookiecutter/*", "*simpleeval*"]
line-length = 88
src = ["samples", "singer_sdk", "tests"]
target-version = "py38"
Expand All @@ -265,13 +243,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
"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 @@ -320,7 +300,7 @@ select = [
"RUF", # ruff
]
unfixable = [
"ERA", # Don't remove commented out code
"ERA", # Don't remove commented out code
]

[tool.ruff.lint.per-file-ignores]
Expand All @@ -330,7 +310,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 Expand Up @@ -358,9 +349,7 @@ known-first-party = ["singer_sdk", "samples", "tests"]
required-imports = ["from __future__ import annotations"]

[tool.ruff.lint.pep8-naming]
classmethod-decorators = [
"singer_sdk.cli.plugin_cli",
]
classmethod-decorators = ["singer_sdk.cli.plugin_cli"]

[tool.ruff.lint.pydocstyle]
convention = "google"
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",
]

0 comments on commit 8e94e48

Please sign in to comment.