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

fix(setup): Add twilio and nexmo as optional dependency #87

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
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
16 changes: 14 additions & 2 deletions phone_verify/backends/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,23 @@ def get_sms_backend(phone_number):
if not backend:

if settings.PHONE_VERIFICATION.get("BACKEND", None):
backend_import = settings.PHONE_VERIFICATION["BACKEND"]
backend_import_path = settings.PHONE_VERIFICATION["BACKEND"]
else:
raise ImproperlyConfigured(
"Please specify BACKEND in PHONE_VERIFICATION within your settings"
)

backend_cls = import_string(backend_import)
try:
backend_cls = import_string(backend_import_path)
except ImportError as e:
if not any(provider in backend_import_path.lower() for provider in ['twilio', 'nexmo']):
# Error for custom backends
raise RuntimeError(f"Failed to import the specified backend: {backend_import_path}. Ensure the module is installed and properly configured.") from e

# Extract the module name (e.g., 'twilio' or 'nexmo') for a more meaningful error message
dependency_name = backend_import_path.split(".")[-2]

# Raise an error with the correct dependency name
raise RuntimeError(f"{dependency_name.capitalize()} backend is not installed. Please install '{dependency_name}' to use this provider.") from e

return backend_cls(**settings.PHONE_VERIFICATION["OPTIONS"])
18 changes: 14 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,23 @@
install_requires=[
"django>=2.1.5",
"djangorestframework>=3.9.0",
"PyJWT>=1.7.1",
"python-dotenv>=0.10.0",
"PyJWT>=2.6.0",
"python-dotenv>=0.21.1",
"phonenumbers>=8.10.2",
"django-phonenumber-field>=2.1.0",
"twilio>=6.21.0",
"nexmo>=2.4.0",
],
extras_require={
"twilio": ["twilio"],
"nexmo": ["nexmo"],
"all": ["twilio", "nexmo"],
},
project_urls={
"Documentation": "#TBD",
"Changelog": "#TBD",
"Code": "https://github.com/CuriousLearner/django-phone-verify",
"Tracker": "https://github.com/CuriousLearner/django-phone-verify/issues",
"Funding": "#TBD"
},
classifiers=[
"Environment :: Web Environment",
"Development Status :: 5 - Production/Stable",
Expand Down
Loading