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

refactor!: Make PyJWT and cryptography dependencies optional #2525

Merged
merged 4 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 4 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 11 additions & 8 deletions pyproject.toml
WillDaSilva marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ python = ">=3.8"
backoff = { version = ">=2.0.0", python = "<4" }
backports-datetime-fromisoformat = { version = ">=2.0.1", python = "<3.11" }
click = "~=8.0"
cryptography = ">=3.4.6"
fs = ">=2.4.16"
importlib-metadata = {version = "<9.0.0", python = "<3.12"}
importlib-resources = {version = ">=5.12.0,!=6.2.0,!=6.3.0,!=6.3.1", python = "<3.9"}
Expand All @@ -52,7 +51,6 @@ jsonpath-ng = ">=1.5.3"
jsonschema = ">=4.16.0"
packaging = ">=23.1"
pendulum = ">=2.1.0,<4"
PyJWT = "~=2.4"
python-dateutil = ">=2.8.2"
python-dotenv = ">=0.20"
PyYAML = ">=6.0"
Expand Down Expand Up @@ -93,10 +91,15 @@ pytest-durations = {version = ">=1.2.0", optional = true}
# installed as optional 'faker' extra
faker = {version = ">=22.5,<27.0", optional = true}

# Crypto extras
cryptography = { version = ">=3.4.6", optional = true }
PyJWT = { version = "~=2.4", optional = true }

[tool.poetry.extras]
# TODO: Add 'cryptography' and 'PyJWT' to the 'jwt' when we want to remove them
# from the main dependencies
jwt = []
jwt = [
"cryptography",
"PyJWT",
]
docs = [
"furo",
"myst-parser",
Expand Down Expand Up @@ -273,9 +276,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
"jsonpath_ng.*",
"pyarrow.*", # TODO: Remove when https://github.com/apache/arrow/issues/32609 if implemented and released
"joblib.*", # TODO: Remove when https://github.com/joblib/joblib/issues/1516 is shipped
"jsonpath_ng.*", # TODO: Remove when https://github.com/h2non/jsonpath-ng/issues/152 is implemented and released
"pyarrow.*", # TODO: Remove when https://github.com/apache/arrow/issues/32609 if implemented and released
]

[tool.poetry-dynamic-versioning]
Expand Down
13 changes: 9 additions & 4 deletions singer_sdk/authenticators.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,13 +568,18 @@ def oauth_request_payload(self) -> dict:
Payload object for OAuth.

Raises:
RuntimeError: If the JWT dependencies are not installed.
ValueError: If the private key is not set.
"""
import jwt # noqa: PLC0415
from cryptography.hazmat.backends import default_backend # noqa: PLC0415
from cryptography.hazmat.primitives import serialization # noqa: PLC0415
try:
import jwt # noqa: PLC0415
from cryptography.hazmat.backends import default_backend # noqa: PLC0415
from cryptography.hazmat.primitives import serialization # noqa: PLC0415
except ModuleNotFoundError as ex: # pragma: no cover
msg = "Install singer-sdk[jwt] to use OAuthJWTAuthenticator."
raise RuntimeError(msg) from ex

if not self.private_key:
if not self.private_key: # pragma: no cover
msg = "Missing 'private_key' property for OAuth payload."
raise ValueError(msg)

Expand Down
Loading