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: publish supported python versions in --about #1800

Merged
merged 13 commits into from
Jul 7, 2023
14 changes: 14 additions & 0 deletions singer_sdk/about.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class AboutInfo:
description: str | None
version: str
sdk_version: str
supported_python_versions: list[str] | None

capabilities: list[CapabilitiesEnum]
settings: dict
Expand Down Expand Up @@ -88,6 +89,7 @@ def format_about(self, about_info: AboutInfo) -> str:
Description: {about_info.description}
Version: {about_info.version}
SDK Version: {about_info.sdk_version}
Supported Python Versions: {about_info.supported_python_versions}
Capabilities: {about_info.capabilities}
Settings: {about_info.settings}""",
)
Expand Down Expand Up @@ -116,6 +118,7 @@ def format_about(self, about_info: AboutInfo) -> str:
("description", about_info.description),
("version", about_info.version),
("sdk_version", about_info.sdk_version),
("supported_python_versions", about_info.supported_python_versions),
("capabilities", [c.value for c in about_info.capabilities]),
("settings", about_info.settings),
],
Expand Down Expand Up @@ -187,6 +190,17 @@ def format_about(self, about_info: AboutInfo) -> str:
)
+ "\n"
)
setting += "\n"
md_list.append(setting)

# Process Supported Python Versions

if about_info.supported_python_versions:
supported_python_versions = "## Supported Python Versions\n\n"
supported_python_versions += "\n".join(
[f"* {v}" for v in about_info.supported_python_versions],
)
supported_python_versions += "\n"
md_list.append(supported_python_versions)

return "".join(md_list)
60 changes: 58 additions & 2 deletions singer_sdk/plugin_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import click
from jsonschema import Draft7Validator
from packaging.specifiers import SpecifierSet

from singer_sdk import about, metrics
from singer_sdk.cli import plugin_cli
Expand All @@ -36,6 +37,26 @@
from singer_sdk.mapper import PluginMapper

SDK_PACKAGE_NAME = "singer_sdk"
CHECK_SUPPORTED_PYTHON_VERSIONS = (
# unsupported versions
"2.7",
"3.0",
"3.1",
"3.2",
"3.3",
"3.4",
"3.5",
"3.6",
"3.7",
# current supported versions
"3.8",
"3.9",
"3.10",
"3.11",
# future supported versions
"3.12",
"3.13",
kgpayne marked this conversation as resolved.
Show resolved Hide resolved
)


JSONSchemaValidator = extend_validator_with_defaults(Draft7Validator)
Expand All @@ -44,7 +65,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 tap or target plugin. e.g. tap-foo
package_name: str | None = (
None # The package name of the plugin. e.g meltanolabs-tap-foo
)
kgpayne marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -171,14 +195,36 @@
version = "[could not be detected]"
return version

@staticmethod
def _get_supported_python_versions(package: str) -> list[str] | None:
"""Return the supported Python versions.

Args:
package: The package name.

Returns:
A list of supported Python versions.
"""
try:
supported_python_versions = []
package_metadata = metadata.metadata(package)
reported_python_versions = SpecifierSet(package_metadata["Requires-Python"])

Check warning on line 211 in singer_sdk/plugin_base.py

View check run for this annotation

Codecov / codecov/patch

singer_sdk/plugin_base.py#L211

Added line #L211 was not covered by tests
kgpayne marked this conversation as resolved.
Show resolved Hide resolved
for version in CHECK_SUPPORTED_PYTHON_VERSIONS:
if version in reported_python_versions:
supported_python_versions.append(version)
return supported_python_versions

Check warning on line 215 in singer_sdk/plugin_base.py

View check run for this annotation

Codecov / codecov/patch

singer_sdk/plugin_base.py#L214-L215

Added lines #L214 - L215 were not covered by tests
except metadata.PackageNotFoundError:
pass
kgpayne marked this conversation as resolved.
Show resolved Hide resolved
return None

@classmethod
def get_plugin_version(cls) -> str:
"""Return the package version number.

Returns:
The package version number.
"""
return cls._get_package_version(cls.name)
return cls._get_package_version(cls.package_name or cls.name)

@classmethod
def get_sdk_version(cls) -> str:
Expand All @@ -189,6 +235,15 @@
"""
return cls._get_package_version(SDK_PACKAGE_NAME)

@classmethod
def get_supported_python_versions(cls) -> list[str] | None:
"""Return the supported Python versions.

Returns:
A list of supported Python versions.
"""
return cls._get_supported_python_versions(cls.package_name or cls.name)

@classproperty
def plugin_version(cls) -> str: # noqa: N805
"""Get version.
Expand Down Expand Up @@ -325,6 +380,7 @@
description=cls.__doc__,
version=cls.get_plugin_version(),
sdk_version=cls.get_sdk_version(),
supported_python_versions=cls.get_supported_python_versions(),
capabilities=cls.capabilities,
settings=config_jsonschema,
)
Expand Down
1 change: 1 addition & 0 deletions tests/core/test_about.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def about_info() -> AboutInfo:
description="Example tap for Singer SDK",
version="0.1.1",
sdk_version="1.0.0",
supported_python_versions=["3.6", "3.7", "3.8"],
capabilities=[
TapCapabilities.CATALOG,
TapCapabilities.DISCOVER,
Expand Down
5 changes: 5 additions & 0 deletions tests/snapshots/about_format/json.snap.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
"description": "Example tap for Singer SDK",
"version": "0.1.1",
"sdk_version": "1.0.0",
"supported_python_versions": [
"3.6",
"3.7",
"3.8"
],
"capabilities": [
"catalog",
"discover",
Expand Down
6 changes: 6 additions & 0 deletions tests/snapshots/about_format/markdown.snap.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ Built with the [Meltano Singer SDK](https://sdk.meltano.com).
| api_key | True | None | API key for the tap to use. |

A full list of supported settings and capabilities is available by running: `tap-example --about`

## Supported Python Versions

* 3.6
* 3.7
* 3.8
1 change: 1 addition & 0 deletions tests/snapshots/about_format/text.snap.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ Name: tap-example
Description: Example tap for Singer SDK
Version: 0.1.1
SDK Version: 1.0.0
Supported Python Versions: ['3.6', '3.7', '3.8']
Capabilities: [catalog, discover, state]
Settings: {'properties': {'start_date': {'type': 'string', 'format': 'date-time', 'description': 'Start date for the tap to extract data from.'}, 'api_key': {'type': 'string', 'description': 'API key for the tap to use.'}}, 'required': ['api_key']}