From 510cbed61c93ae565254ce70a1e789966a2433fd Mon Sep 17 00:00:00 2001 From: Debanjum Date: Sun, 23 Mar 2025 08:31:41 +0530 Subject: [PATCH] Make google auth package dependency explicit to simplify code Previously google auth library was explicitly installed only for the cloud variant of Khoj to minimize packages installed for non production use-cases. But it was being implicitly installed as a dependency of an explicit package in the default installation anyway. Making the dependency on google auth package explicit simplifies the conditional import of google auth in code while not incurring any additional cost in terms of space or complexity. --- pyproject.toml | 2 +- src/khoj/routers/auth.py | 7 ++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 084bc65e..a012f158 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -89,6 +89,7 @@ dependencies = [ "anthropic == 0.49.0", "docx2txt == 0.8", "google-genai == 1.5.0", + "google-auth ~= 2.23.3", "pyjson5 == 1.6.7", "resend == 1.0.1", "email-validator == 2.2.0", @@ -107,7 +108,6 @@ khoj = "khoj.main:run" [project.optional-dependencies] prod = [ "gunicorn == 22.0.0", - "google-auth == 2.23.3", "stripe == 7.3.0", "twilio == 8.11", "boto3 >= 1.34.57", diff --git a/src/khoj/routers/auth.py b/src/khoj/routers/auth.py index 00088d00..838cfa48 100644 --- a/src/khoj/routers/auth.py +++ b/src/khoj/routers/auth.py @@ -43,12 +43,9 @@ class MagicLinkForm(BaseModel): if not state.anonymous_mode: missing_requirements = [] from authlib.integrations.starlette_client import OAuth, OAuthError + from google.auth.transport import requests as google_requests + from google.oauth2 import id_token - try: - from google.auth.transport import requests as google_requests - from google.oauth2 import id_token - except ImportError: - missing_requirements += ["Install the Khoj production package with `pip install khoj[prod]`"] if not os.environ.get("RESEND_API_KEY") and ( not os.environ.get("GOOGLE_CLIENT_ID") or not os.environ.get("GOOGLE_CLIENT_SECRET") ):