mirror of
https://github.com/joshuadavidthomas/django-language-server.git
synced 2025-09-13 13:56:25 +00:00
abstract zipapp to separate dedicated submodule (#215)
Some checks are pending
test / Python , Django () (push) Blocked by required conditions
lint / pre-commit (push) Waiting to run
lint / rustfmt (push) Waiting to run
lint / clippy (push) Waiting to run
lint / cargo-check (push) Waiting to run
release / build (push) Waiting to run
release / test (push) Waiting to run
release / release (push) Blocked by required conditions
test / generate-matrix (push) Waiting to run
test / tests (push) Blocked by required conditions
zizmor 🌈 / zizmor latest via PyPI (push) Waiting to run
Some checks are pending
test / Python , Django () (push) Blocked by required conditions
lint / pre-commit (push) Waiting to run
lint / rustfmt (push) Waiting to run
lint / clippy (push) Waiting to run
lint / cargo-check (push) Waiting to run
release / build (push) Waiting to run
release / test (push) Waiting to run
release / release (push) Blocked by required conditions
test / generate-matrix (push) Waiting to run
test / tests (push) Blocked by required conditions
zizmor 🌈 / zizmor latest via PyPI (push) Waiting to run
This commit is contained in:
parent
d99c96d6b6
commit
007a009d33
7 changed files with 64 additions and 57 deletions
|
@ -69,7 +69,8 @@ def handle_request(request: dict[str, Any]) -> DjlsResponse:
|
|||
return DjlsResponse(ok=True, data=get_installed_templatetags())
|
||||
|
||||
elif query == Query.DJANGO_INIT:
|
||||
return DjlsResponse(ok=True, data=initialize_django())
|
||||
success, error = initialize_django()
|
||||
return DjlsResponse(ok=success, data=None, error=error)
|
||||
|
||||
return DjlsResponse(ok=False, error=f"Unhandled query type: {query}")
|
||||
|
||||
|
|
|
@ -90,13 +90,8 @@ def get_installed_templatetags() -> TemplateTagQueryData:
|
|||
return TemplateTagQueryData(templatetags=templatetags)
|
||||
|
||||
|
||||
@dataclass
|
||||
class DjangoInitQueryData:
|
||||
success: bool
|
||||
message: str | None = None
|
||||
|
||||
|
||||
def initialize_django() -> DjangoInitQueryData:
|
||||
def initialize_django() -> tuple[bool, str | None]:
|
||||
"""Initialize Django and return (success, error_message)."""
|
||||
import os
|
||||
import django
|
||||
from django.apps import apps
|
||||
|
@ -122,9 +117,9 @@ def initialize_django() -> DjangoInitQueryData:
|
|||
current_path = current_path.parent
|
||||
|
||||
if not manage_py:
|
||||
return DjangoInitQueryData(
|
||||
success=False,
|
||||
message="Could not find manage.py or DJANGO_SETTINGS_MODULE not set",
|
||||
return (
|
||||
False,
|
||||
"Could not find manage.py or DJANGO_SETTINGS_MODULE not set",
|
||||
)
|
||||
|
||||
# Add project directory to sys.path
|
||||
|
@ -163,12 +158,10 @@ def initialize_django() -> DjangoInitQueryData:
|
|||
if not apps.ready:
|
||||
django.setup()
|
||||
|
||||
return DjangoInitQueryData(
|
||||
success=True, message="Django initialized successfully"
|
||||
)
|
||||
return True, None
|
||||
|
||||
except Exception as e:
|
||||
return DjangoInitQueryData(success=False, message=str(e))
|
||||
return False, str(e)
|
||||
|
||||
|
||||
QueryData = PythonEnvironmentQueryData | TemplateTagQueryData | DjangoInitQueryData
|
||||
QueryData = PythonEnvironmentQueryData | TemplateTagQueryData
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue