Skip to content

Commit

Permalink
Merge branch 'main' into docs-link-color
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon authored Mar 28, 2023
2 parents f85d483 + 563663f commit 6a3d10b
Show file tree
Hide file tree
Showing 20 changed files with 66 additions and 51 deletions.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# -- Project information -----------------------------------------------------

project = "Meltano Singer SDK"
copyright = "2021, Meltano Core Team and Contributors"
copyright = "2021, Meltano Core Team and Contributors" # noqa: A001
author = "Meltano Core Team and Contributors"

# The full version, including alpha/beta/rc tags
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ select = [
"ANN", # flake8-annotations
"BLE", # flake8-blind-except
"B", # flake8-bugbear
"A", # flake8-builtins
"COM", # flake8-commas
"C4", # flake8-comprehensions
"T10", # flake8-debugger
Expand Down
7 changes: 5 additions & 2 deletions samples/sample_tap_gitlab/gitlab_rest_streams.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,18 @@ def partitions(self) -> list[dict]:
"""Return a list of partition key dicts (if applicable), otherwise None."""
if "{project_id}" in self.path:
return [
{"project_id": id} for id in cast(list, self.config.get("project_ids"))
{"project_id": pid}
for pid in cast(list, self.config.get("project_ids"))
]
if "{group_id}" in self.path:
if "group_ids" not in self.config:
raise ValueError(
f"Missing `group_ids` setting which is required for the "
f"'{self.name}' stream.",
)
return [{"group_id": id} for id in cast(list, self.config.get("group_ids"))]
return [
{"group_id": gid} for gid in cast(list, self.config.get("group_ids"))
]
raise ValueError(
"Could not detect partition type for Gitlab stream "
f"'{self.name}' ({self.path}). "
Expand Down
4 changes: 2 additions & 2 deletions samples/sample_target_parquet/parquet_target_sink.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ def translate_data_type(singer_type: str | dict) -> Any:

def _get_parquet_schema(self) -> list[tuple[str, Any]]:
col_list: list[tuple[str, Any]] = []
for property in self.schema["properties"]:
for prop in self.schema["properties"]:
col_list.append(
(property["name"], self.translate_data_type(property["type"])),
(prop["name"], self.translate_data_type(prop["type"])),
)
return col_list
2 changes: 1 addition & 1 deletion singer_sdk/_singerlib/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def exclude_null_dict(pairs: list[tuple[str, t.Any]]) -> dict[str, t.Any]:
class Message:
"""Singer base message."""

type: SingerMessageType = field(init=False)
type: SingerMessageType = field(init=False) # noqa: A003
"""The message type."""

def to_dict(self) -> dict[str, t.Any]:
Expand Down
4 changes: 2 additions & 2 deletions singer_sdk/_singerlib/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Schema:
This is because we wanted to expand it with extra STANDARD_KEYS.
"""

type: str | list[str] | None = None
type: str | list[str] | None = None # noqa: A003
properties: dict | None = None
items: t.Any | None = None
description: str | None = None
Expand All @@ -55,7 +55,7 @@ class Schema:
maxLength: int | None = None
minLength: int | None = None
anyOf: t.Any | None = None
format: str | None = None
format: str | None = None # noqa: A003
additionalProperties: t.Any | None = None
patternProperties: t.Any | None = None
required: list[str] | None = None
Expand Down
1 change: 1 addition & 0 deletions singer_sdk/cli/common_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

PLUGIN_ABOUT_FORMAT = click.option(
"--format",
"about_format",
help="Specify output style for --about",
type=click.Choice(["json", "markdown"], case_sensitive=False),
default=None,
Expand Down
8 changes: 6 additions & 2 deletions singer_sdk/helpers/_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class BaseBatchFileEncoding:
__encoding_format__: ClassVar[str] = "OVERRIDE_ME"

# Base encoding fields
format: str = field(init=False)
format: str = field(init=False) # noqa: A003
"""The format of the batch file."""

compression: str | None = None
Expand Down Expand Up @@ -176,7 +176,11 @@ def fs(self, **kwargs: Any) -> Generator[FS, None, None]:
filesystem.close()

@contextmanager
def open(self, filename: str, mode: str = "rb") -> Generator[IO, None, None]:
def open( # noqa: A003
self,
filename: str,
mode: str = "rb",
) -> Generator[IO, None, None]:
"""Open a file in the storage target.
Args:
Expand Down
5 changes: 4 additions & 1 deletion singer_sdk/helpers/jsonpath.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
import jsonpath_ng


def extract_jsonpath(expression: str, input: dict | list) -> Generator[Any, None, None]:
def extract_jsonpath(
expression: str,
input: dict | list, # noqa: A002
) -> Generator[Any, None, None]:
"""Extract records from an input based on a JSONPath expression.
Args:
Expand Down
6 changes: 3 additions & 3 deletions singer_sdk/mapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,16 @@
NULL_STRING = "__NULL__"


def md5(input: str) -> str:
def md5(string: str) -> str:
"""Digest a string using MD5. This is a function for inline calculations.
Args:
input: String to digest.
string: String to digest.
Returns:
A string digested into MD5.
"""
return hashlib.md5(input.encode("utf-8")).hexdigest()
return hashlib.md5(string.encode("utf-8")).hexdigest()


StreamMapsDict: TypeAlias = Dict[str, Union[str, dict, None]]
Expand Down
6 changes: 3 additions & 3 deletions singer_sdk/mapper_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,15 @@ def cli(
version: bool = False,
about: bool = False,
config: tuple[str, ...] = (),
format: str | None = None,
about_format: str | None = None,
file_input: FileIO | None = None,
) -> None:
"""Handle command line execution.
Args:
version: Display the package version.
about: Display package metadata and settings.
format: Specify output style for `--about`.
about_format: Specify output style for `--about`.
config: Configuration file location or 'ENV' to use environment
variables. Accepts multiple inputs as a tuple.
file_input: Specify a path to an input file to read messages from.
Expand Down Expand Up @@ -170,7 +170,7 @@ def cli(
)

if about:
mapper.print_about(format)
mapper.print_about(about_format)
else:
mapper.listen(file_input)

Expand Down
11 changes: 7 additions & 4 deletions singer_sdk/plugin_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,18 +327,21 @@ def _merge_missing(source_jsonschema: dict, target_jsonschema: dict) -> None:
_merge_missing(FLATTENING_CONFIG, config_jsonschema)

@classmethod
def print_about(cls: type[PluginBase], format: str | None = None) -> None:
def print_about(
cls: type[PluginBase],
output_format: str | None = None,
) -> None:
"""Print capabilities and other tap metadata.
Args:
format: Render option for the plugin information.
output_format: Render option for the plugin information.
"""
info = cls._get_about_info()

if format == "json":
if output_format == "json":
print(json.dumps(info, indent=2, default=str)) # noqa: T201

elif format == "markdown":
elif output_format == "markdown":
max_setting_len = cast(
int,
max(len(k) for k in info["settings"]["properties"]),
Expand Down
6 changes: 3 additions & 3 deletions singer_sdk/tap_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ def cli(
config: tuple[str, ...] = (),
state: str | None = None,
catalog: str | None = None,
format: str | None = None,
about_format: str | None = None,
) -> None:
"""Handle command line execution.
Expand All @@ -449,7 +449,7 @@ def cli(
about: Display package metadata and settings.
discover: Run the tap in discovery mode.
test: Test connectivity by syncing a single record and exiting.
format: Specify output style for `--about`.
about_format: Specify output style for `--about`.
config: Configuration file location or 'ENV' to use environment
variables. Accepts multiple inputs as a tuple.
catalog: Use a Singer catalog file with the tap.",
Expand All @@ -465,7 +465,7 @@ def cli(
if not about:
cls.print_version(print_fn=cls.logger.info)
else:
cls.print_about(format=format)
cls.print_about(output_format=about_format)
return

validate_config: bool = True
Expand Down
6 changes: 3 additions & 3 deletions singer_sdk/target_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,15 +521,15 @@ def cli(
version: bool = False,
about: bool = False,
config: tuple[str, ...] = (),
format: str | None = None,
about_format: str | None = None,
file_input: FileIO | None = None,
) -> None:
"""Handle command line execution.
Args:
version: Display the package version.
about: Display package metadata and settings.
format: Specify output style for `--about`.
about_format: Specify output style for `--about`.
config: Configuration file location or 'ENV' to use environment
variables. Accepts multiple inputs as a tuple.
file_input: Specify a path to an input file to read messages from.
Expand All @@ -545,7 +545,7 @@ def cli(
if not about:
cls.print_version(print_fn=cls.logger.info)
else:
cls.print_about(format=format)
cls.print_about(output_format=about_format)
return

validate_config: bool = True
Expand Down
4 changes: 2 additions & 2 deletions singer_sdk/testing/legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _test_cli_prints() -> None:
# Test CLI prints
tap1.print_version()
tap1.print_about()
tap1.print_about(format="json")
tap1.print_about(output_format="json")

def _test_discovery() -> None:
catalog1 = _get_tap_catalog(tap_class, config or {})
Expand Down Expand Up @@ -173,7 +173,7 @@ def _select_all(catalog_dict: dict) -> dict:

def target_sync_test(
target: Target,
input: io.StringIO | None,
input: io.StringIO | None, # noqa: A002
finalize: bool = True,
) -> tuple[io.StringIO, io.StringIO]:
"""Invoke the target with the provided input.
Expand Down
16 changes: 8 additions & 8 deletions singer_sdk/testing/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def target(self) -> Target:
return cast(Target, self.create())

@property
def input(self) -> IO[str]:
def target_input(self) -> IO[str]:
"""Input messages to pass to Target.
Returns:
Expand All @@ -234,8 +234,8 @@ def input(self) -> IO[str]:
self._input = Path(self.input_filepath).open() # noqa: SIM115
return cast(IO[str], self._input)

@input.setter
def input(self, value: IO[str]) -> None:
@target_input.setter
def target_input(self, value: IO[str]) -> None:
self._input = value

def sync_all(self, finalize: bool = True, **kwargs: Any) -> None: # noqa: ARG002
Expand All @@ -249,7 +249,7 @@ def sync_all(self, finalize: bool = True, **kwargs: Any) -> None: # noqa: ARG00
target = cast(Target, self.create())
stdout, stderr = self._execute_sync(
target=target,
input=self.input,
target_input=self.target_input,
finalize=finalize,
)
self.stdout, self.stderr = (stdout.read(), stderr.read())
Expand All @@ -258,14 +258,14 @@ def sync_all(self, finalize: bool = True, **kwargs: Any) -> None: # noqa: ARG00
def _execute_sync(
self,
target: Target,
input: IO[str],
target_input: IO[str],
finalize: bool = True,
) -> tuple[io.StringIO, io.StringIO]:
"""Invoke the target with the provided input.
Args:
target: Target to sync.
input: The input to process as if from STDIN.
target_input: The input to process as if from STDIN.
finalize: True to process as the end of stream as a completion signal;
False to keep the sink operation open for further records.
Expand All @@ -277,8 +277,8 @@ def _execute_sync(
stderr_buf = io.StringIO()

with redirect_stdout(stdout_buf), redirect_stderr(stderr_buf):
if input is not None:
target._process_lines(input)
if target_input is not None:
target._process_lines(target_input)
if finalize:
target._process_endofpipe()

Expand Down
2 changes: 1 addition & 1 deletion singer_sdk/testing/tap_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def test(self) -> None:
"""Run test."""
self.tap.print_version()
self.tap.print_about()
self.tap.print_about(format="json")
self.tap.print_about(output_format="json")


class TapDiscoveryTest(TapTestTemplate):
Expand Down
2 changes: 1 addition & 1 deletion singer_sdk/testing/target_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def test(self) -> None:
"""Run test."""
self.target.print_version()
self.target.print_about()
self.target.print_about(format="json")
self.target.print_about(output_format="json")


class TargetDuplicateRecords(TargetFileTestTemplate):
Expand Down
Loading

0 comments on commit 6a3d10b

Please sign in to comment.