Skip to content

Commit

Permalink
fix: python separate datatypes
Browse files Browse the repository at this point in the history
  • Loading branch information
spicyfalafel committed Sep 23, 2024
1 parent fe7f1c0 commit 384aad4
Show file tree
Hide file tree
Showing 146 changed files with 174 additions and 161 deletions.
9 changes: 9 additions & 0 deletions dev/user.clj
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,12 @@
)

:rcf)

(comment
(sdk/generate! :python
"http://localhost:8765/api/sdk/fhir-packages"
{:output-dir "out"
:auth-token "YmFzaWM6c2VjcmV0"
:exit (fn [_] nil)})

:rcf)
38 changes: 21 additions & 17 deletions src/aidbox_sdk/generator/python.clj
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@
[x]
(str/replace x #"[\.#]" "-"))

(defn datatypes-file-path []
(io/file "base/__init__.py"))
(defn datatypes-file-path [ir-schema]
(io/file "base/"
(str (->pascal-case (or (:name ir-schema)
(url->resource-name (:url ir-schema)))) ".py")))

(defn resource-file-path [ir-schema]
(io/file (package->directory (:package ir-schema))
Expand Down Expand Up @@ -150,13 +152,13 @@
base-class-name (when-not (str/blank? base-class)
(uppercase-first-letter base-class))]
(str
(when (seq inner-classes)
(str (str/join "\n\n" inner-classes) "\n\n"))
(when (seq inner-classes)
(str (str/join "\n\n" inner-classes) "\n\n"))

"class " class-name' "(" base-class-name "):"
(when-not (str/blank? properties)
"\n")
properties)))
"class " class-name' "(" base-class-name "):"
"\n"
properties
(when-not (seq properties) " pass"))))

(defn generate-module
[& {:keys [deps classes]
Expand All @@ -174,15 +176,17 @@
(defrecord PythonCodeGenerator []
CodeGenerator
(generate-datatypes [_ ir-schemas]
[{:path (datatypes-file-path)
:content (generate-module
:deps [{:module "typing" :members ["Optional" "List"]}
{:module "pydantic" :members ["*"]}]
:classes (map (fn [ir-schema]
(generate-class ir-schema
(map generate-class (:backbone-elements ir-schema))
))
ir-schemas))}])
(let [ir-schemas (sort-by :base ir-schemas)]
(map (fn [ir-schema]
{:path (datatypes-file-path ir-schema)
:content (generate-module
:deps (concat
[{:module "future" :members ["annotations"]}
{:module "typing" :members ["Optional" "List"]}
{:module "pydantic" :members ["*"]}]
(map (fn [d] {:module (str "." d) :members [d]}) (:deps ir-schema)))
:classes [(generate-class ir-schema (map generate-class (:backbone-elements ir-schema)))])})
ir-schemas)))

(generate-resource-module [_ ir-schema]
{:path (resource-file-path ir-schema)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/aidbox_sdk/snapshots/python/hl7-fhir-r4-core/Basic.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion test/aidbox_sdk/snapshots/python/hl7-fhir-r4-core/Claim.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 384aad4

Please sign in to comment.