From f5cd1ef8cda0c113725ee3002decbf342c0fb7c7 Mon Sep 17 00:00:00 2001 From: Ken Payne Date: Mon, 5 Dec 2022 17:35:09 +0200 Subject: [PATCH 01/11] support sourcing version when package name differs from executable name --- singer_sdk/plugin_base.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/singer_sdk/plugin_base.py b/singer_sdk/plugin_base.py index 0d4ba30db..da3787c2e 100644 --- a/singer_sdk/plugin_base.py +++ b/singer_sdk/plugin_base.py @@ -48,7 +48,8 @@ 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 # The package name of the plugin. e.g. meltanolabs-tap-csv config_jsonschema: dict = {} # A JSON Schema object defining the config options that this tap will accept. @@ -165,7 +166,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 From 6498ff3a0c5539ed450318b67074ae9b3b074490 Mon Sep 17 00:00:00 2001 From: Ken Payne Date: Mon, 5 Dec 2022 17:41:21 +0200 Subject: [PATCH 02/11] make package_name optional --- singer_sdk/plugin_base.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/singer_sdk/plugin_base.py b/singer_sdk/plugin_base.py index da3787c2e..72037a89c 100644 --- a/singer_sdk/plugin_base.py +++ b/singer_sdk/plugin_base.py @@ -1,5 +1,7 @@ """Shared parent class for Tap, Target (future), and Transform (future).""" +from __future__ import annotations + import abc import json import logging @@ -49,7 +51,9 @@ class PluginBase(metaclass=abc.ABCMeta): """Abstract base class for taps.""" name: str # The executable name of the plugin. e.g. tap-csv - package_name: str # The package name of the plugin. e.g. meltanolabs-tap-csv + package_name: str | None = ( + None # The package name of the plugin. e.g. meltanolabs-tap-csv + ) config_jsonschema: dict = {} # A JSON Schema object defining the config options that this tap will accept. From 4d77bfad2f1863077effedd431ae6ec59d01c6b8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 5 Dec 2022 15:56:34 +0000 Subject: [PATCH 03/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- singer_sdk/plugin_base.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/singer_sdk/plugin_base.py b/singer_sdk/plugin_base.py index 72037a89c..7d62cf8f8 100644 --- a/singer_sdk/plugin_base.py +++ b/singer_sdk/plugin_base.py @@ -85,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: @@ -130,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 @@ -145,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 "_", @@ -226,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: @@ -239,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: @@ -275,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. @@ -287,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 @@ -306,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 @@ -336,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: From a1a98f96b237810235f103e762b6e4abc5c14c30 Mon Sep 17 00:00:00 2001 From: Ken Payne Date: Mon, 5 Dec 2022 20:53:13 +0200 Subject: [PATCH 04/11] Update singer_sdk/plugin_base.py Co-authored-by: Edgar R. M. --- singer_sdk/plugin_base.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/singer_sdk/plugin_base.py b/singer_sdk/plugin_base.py index 7d62cf8f8..a3296c933 100644 --- a/singer_sdk/plugin_base.py +++ b/singer_sdk/plugin_base.py @@ -50,10 +50,11 @@ class PluginBase(metaclass=abc.ABCMeta): """Abstract base class for taps.""" - 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 - ) + #: The executable name of the plugin. e.g. tap-csv + name: str + + #: The package name of the plugin. e.g. meltanolabs-tap-csv + package_name: str | None = None config_jsonschema: dict = {} # A JSON Schema object defining the config options that this tap will accept. From 0e8264cec725a566ecf0fc58464760fa355c956c Mon Sep 17 00:00:00 2001 From: Ken Payne Date: Mon, 5 Dec 2022 21:52:06 +0200 Subject: [PATCH 05/11] linting --- singer_sdk/plugin_base.py | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/singer_sdk/plugin_base.py b/singer_sdk/plugin_base.py index a3296c933..88b52a983 100644 --- a/singer_sdk/plugin_base.py +++ b/singer_sdk/plugin_base.py @@ -9,18 +9,7 @@ from collections import OrderedDict from pathlib import PurePath from types import MappingProxyType -from typing import ( - Any, - Callable, - Dict, - List, - Mapping, - Optional, - Tuple, - Type, - Union, - cast, -) +from typing import Any, Callable, Dict, Mapping, cast import click from jsonschema import Draft7Validator, SchemaError, ValidationError From fd60579e2e688684f800c16e7b010919cc7cb4f2 Mon Sep 17 00:00:00 2001 From: Ken Payne Date: Tue, 6 Dec 2022 13:44:11 +0200 Subject: [PATCH 06/11] add variant and package_name properties, and update cookiecutter --- cookiecutter/tap-template/cookiecutter.json | 37 ++++++++----------- .../tap-template/cookiecutter.tests.yml | 7 ++++ .../{{cookiecutter.library_name}}/tap.py | 5 +++ .../target-template/cookiecutter.json | 13 ++++--- .../target-template/cookiecutter.tests.yml | 4 ++ .../{{cookiecutter.library_name}}/target.py | 5 +++ singer_sdk/plugin_base.py | 20 ++++++++-- 7 files changed, 60 insertions(+), 31 deletions(-) diff --git a/cookiecutter/tap-template/cookiecutter.json b/cookiecutter/tap-template/cookiecutter.json index 243a3d589..0635a6c02 100644 --- a/cookiecutter/tap-template/cookiecutter.json +++ b/cookiecutter/tap-template/cookiecutter.json @@ -1,24 +1,17 @@ { - "source_name": "MySourceName", - "admin_name": "FirstName LastName", - "tap_id": "tap-{{ cookiecutter.source_name.lower() }}", - "library_name": "{{ cookiecutter.tap_id.replace('-', '_') }}", - "stream_type": [ - "REST", - "GraphQL", - "SQL", - "Other" - ], - "auth_method": [ - "API Key", - "Bearer Token", - "Basic Auth", - "OAuth2", - "JWT", - "Custom or N/A" - ], - "include_cicd_sample_template": [ - "GitHub", - "None (Skip)" - ] + "source_name": "MySourceName", + "admin_name": "FirstName LastName", + "tap_id": "tap-{{ cookiecutter.source_name.lower() }}", + "library_name": "{{ cookiecutter.tap_id.replace('-', '_') }}", + "variant": "None (Skip)", + "stream_type": ["REST", "GraphQL", "SQL", "Other"], + "auth_method": [ + "API Key", + "Bearer Token", + "Basic Auth", + "OAuth2", + "JWT", + "Custom or N/A" + ], + "include_cicd_sample_template": ["GitHub", "None (Skip)"] } diff --git a/cookiecutter/tap-template/cookiecutter.tests.yml b/cookiecutter/tap-template/cookiecutter.tests.yml index 11e17f8ef..eb6a2d832 100644 --- a/cookiecutter/tap-template/cookiecutter.tests.yml +++ b/cookiecutter/tap-template/cookiecutter.tests.yml @@ -57,3 +57,10 @@ tests: stream_type: Other auth_method: Custom or N/A include_cicd_sample_template: GitHub + + - source_name: OtherCustomTemplateTest + tap_id: test-tap-other-custom-type + variant: meltanolabs + stream_type: Other + auth_method: Custom or N/A + include_cicd_sample_template: "None (Skip)" \ No newline at end of file diff --git a/cookiecutter/tap-template/{{cookiecutter.tap_id}}/{{cookiecutter.library_name}}/tap.py b/cookiecutter/tap-template/{{cookiecutter.tap_id}}/{{cookiecutter.library_name}}/tap.py index e41c337d7..cf6eee6e1 100644 --- a/cookiecutter/tap-template/{{cookiecutter.tap_id}}/{{cookiecutter.library_name}}/tap.py +++ b/cookiecutter/tap-template/{{cookiecutter.tap_id}}/{{cookiecutter.library_name}}/tap.py @@ -30,8 +30,13 @@ class Tap{{ cookiecutter.source_name }}({{ 'SQL' if cookiecutter.stream_type == 'SQL' else '' }}Tap): """{{ cookiecutter.source_name }} tap class.""" + name = "{{ cookiecutter.tap_id }}" +{%- if cookiecutter.variant != "None (Skip)" %} + variant = "{{ cookiecutter.variant }}" +{%- endif %} + # TODO: Update this section with the actual config values you expect: config_jsonschema = th.PropertiesList( th.Property( diff --git a/cookiecutter/target-template/cookiecutter.json b/cookiecutter/target-template/cookiecutter.json index c07a7ac6a..fc17807c4 100644 --- a/cookiecutter/target-template/cookiecutter.json +++ b/cookiecutter/target-template/cookiecutter.json @@ -1,7 +1,8 @@ { - "destination_name": "MyDestinationName", - "admin_name": "FirstName LastName", - "target_id": "target-{{ cookiecutter.destination_name.lower() }}", - "library_name": "{{ cookiecutter.target_id.replace('-', '_') }}", - "serialization_method": ["Per record", "Per batch", "SQL"] -} \ No newline at end of file + "destination_name": "MyDestinationName", + "admin_name": "FirstName LastName", + "target_id": "target-{{ cookiecutter.destination_name.lower() }}", + "library_name": "{{ cookiecutter.target_id.replace('-', '_') }}", + "variant": "None (Skip)", + "serialization_method": ["Per record", "Per batch", "SQL"] +} diff --git a/cookiecutter/target-template/cookiecutter.tests.yml b/cookiecutter/target-template/cookiecutter.tests.yml index 514f220bf..e0747fe8f 100644 --- a/cookiecutter/target-template/cookiecutter.tests.yml +++ b/cookiecutter/target-template/cookiecutter.tests.yml @@ -8,3 +8,7 @@ tests: - destination_name: SQLSinkTest target_id: target-sqlsink-test serialization_method: SQL + - destination_name: TargetRecordSinkTest + target_id: target-recordsink-test + variant: meltanolabs + serialization_method: Per record \ No newline at end of file diff --git a/cookiecutter/target-template/{{cookiecutter.target_id}}/{{cookiecutter.library_name}}/target.py b/cookiecutter/target-template/{{cookiecutter.target_id}}/{{cookiecutter.library_name}}/target.py index 35b4a4675..ff4f43cec 100644 --- a/cookiecutter/target-template/{{cookiecutter.target_id}}/{{cookiecutter.library_name}}/target.py +++ b/cookiecutter/target-template/{{cookiecutter.target_id}}/{{cookiecutter.library_name}}/target.py @@ -16,6 +16,11 @@ class Target{{ cookiecutter.destination_name }}({{ target_class }}): """Sample target for {{ cookiecutter.destination_name }}.""" name = "{{ cookiecutter.target_id }}" + +{%- if cookiecutter.variant != "None (Skip)" %} + variant = "{{ cookiecutter.variant }}" +{%- endif %} + config_jsonschema = th.PropertiesList( {%- if cookiecutter.serialization_method == "SQL" %} th.Property( diff --git a/singer_sdk/plugin_base.py b/singer_sdk/plugin_base.py index 88b52a983..a18521587 100644 --- a/singer_sdk/plugin_base.py +++ b/singer_sdk/plugin_base.py @@ -42,8 +42,8 @@ class PluginBase(metaclass=abc.ABCMeta): #: The executable name of the plugin. e.g. tap-csv name: str - #: The package name of the plugin. e.g. meltanolabs-tap-csv - package_name: str | None = None + #: The variant name of the plugin. e.g. meltanolabs + variant: str | None = None config_jsonschema: dict = {} # A JSON Schema object defining the config options that this tap will accept. @@ -152,6 +152,20 @@ def _env_var_config(cls) -> dict[str, Any]: # Core plugin metadata: + @classproperty + def package_name(cls) -> str: + """Get package name. + + Package name is the distribution name (wheel name or pip install name) + of this plugin. By convention it is a concatenation of the variant and name. + + e.g. "meltanolabs-tap-csv" + + Returns: + The package name. + """ + return f"{cls.variant}-{cls.name}" if cls.variant else cls.name + @classproperty def plugin_version(cls) -> str: """Get version. @@ -160,7 +174,7 @@ def plugin_version(cls) -> str: The package version number. """ try: - version = metadata.version(cls.package_name or cls.name) + version = metadata.version(cls.package_name) except metadata.PackageNotFoundError: version = "[could not be detected]" return version From dab7a20e9917f5aff4131c5b3f7e11ad3eb08418 Mon Sep 17 00:00:00 2001 From: Ken Payne Date: Tue, 6 Dec 2022 13:59:05 +0200 Subject: [PATCH 07/11] update pyproject.toml --- .../{{cookiecutter.tap_id}}/pyproject.toml | 10 ++++++++++ .../{{cookiecutter.target_id}}/pyproject.toml | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/cookiecutter/tap-template/{{cookiecutter.tap_id}}/pyproject.toml b/cookiecutter/tap-template/{{cookiecutter.tap_id}}/pyproject.toml index 9bce76242..41987e4e1 100644 --- a/cookiecutter/tap-template/{{cookiecutter.tap_id}}/pyproject.toml +++ b/cookiecutter/tap-template/{{cookiecutter.tap_id}}/pyproject.toml @@ -1,13 +1,23 @@ [tool.poetry] +{%- if cookiecutter.variant != "None (Skip)" %} +name = "{{cookiecutter.variant}}-{{cookiecutter.tap_id}}" +{% else %} name = "{{cookiecutter.tap_id}}" +{%- endif %} version = "0.0.1" description = "`{{cookiecutter.tap_id}}` is a Singer tap for {{cookiecutter.source_name}}, built with the Meltano Singer SDK." +readme = "README.md" authors = ["{{ cookiecutter.admin_name }}"] keywords = [ "ELT", "{{cookiecutter.source_name}}", ] license = "Apache 2.0" +{%- if cookiecutter.variant != "None (Skip)" %} +packages = [ + { include = "{{cookiecutter.library_name}}" }, +] +{%- endif %} [tool.poetry.dependencies] python = "<3.11,>=3.7.1" diff --git a/cookiecutter/target-template/{{cookiecutter.target_id}}/pyproject.toml b/cookiecutter/target-template/{{cookiecutter.target_id}}/pyproject.toml index 9f6771603..58bada738 100644 --- a/cookiecutter/target-template/{{cookiecutter.target_id}}/pyproject.toml +++ b/cookiecutter/target-template/{{cookiecutter.target_id}}/pyproject.toml @@ -1,13 +1,23 @@ [tool.poetry] +{%- if cookiecutter.variant != "None (Skip)" %} +name = "{{cookiecutter.variant}}-{{cookiecutter.target_id}}" +{% else %} name = "{{cookiecutter.target_id}}" +{% %} version = "0.0.1" description = "`{{cookiecutter.target_id}}` is a Singer target for {{cookiecutter.destination_name}}, built with the Meltano Singer SDK." +readme = "README.md" authors = ["{{ cookiecutter.admin_name }}"] keywords = [ "ELT", "{{cookiecutter.destination_name}}", ] license = "Apache 2.0" +{%- if cookiecutter.variant != "None (Skip)" %} +packages = [ + { include = "{{cookiecutter.library_name}}" }, +] +{%- endif %} [tool.poetry.dependencies] python = "<3.11,>=3.7.1" From 84dd5426f6fb49bcb607b6705b0509e83f4203de Mon Sep 17 00:00:00 2001 From: Ken Payne Date: Tue, 6 Dec 2022 14:08:32 +0200 Subject: [PATCH 08/11] fix missing tag --- .../target-template/{{cookiecutter.target_id}}/pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cookiecutter/target-template/{{cookiecutter.target_id}}/pyproject.toml b/cookiecutter/target-template/{{cookiecutter.target_id}}/pyproject.toml index 58bada738..6437ca90a 100644 --- a/cookiecutter/target-template/{{cookiecutter.target_id}}/pyproject.toml +++ b/cookiecutter/target-template/{{cookiecutter.target_id}}/pyproject.toml @@ -3,7 +3,7 @@ name = "{{cookiecutter.variant}}-{{cookiecutter.target_id}}" {% else %} name = "{{cookiecutter.target_id}}" -{% %} +{% endif %} version = "0.0.1" description = "`{{cookiecutter.target_id}}` is a Singer target for {{cookiecutter.destination_name}}, built with the Meltano Singer SDK." readme = "README.md" From 5c279c8cff69177723226be6161e8151c786546c Mon Sep 17 00:00:00 2001 From: Ken Payne Date: Tue, 6 Dec 2022 15:08:21 +0200 Subject: [PATCH 09/11] fix jinja formatting --- .../tap-template/{{cookiecutter.tap_id}}/pyproject.toml | 2 +- .../target-template/{{cookiecutter.target_id}}/pyproject.toml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cookiecutter/tap-template/{{cookiecutter.tap_id}}/pyproject.toml b/cookiecutter/tap-template/{{cookiecutter.tap_id}}/pyproject.toml index 41987e4e1..401e151ce 100644 --- a/cookiecutter/tap-template/{{cookiecutter.tap_id}}/pyproject.toml +++ b/cookiecutter/tap-template/{{cookiecutter.tap_id}}/pyproject.toml @@ -1,7 +1,7 @@ [tool.poetry] {%- if cookiecutter.variant != "None (Skip)" %} name = "{{cookiecutter.variant}}-{{cookiecutter.tap_id}}" -{% else %} +{%- else %} name = "{{cookiecutter.tap_id}}" {%- endif %} version = "0.0.1" diff --git a/cookiecutter/target-template/{{cookiecutter.target_id}}/pyproject.toml b/cookiecutter/target-template/{{cookiecutter.target_id}}/pyproject.toml index 6437ca90a..1827a9c2a 100644 --- a/cookiecutter/target-template/{{cookiecutter.target_id}}/pyproject.toml +++ b/cookiecutter/target-template/{{cookiecutter.target_id}}/pyproject.toml @@ -1,9 +1,9 @@ [tool.poetry] {%- if cookiecutter.variant != "None (Skip)" %} name = "{{cookiecutter.variant}}-{{cookiecutter.target_id}}" -{% else %} +{%- else %} name = "{{cookiecutter.target_id}}" -{% endif %} +{%- endif %} version = "0.0.1" description = "`{{cookiecutter.target_id}}` is a Singer target for {{cookiecutter.destination_name}}, built with the Meltano Singer SDK." readme = "README.md" From 4077106709e856095189064e8434755e852db733 Mon Sep 17 00:00:00 2001 From: Ken Payne Date: Wed, 7 Dec 2022 12:20:03 +0200 Subject: [PATCH 10/11] revert plugin_base changes --- singer_sdk/plugin_base.py | 81 +++++++++++++++++---------------------- 1 file changed, 36 insertions(+), 45 deletions(-) diff --git a/singer_sdk/plugin_base.py b/singer_sdk/plugin_base.py index a18521587..feb0f0db3 100644 --- a/singer_sdk/plugin_base.py +++ b/singer_sdk/plugin_base.py @@ -1,7 +1,5 @@ """Shared parent class for Tap, Target (future), and Transform (future).""" -from __future__ import annotations - import abc import json import logging @@ -9,7 +7,18 @@ from collections import OrderedDict from pathlib import PurePath from types import MappingProxyType -from typing import Any, Callable, Dict, Mapping, cast +from typing import ( + Any, + Callable, + Dict, + List, + Mapping, + Optional, + Tuple, + Type, + Union, + cast, +) import click from jsonschema import Draft7Validator, SchemaError, ValidationError @@ -39,11 +48,7 @@ class PluginBase(metaclass=abc.ABCMeta): """Abstract base class for taps.""" - #: The executable name of the plugin. e.g. tap-csv - name: str - - #: The variant name of the plugin. e.g. meltanolabs - variant: str | None = None + name: str # The executable name of the tap or target plugin. config_jsonschema: dict = {} # A JSON Schema object defining the config options that this tap will accept. @@ -58,24 +63,22 @@ def logger(cls) -> logging.Logger: Plugin logger. """ # Get the level from _LOGLEVEL or LOGLEVEL environment variables - LOGLEVEL = ( - os.environ.get(f"{cls.name.upper()}_LOGLEVEL") - or os.environ.get("LOGLEVEL") - or "INFO" - ).upper() - - assert ( - LOGLEVEL in logging._levelToName.values() - ), f"Invalid LOGLEVEL configuration: {LOGLEVEL}" + LOGLEVEL = os.environ.get(f"{cls.name.upper()}_LOGLEVEL") or os.environ.get( + "LOGLEVEL" + ) + logger = logging.getLogger(cls.name) - logger.setLevel(LOGLEVEL) + + if LOGLEVEL is not None and LOGLEVEL.upper() in logging._levelToName.values(): + logger.setLevel(LOGLEVEL.upper()) + return logger # Constructor def __init__( self, - config: dict | PurePath | str | list[PurePath | str] | None = None, + config: Optional[Union[dict, PurePath, str, List[Union[PurePath, str]]]] = None, parse_env_config: bool = False, validate_config: bool = True, ) -> None: @@ -120,7 +123,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 @@ -135,7 +138,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 "_", @@ -152,20 +155,6 @@ def _env_var_config(cls) -> dict[str, Any]: # Core plugin metadata: - @classproperty - def package_name(cls) -> str: - """Get package name. - - Package name is the distribution name (wheel name or pip install name) - of this plugin. By convention it is a concatenation of the variant and name. - - e.g. "meltanolabs-tap-csv" - - Returns: - The package name. - """ - return f"{cls.variant}-{cls.name}" if cls.variant else cls.name - @classproperty def plugin_version(cls) -> str: """Get version. @@ -174,7 +163,7 @@ def plugin_version(cls) -> str: The package version number. """ try: - version = metadata.version(cls.package_name) + version = metadata.version(cls.name) except metadata.PackageNotFoundError: version = "[could not be detected]" return version @@ -230,7 +219,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: @@ -243,8 +232,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: @@ -279,25 +268,27 @@ 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. Args: print_fn: A function to use to display the plugin version. - Defaults to :function:`print`. + Defaults to `print`_. + + .. _print: https://docs.python.org/3/library/functions.html#print """ 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 @@ -310,7 +301,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 @@ -340,7 +331,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: str | None = None) -> None: + def print_about(cls: Type["PluginBase"], format: Optional[str] = None) -> None: """Print capabilities and other tap metadata. Args: From 3b3edca7b880b654a948da8ca39697a1a6c3728c Mon Sep 17 00:00:00 2001 From: Ken Payne Date: Wed, 7 Dec 2022 12:21:34 +0200 Subject: [PATCH 11/11] revert cookiecutter variant changes --- .../{{cookiecutter.library_name}}/tap.py | 4 ---- .../{{cookiecutter.library_name}}/target.py | 4 ---- 2 files changed, 8 deletions(-) diff --git a/cookiecutter/tap-template/{{cookiecutter.tap_id}}/{{cookiecutter.library_name}}/tap.py b/cookiecutter/tap-template/{{cookiecutter.tap_id}}/{{cookiecutter.library_name}}/tap.py index cf6eee6e1..ca508aae3 100644 --- a/cookiecutter/tap-template/{{cookiecutter.tap_id}}/{{cookiecutter.library_name}}/tap.py +++ b/cookiecutter/tap-template/{{cookiecutter.tap_id}}/{{cookiecutter.library_name}}/tap.py @@ -33,10 +33,6 @@ class Tap{{ cookiecutter.source_name }}({{ 'SQL' if cookiecutter.stream_type == name = "{{ cookiecutter.tap_id }}" -{%- if cookiecutter.variant != "None (Skip)" %} - variant = "{{ cookiecutter.variant }}" -{%- endif %} - # TODO: Update this section with the actual config values you expect: config_jsonschema = th.PropertiesList( th.Property( diff --git a/cookiecutter/target-template/{{cookiecutter.target_id}}/{{cookiecutter.library_name}}/target.py b/cookiecutter/target-template/{{cookiecutter.target_id}}/{{cookiecutter.library_name}}/target.py index ff4f43cec..ac4299abb 100644 --- a/cookiecutter/target-template/{{cookiecutter.target_id}}/{{cookiecutter.library_name}}/target.py +++ b/cookiecutter/target-template/{{cookiecutter.target_id}}/{{cookiecutter.library_name}}/target.py @@ -17,10 +17,6 @@ class Target{{ cookiecutter.destination_name }}({{ target_class }}): name = "{{ cookiecutter.target_id }}" -{%- if cookiecutter.variant != "None (Skip)" %} - variant = "{{ cookiecutter.variant }}" -{%- endif %} - config_jsonschema = th.PropertiesList( {%- if cookiecutter.serialization_method == "SQL" %} th.Property(