Skip to content
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
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ trim_trailing_whitespace = true
[{,.}{j,J}ustfile]
indent_size = 4

[*.{just,proto,py,rst,ini,md}]
[*.{just,py,rst,ini,md}]
indent_size = 4

[*.py]
line_length = 120
multi_line_output = 3

[*.{css,html,js,json,jsx,sass,scss,svelte,ts,tsx,yml,yaml}]
[*.{css,html,js,json,jsx,proto,sass,scss,svelte,ts,tsx,yml,yaml}]
indent_size = 2

[*.md]
Expand Down
4 changes: 2 additions & 2 deletions crates/djls-django/src/django.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl DjangoProject {
pub fn setup(mut python: PythonProcess) -> Result<Self, ProjectError> {
let py = Python::setup(&mut python)?;

match check::GeoDjangoPrereqsRequest::execute(&mut python)?.result {
match commands::check::GeoDjangoPrereqsRequest::execute(&mut python)?.result {
Some(messages::response::Result::CheckGeodjangoPrereqs(response)) => {
if !response.passed {
eprintln!("Warning: GeoDjango detected but GDAL is not available.");
Expand All @@ -43,7 +43,7 @@ impl DjangoProject {
_ => Err(ProcessError::Response)?,
}

let response = django::GetProjectInfoRequest::execute(&mut python)?;
let response = commands::django::GetProjectInfoRequest::execute(&mut python)?;

let version = match response.result {
Some(messages::response::Result::DjangoGetProjectInfo(response)) => {
Expand Down
8 changes: 4 additions & 4 deletions crates/djls-ipc/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub trait IpcCommand: Default {
}
}

impl IpcCommand for v1::check::HealthRequest {
impl IpcCommand for v1::commands::check::HealthRequest {
fn into_request(&self) -> messages::Request {
messages::Request {
command: Some(messages::request::Command::CheckHealth(*self)),
Expand All @@ -29,7 +29,7 @@ impl IpcCommand for v1::check::HealthRequest {
}
}

impl IpcCommand for v1::check::GeoDjangoPrereqsRequest {
impl IpcCommand for v1::commands::check::GeoDjangoPrereqsRequest {
fn into_request(&self) -> messages::Request {
messages::Request {
command: Some(messages::request::Command::CheckGeodjangoPrereqs(*self)),
Expand All @@ -45,7 +45,7 @@ impl IpcCommand for v1::check::GeoDjangoPrereqsRequest {
}
}

impl IpcCommand for v1::python::GetEnvironmentRequest {
impl IpcCommand for v1::commands::python::GetEnvironmentRequest {
fn into_request(&self) -> messages::Request {
messages::Request {
command: Some(messages::request::Command::PythonGetEnvironment(*self)),
Expand All @@ -61,7 +61,7 @@ impl IpcCommand for v1::python::GetEnvironmentRequest {
}
}

impl IpcCommand for v1::django::GetProjectInfoRequest {
impl IpcCommand for v1::commands::django::GetProjectInfoRequest {
fn into_request(&self) -> messages::Request {
messages::Request {
command: Some(messages::request::Command::DjangoGetProjectInfo(*self)),
Expand Down
2 changes: 1 addition & 1 deletion crates/djls-ipc/src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl PythonProcess {
) -> Result<(), ProcessError> {
let request = messages::Request {
command: Some(messages::request::Command::CheckHealth(
check::HealthRequest {},
commands::check::HealthRequest {},
)),
};

Expand Down
12 changes: 6 additions & 6 deletions crates/djls-ipc/src/proto.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
pub mod v1 {
pub mod messages {
include!(concat!(env!("OUT_DIR"), "/djls.v1.messages.rs"));
}

pub mod check {
include!(concat!(env!("OUT_DIR"), "/djls.v1.check.rs"));
pub mod commands {
include!(concat!(env!("OUT_DIR"), "/djls.v1.commands.rs"));
}

pub mod django {
include!(concat!(env!("OUT_DIR"), "/djls.v1.django.rs"));
}

pub mod messages {
include!(concat!(env!("OUT_DIR"), "/djls.v1.messages.rs"));
}

pub mod python {
include!(concat!(env!("OUT_DIR"), "/djls.v1.python.rs"));
}
Expand Down
2 changes: 1 addition & 1 deletion crates/djls-python/src/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub struct Python {

impl Python {
pub fn setup(python: &mut PythonProcess) -> Result<Self, PythonError> {
let response = python::GetEnvironmentRequest::execute(python)?;
let response = commands::python::GetEnvironmentRequest::execute(python)?;
match response.result {
Some(messages::response::Result::PythonGetEnvironment(response)) => response
.python
Expand Down
15 changes: 0 additions & 15 deletions proto/v1/check.proto

This file was deleted.

35 changes: 35 additions & 0 deletions proto/v1/commands.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
syntax = "proto3";

package djls.v1.commands;

import "v1/django.proto";
import "v1/python.proto";

message Check {
message HealthRequest {}
message HealthResponse {
bool passed = 1;
optional string error = 2;
}

message GeoDjangoPrereqsRequest {}
message GeoDjangoPrereqsResponse {
bool passed = 1;
optional string error = 2;
}
}

message Python {
message GetEnvironmentRequest {}
message GetEnvironmentResponse {
python.Python python = 1;
}
}

message Django {
message GetProjectInfoRequest {}
message GetProjectInfoResponse {
django.Project project = 1;
}
}

8 changes: 0 additions & 8 deletions proto/v1/django.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@ syntax = "proto3";

package djls.v1.django;

// models
message Project {
string version = 3;
}

// commands
message GetProjectInfoRequest {}

message GetProjectInfoResponse {
Project project = 1;
}
20 changes: 9 additions & 11 deletions proto/v1/messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,23 @@ syntax = "proto3";

package djls.v1.messages;

import "v1/check.proto";
import "v1/django.proto";
import "v1/python.proto";
import "v1/commands.proto";

message Request {
oneof command {
check.HealthRequest check__health = 1;
check.GeoDjangoPrereqsRequest check__geodjango_prereqs = 2;
python.GetEnvironmentRequest python__get_environment = 1000;
django.GetProjectInfoRequest django__get_project_info = 2000;
commands.Check.HealthRequest check__health = 1;
commands.Check.GeoDjangoPrereqsRequest check__geodjango_prereqs = 2;
commands.Python.GetEnvironmentRequest python__get_environment = 1000;
commands.Django.GetProjectInfoRequest django__get_project_info = 2000;
}
}

message Response {
oneof result {
check.HealthResponse check__health = 1;
check.GeoDjangoPrereqsResponse check__geodjango_prereqs = 2;
python.GetEnvironmentResponse python__get_environment = 1000;
django.GetProjectInfoResponse django__get_project_info = 2000;
commands.Check.HealthResponse check__health = 1;
commands.Check.GeoDjangoPrereqsResponse check__geodjango_prereqs = 2;
commands.Python.GetEnvironmentResponse python__get_environment = 1000;
commands.Django.GetProjectInfoResponse django__get_project_info = 2000;
Error error = 9000;
}
}
Expand Down
7 changes: 0 additions & 7 deletions proto/v1/python.proto
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,3 @@ message Package {
repeated string dist_requires = 6;
optional string dist_requires_python = 7;
}

// commands
message GetEnvironmentRequest {}

message GetEnvironmentResponse {
Python python = 1;
}
34 changes: 18 additions & 16 deletions python/djls/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from django.apps import apps
from google.protobuf.message import Message

from .proto.v1 import check_pb2
from .proto.v1 import commands_pb2
from .proto.v1 import django_pb2
from .proto.v1 import messages_pb2
from .proto.v1 import python_pb2
Expand Down Expand Up @@ -87,15 +87,17 @@ async def wrapper(request: T) -> R:
return decorator


@proto_handler(check_pb2.HealthRequest)
async def check__health(_request: check_pb2.HealthRequest) -> check_pb2.HealthResponse:
return check_pb2.HealthResponse(passed=True)
@proto_handler(commands_pb2.Check.HealthRequest)
async def check__health(
_request: commands_pb2.Check.HealthRequest,
) -> commands_pb2.Check.HealthResponse:
return commands_pb2.Check.HealthResponse(passed=True)


@proto_handler(check_pb2.GeoDjangoPrereqsRequest)
@proto_handler(commands_pb2.Check.GeoDjangoPrereqsRequest)
async def check__geodjango_prereqs(
request: check_pb2.GeoDjangoPrereqsRequest,
) -> check_pb2.GeoDjangoPrereqsResponse:
request: commands_pb2.Check.GeoDjangoPrereqsRequest,
) -> commands_pb2.Check.GeoDjangoPrereqsResponse:
has_geodjango = apps.is_installed("django.contrib.gis")

try:
Expand All @@ -106,15 +108,15 @@ async def check__geodjango_prereqs(
except FileNotFoundError:
gdal_is_installed = False

return check_pb2.GeoDjangoPrereqsResponse(
return commands_pb2.Check.GeoDjangoPrereqsResponse(
passed=(not has_geodjango) or gdal_is_installed
)


@proto_handler(python_pb2.GetEnvironmentRequest)
@proto_handler(commands_pb2.Python.GetEnvironmentRequest)
async def python__get_environment(
_request: python_pb2.GetEnvironmentRequest,
) -> python_pb2.GetEnvironmentResponse:
_request: commands_pb2.Python.GetEnvironmentRequest,
) -> commands_pb2.Python.GetEnvironmentResponse:
packages = {}
for dist in importlib.metadata.distributions():
try:
Expand Down Expand Up @@ -158,7 +160,7 @@ async def python__get_environment(
serial=sys.version_info.serial,
)

return python_pb2.GetEnvironmentResponse(
return commands_pb2.Python.GetEnvironmentResponse(
python=python_pb2.Python(
os=python_pb2.Os(environ={k: v for k, v in os.environ.items()}),
site=python_pb2.Site(packages=packages),
Expand Down Expand Up @@ -193,10 +195,10 @@ async def python__get_environment(
)


@proto_handler(django_pb2.GetProjectInfoRequest)
@proto_handler(commands_pb2.Django.GetProjectInfoRequest)
async def django__get_project_info(
_request: django_pb2.GetProjectInfoRequest,
) -> django_pb2.GetProjectInfoResponse:
return django_pb2.GetProjectInfoResponse(
_request: commands_pb2.Django.GetProjectInfoRequest,
) -> commands_pb2.Django.GetProjectInfoResponse:
return commands_pb2.Django.GetProjectInfoResponse(
project=django_pb2.Project(version=django.__version__)
)
46 changes: 0 additions & 46 deletions python/djls/proto/v1/check_pb2.py

This file was deleted.

33 changes: 0 additions & 33 deletions python/djls/proto/v1/check_pb2.pyi

This file was deleted.

Loading
Loading