Skip to content

Commit

Permalink
allow module configuration via trust cfg by fixing proper imports in
Browse files Browse the repository at this point in the history
python server and client
  • Loading branch information
wkarwacki committed Jan 11, 2025
1 parent 7244761 commit 57b2da2
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/lib/gen/python/client/gen_python_http_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ impl Gen for GenPythonHttpClient {
.unique()
.collect::<Vec<_>>()
.join("\n");
let dto = handlebars.render_template(dto_template.as_str(), &json!({"key": dto_name(def_name, &self.lang()), "val": def, "formLike": form_like})).unwrap();
let dto = handlebars.render_template(dto_template.as_str(), &json!({"key": dto_name(def_name, &self.lang()), "val": def, "formLike": form_like, "mod": &self.lang().module()})).unwrap();
({
let dto_path_str = dto_path.as_str();
format!("{out_dir}/{dto_path_str}").into()
Expand Down Expand Up @@ -418,7 +418,7 @@ impl Gen for GenPythonHttpClient {
let service = handlebars
.render_template(
service_template.as_str(),
&json!({"feature": self.lang.feature.clone(), "ops": &pkg.ops, "useNamespace": &pkg.use_namespace}),
&json!({"feature": self.lang.feature.clone(), "ops": &pkg.ops, "useNamespace": &pkg.use_namespace, "mod": &self.lang().module()}),
)
.unwrap();
(
Expand Down
2 changes: 1 addition & 1 deletion src/lib/gen/python/client/templates/dtoFile.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ from enum import Enum
from pydantic import Field, model_validator
from typing import Annotated, Any, ClassVar, Literal

from trust import Dto
from {{mod}} import Dto

{{>dto key=key val=val formLike=formLike tl=true}}
3 changes: 2 additions & 1 deletion src/lib/gen/python/client/templates/service.hbs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from io import BufferedReader
from pydantic import TypeAdapter
from trust import client
from typing import Any, Generator

from {{mod}} import client

class {{to_pascal_case feature}}Service:
{{#each ops}}{{#each this}}
def {{to_snake_case this.name}}(self{{#if this.req}}, {{#if this.req.path}}{{fmtName (fmtType this.req)}}: {{#with (resolveIfMappedType (fmtClass this.req.path))}}{{fmtClass this}}{{else}}{{fmtType this.req (to_pascal_case this.name)}}{{/with}}{{else if (or (eq this.req.type "obj") (eq this.req.type "seq") (eq this.req.type "map"))}}{{fmtName (add this.name "Req")}}: {{>dtoName val=(fmtClass (add this.name "Req"))}}{{else}}request: {{fmtType this.req}}{{/if}}{{#if (eq this.req.form "multipart/form-data")}}, file: BufferedReader{{/if}}{{/if}}{{#if this.params}}{{#each (sortOptionalsLast this.params)}}, {{to_snake_case this.name}}: {{#if (hasKey this "default")}}{{#if (eq this.loc "header")}}{{fmtOpt "str"}}{{else}}{{fmtOpt (fmtType this)}}{{/if}} = None{{else}}{{#if (eq this.loc "header")}}str{{else}}{{fmtType this}}{{/if}}{{/if}}{{/each}}{{/if}}) -> {{#if this.res}}{{#if (eq this.res.carrier "stream")}}Generator[{{fmtType this.res}}, None, None]{{else}}{{#if this.res.path}}{{#with (resolveIfMappedType (fmtClass this.res.path))}}{{fmtClass this}}{{else}}{{fmtType this.res (to_pascal_case this.name)}}{{/with}}{{else if (or (eq this.res.type "obj") (eq this.res.type "seq") (eq this.res.type "map"))}}{{>dtoName val=(fmtClass (add this.name "Res"))}}{{else}}{{fmtType this.res}}{{/if}}{{/if}}{{else}}None{{/if}}:
Expand Down
2 changes: 1 addition & 1 deletion src/lib/gen/python/server/gen_python_http_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ impl Gen for GenPythonHttpServer {
.unique()
.collect::<Vec<_>>()
.join("\n");
let dto = handlebars.render_template(dto_template.as_str(), &json!({"key": dto_name(def_name, &self.lang()), "val": def, "formLike": form_like})).unwrap();
let dto = handlebars.render_template(dto_template.as_str(), &json!({"key": dto_name(def_name, &self.lang()), "val": def, "formLike": form_like, "mod": &self.lang().module()})).unwrap();
({
let dto_path_str = dto_path.as_str();
format!("{out_dir}/{dto_path_str}").into()
Expand Down
2 changes: 1 addition & 1 deletion src/lib/gen/python/server/templates/dtoFile.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ from fastapi import File, Form, UploadFile
from pydantic import Field
from typing import Annotated, Any, ClassVar, Literal

from trust import Dto
from {{mod}} import Dto

{{>dto key=key val=val formLike=formLike tl=true}}

0 comments on commit 57b2da2

Please sign in to comment.