Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support declaring variant for use in package name #1241

Merged
Merged
Changes from 3 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
f5cd1ef
support sourcing version when package name differs from executable name
Dec 5, 2022
6498ff3
make package_name optional
Dec 5, 2022
4d77bfa
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Dec 5, 2022
a1a98f9
Update singer_sdk/plugin_base.py
Dec 5, 2022
0e8264c
linting
Dec 5, 2022
fd60579
add variant and package_name properties, and update cookiecutter
Dec 6, 2022
dab7a20
update pyproject.toml
Dec 6, 2022
8a7b52f
Merge branch 'main' into kgpayne/version-when-package-name-differs-fr…
Dec 6, 2022
84dd542
fix missing tag
Dec 6, 2022
020ba29
Merge branch 'kgpayne/version-when-package-name-differs-from-exec-nam…
Dec 6, 2022
5c279c8
fix jinja formatting
Dec 6, 2022
5c7fb53
Merge branch 'main' into kgpayne/version-when-package-name-differs-fr…
Dec 6, 2022
925026b
Merge branch 'main' into kgpayne/version-when-package-name-differs-fr…
Dec 7, 2022
4077106
revert plugin_base changes
Dec 7, 2022
3b3edca
revert cookiecutter variant changes
Dec 7, 2022
b6eac31
Merge branch 'kgpayne/version-when-package-name-differs-from-exec-nam…
Dec 7, 2022
5b6197a
Merge branch 'main' into kgpayne/version-when-package-name-differs-fr…
Dec 14, 2022
b826326
Merge branch 'main' into kgpayne/version-when-package-name-differs-fr…
Dec 15, 2022
f14b64f
Merge branch 'main' into kgpayne/version-when-package-name-differs-fr…
Feb 8, 2023
27122e7
Merge branch 'main' into kgpayne/version-when-package-name-differs-fr…
Feb 8, 2023
fb6481c
Merge branch 'main' into kgpayne/version-when-package-name-differs-fr…
Feb 9, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions singer_sdk/plugin_base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Shared parent class for Tap, Target (future), and Transform (future)."""

from __future__ import annotations

import abc
import json
import logging
Expand Down Expand Up @@ -48,7 +50,10 @@
class PluginBase(metaclass=abc.ABCMeta):
"""Abstract base class for taps."""

name: str # The executable name of the tap or target plugin.
name: str # The executable name of the plugin. e.g. tap-csv
package_name: str | None = (
None # The package name of the plugin. e.g. meltanolabs-tap-csv
)
kgpayne marked this conversation as resolved.
Show resolved Hide resolved

config_jsonschema: dict = {}
# A JSON Schema object defining the config options that this tap will accept.
Expand Down Expand Up @@ -80,7 +85,7 @@ def logger(cls) -> logging.Logger:

def __init__(
self,
config: Optional[Union[dict, PurePath, str, List[Union[PurePath, str]]]] = None,
config: dict | PurePath | str | list[PurePath | str] | None = None,
parse_env_config: bool = False,
validate_config: bool = True,
) -> None:
Expand Down Expand Up @@ -125,7 +130,7 @@ def __init__(
self.metrics_logger = metrics.get_metrics_logger()

@classproperty
def capabilities(self) -> List[CapabilitiesEnum]:
def capabilities(self) -> list[CapabilitiesEnum]:
"""Get capabilities.

Developers may override this property in oder to add or remove
Expand All @@ -140,7 +145,7 @@ def capabilities(self) -> List[CapabilitiesEnum]:
]

@classproperty
def _env_var_config(cls) -> Dict[str, Any]:
def _env_var_config(cls) -> dict[str, Any]:
"""Return any config specified in environment variables.

Variables must match the convention "<PLUGIN_NAME>_<SETTING_NAME>",
Expand All @@ -165,7 +170,7 @@ def plugin_version(cls) -> str:
The package version number.
"""
try:
version = metadata.version(cls.name)
version = metadata.version(cls.package_name or cls.name)
except metadata.PackageNotFoundError:
version = "[could not be detected]"
return version
Expand Down Expand Up @@ -221,7 +226,7 @@ def _is_secret_config(config_key: str) -> bool:

def _validate_config(
self, raise_errors: bool = True, warnings_as_errors: bool = False
) -> Tuple[List[str], List[str]]:
) -> tuple[list[str], list[str]]:
"""Validate configuration input against the plugin configuration JSON schema.

Args:
Expand All @@ -234,8 +239,8 @@ def _validate_config(
Raises:
ConfigValidationError: If raise_errors is True and validation fails.
"""
warnings: List[str] = []
errors: List[str] = []
warnings: list[str] = []
errors: list[str] = []
log_fn = self.logger.info
config_jsonschema = self.config_jsonschema
if config_jsonschema:
Expand Down Expand Up @@ -270,7 +275,7 @@ def _validate_config(

@classmethod
def print_version(
cls: Type["PluginBase"],
cls: type[PluginBase],
print_fn: Callable[[Any], None] = print,
) -> None:
"""Print help text for the tap.
Expand All @@ -282,13 +287,13 @@ def print_version(
print_fn(f"{cls.name} v{cls.plugin_version}, Meltano SDK v{cls.sdk_version}")

@classmethod
def _get_about_info(cls: Type["PluginBase"]) -> Dict[str, Any]:
def _get_about_info(cls: type[PluginBase]) -> dict[str, Any]:
"""Returns capabilities and other tap metadata.

Returns:
A dictionary containing the relevant 'about' information.
"""
info: Dict[str, Any] = OrderedDict({})
info: dict[str, Any] = OrderedDict({})
info["name"] = cls.name
info["description"] = cls.__doc__
info["version"] = cls.plugin_version
Expand All @@ -301,7 +306,7 @@ def _get_about_info(cls: Type["PluginBase"]) -> Dict[str, Any]:
return info

@classmethod
def append_builtin_config(cls: Type["PluginBase"], config_jsonschema: dict) -> None:
def append_builtin_config(cls: type[PluginBase], config_jsonschema: dict) -> None:
"""Appends built-in config to `config_jsonschema` if not already set.

To customize or disable this behavior, developers may either override this class
Expand Down Expand Up @@ -331,7 +336,7 @@ def _merge_missing(source_jsonschema: dict, target_jsonschema: dict) -> None:
_merge_missing(FLATTENING_CONFIG, config_jsonschema)

@classmethod
def print_about(cls: Type["PluginBase"], format: Optional[str] = None) -> None:
def print_about(cls: type[PluginBase], format: str | None = None) -> None:
"""Print capabilities and other tap metadata.

Args:
Expand Down