diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..0047243 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,23 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "pip" # See documentation for possible values + directory: "/" # Location of package manifests + schedule: + interval: "weekly" + groups: + pip: + patterns: + - '*' + - package-ecosystem: "github-actions" # See documentation for possible values + directory: ".github/workflows" # Location of package manifests + schedule: + interval: "weekly" + groups: + github: + patterns: + - '*' diff --git a/.github/workflows/autoformat-and-lint.yml b/.github/workflows/autoformat-and-lint.yml new file mode 100644 index 0000000..c27baf7 --- /dev/null +++ b/.github/workflows/autoformat-and-lint.yml @@ -0,0 +1,45 @@ +name: Autoformat and Lint + +on: + pull_request: + push: + branches: + - main + merge_group: + +jobs: + autoformat-and-lint: + name: Autoformat and Lint + if: github.actor != 'dependabot[bot]' + runs-on: ubuntu-latest + permissions: + contents: write + + steps: + - name: 🛎 Checkout + uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} + token: ${{ secrets.WORKFLOW_COMMIT_TOKEN }} + + - name: 🐍 Setup Python + uses: actions/setup-python@v5 + with: + python-version: '3.12' + cache: 'pip' + + - name: 📦 Install Hatch + run: pip install hatch + + - name: 📝 Format Code + run: hatch fmt -f + + - name: ✅ Commit code format changes + uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: "Autoformat code" + skip_fetch: true + skip_checkout: true + + - name: 🔍 Lint + run: hatch fmt --check \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..0a909bb --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,36 @@ +name: Build + +on: + push: + branches: + - main + +jobs: + build: + name: Build + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: 🐍 Setup Python + uses: actions/setup-python@v4 + with: + python-version: '3.12' + cache: 'pip' + + - name: 📦 Install dependencies + run: pip install . + + - name: 🛠️ Build + run: ./vbl_aquarium_build + + - name: 📤 PR changes + uses: peter-evans/create-pull-request@v6 + with: + token: ${{ secrets.PR_TOKEN }} + commit-message: "Build Models" + title: "chore: Build Models" + branch: "build-models" + delete-branch: true \ No newline at end of file diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml new file mode 100644 index 0000000..2fd479e --- /dev/null +++ b/.github/workflows/codeql-analysis.yml @@ -0,0 +1,51 @@ +# For most projects, this workflow file will not need changing; you simply need +# to commit it to your repository. +# +# You may wish to alter this file to override the set of languages analyzed, +# or to provide custom queries or build logic. +# +# ******** NOTE ******** +# We have attempted to detect the languages in your repository. Please check +# the `language` matrix defined below to confirm you have the correct set of +# supported CodeQL languages. +# +name: "CodeQL" + +on: + push: + branches: [ "main" ] + schedule: + - cron: '32 21 * * 1' + +concurrency: + group: "codeql" + cancel-in-progress: true + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'python' ] + # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] + # Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + # Initializes the CodeQL tools for scanning. + - name: Initialize CodeQL + uses: github/codeql-action/init@v3 + with: + languages: ${{ matrix.language }} + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v3 diff --git a/.github/workflows/dependency-review.yml b/.github/workflows/dependency-review.yml new file mode 100644 index 0000000..f0b0eb0 --- /dev/null +++ b/.github/workflows/dependency-review.yml @@ -0,0 +1,14 @@ +name: 'Dependency Review' +on: [pull_request] + +permissions: + contents: read + +jobs: + dependency-review: + runs-on: ubuntu-latest + steps: + - name: 'Checkout Repository' + uses: actions/checkout@v4 + - name: 'Dependency Review' + uses: actions/dependency-review-action@v4 \ No newline at end of file diff --git a/models/csharp/dock/BucketModel.cs b/models/csharp/dock/BucketModel.cs index 7d44755..6653e97 100644 --- a/models/csharp/dock/BucketModel.cs +++ b/models/csharp/dock/BucketModel.cs @@ -1,6 +1,6 @@ - + public struct BucketModel { public string Token; diff --git a/models/csharp/dock/LoadModel.cs b/models/csharp/dock/LoadModel.cs index be48b99..34e746f 100644 --- a/models/csharp/dock/LoadModel.cs +++ b/models/csharp/dock/LoadModel.cs @@ -1,6 +1,6 @@ - + public struct LoadModel { public string Bucket; diff --git a/models/csharp/dock/SaveManagerModel.cs b/models/csharp/dock/SaveManagerModel.cs index e9fad58..bed26d9 100644 --- a/models/csharp/dock/SaveManagerModel.cs +++ b/models/csharp/dock/SaveManagerModel.cs @@ -1,6 +1,6 @@ - + public struct SaveManagerModel { public string Bucket; diff --git a/models/csharp/dock/SaveModel.cs b/models/csharp/dock/SaveModel.cs index ff51789..77bf56c 100644 --- a/models/csharp/dock/SaveModel.cs +++ b/models/csharp/dock/SaveModel.cs @@ -1,6 +1,6 @@ - + public struct SaveModel { public string Bucket; diff --git a/models/csharp/ephys_link/AngularResponse.cs b/models/csharp/ephys_link/AngularResponse.cs index 0bf06d5..ee234c7 100644 --- a/models/csharp/ephys_link/AngularResponse.cs +++ b/models/csharp/ephys_link/AngularResponse.cs @@ -1,6 +1,6 @@ using UnityEngine; - + public struct AngularResponse { public Vector3 Angles; diff --git a/models/csharp/ephys_link/BooleanStateResponse.cs b/models/csharp/ephys_link/BooleanStateResponse.cs index a424d5f..9f7a41d 100644 --- a/models/csharp/ephys_link/BooleanStateResponse.cs +++ b/models/csharp/ephys_link/BooleanStateResponse.cs @@ -1,6 +1,6 @@ - + public struct BooleanStateResponse { public bool State; diff --git a/models/csharp/ephys_link/CanWriteRequest.cs b/models/csharp/ephys_link/CanWriteRequest.cs index 83a09ee..e208e7b 100644 --- a/models/csharp/ephys_link/CanWriteRequest.cs +++ b/models/csharp/ephys_link/CanWriteRequest.cs @@ -1,6 +1,6 @@ - + public struct CanWriteRequest { public string ManipulatorId; diff --git a/models/csharp/ephys_link/DriveToDepthRequest.cs b/models/csharp/ephys_link/DriveToDepthRequest.cs index 7507066..5874510 100644 --- a/models/csharp/ephys_link/DriveToDepthRequest.cs +++ b/models/csharp/ephys_link/DriveToDepthRequest.cs @@ -1,6 +1,6 @@ - + public struct DriveToDepthRequest { public string ManipulatorId; diff --git a/models/csharp/ephys_link/DriveToDepthResponse.cs b/models/csharp/ephys_link/DriveToDepthResponse.cs index b6b672b..4de0e32 100644 --- a/models/csharp/ephys_link/DriveToDepthResponse.cs +++ b/models/csharp/ephys_link/DriveToDepthResponse.cs @@ -1,6 +1,6 @@ - + public struct DriveToDepthResponse { public float Depth; diff --git a/models/csharp/ephys_link/GetManipulatorsResponse.cs b/models/csharp/ephys_link/GetManipulatorsResponse.cs index d8180cc..5166305 100644 --- a/models/csharp/ephys_link/GetManipulatorsResponse.cs +++ b/models/csharp/ephys_link/GetManipulatorsResponse.cs @@ -1,6 +1,6 @@ using UnityEngine; - + public struct GetManipulatorsResponse { public string[] Manipulators; diff --git a/models/csharp/ephys_link/GotoPositionRequest.cs b/models/csharp/ephys_link/GotoPositionRequest.cs index 4caa192..6377d49 100644 --- a/models/csharp/ephys_link/GotoPositionRequest.cs +++ b/models/csharp/ephys_link/GotoPositionRequest.cs @@ -1,6 +1,6 @@ using UnityEngine; - + public struct GotoPositionRequest { public string ManipulatorId; diff --git a/models/csharp/ephys_link/InsideBrainRequest.cs b/models/csharp/ephys_link/InsideBrainRequest.cs index a21c15c..aa52ce7 100644 --- a/models/csharp/ephys_link/InsideBrainRequest.cs +++ b/models/csharp/ephys_link/InsideBrainRequest.cs @@ -1,6 +1,6 @@ - + public struct InsideBrainRequest { public string ManipulatorId; diff --git a/models/csharp/ephys_link/PositionalResponse.cs b/models/csharp/ephys_link/PositionalResponse.cs index 24161c2..5fead59 100644 --- a/models/csharp/ephys_link/PositionalResponse.cs +++ b/models/csharp/ephys_link/PositionalResponse.cs @@ -1,6 +1,6 @@ using UnityEngine; - + public struct PositionalResponse { public Vector4 Position; diff --git a/models/csharp/ephys_link/ShankCountResponse.cs b/models/csharp/ephys_link/ShankCountResponse.cs index e453dc8..c730edb 100644 --- a/models/csharp/ephys_link/ShankCountResponse.cs +++ b/models/csharp/ephys_link/ShankCountResponse.cs @@ -1,6 +1,6 @@ - + public struct ShankCountResponse { public int ShankCount; diff --git a/models/csharp/generic/BoolData.cs b/models/csharp/generic/BoolData.cs index fddfa2e..03d29fe 100644 --- a/models/csharp/generic/BoolData.cs +++ b/models/csharp/generic/BoolData.cs @@ -1,6 +1,6 @@ - + public struct BoolData { public string ID; diff --git a/models/csharp/generic/BoolList.cs b/models/csharp/generic/BoolList.cs index 2172531..c38bbfe 100644 --- a/models/csharp/generic/BoolList.cs +++ b/models/csharp/generic/BoolList.cs @@ -1,6 +1,6 @@ - + public struct BoolList { public string ID; diff --git a/models/csharp/generic/ColorData.cs b/models/csharp/generic/ColorData.cs index bf63514..afc24ad 100644 --- a/models/csharp/generic/ColorData.cs +++ b/models/csharp/generic/ColorData.cs @@ -1,6 +1,6 @@ using UnityEngine; - + public struct ColorData { public string ID; diff --git a/models/csharp/generic/ColorList.cs b/models/csharp/generic/ColorList.cs index 7fd53fe..b3e44db 100644 --- a/models/csharp/generic/ColorList.cs +++ b/models/csharp/generic/ColorList.cs @@ -1,6 +1,6 @@ using UnityEngine; - + public struct ColorList { public string ID; diff --git a/models/csharp/generic/FloatData.cs b/models/csharp/generic/FloatData.cs index 285261d..9ae5d8c 100644 --- a/models/csharp/generic/FloatData.cs +++ b/models/csharp/generic/FloatData.cs @@ -1,6 +1,6 @@ - + public struct FloatData { public string ID; diff --git a/models/csharp/generic/FloatList.cs b/models/csharp/generic/FloatList.cs index c81452e..2ce045c 100644 --- a/models/csharp/generic/FloatList.cs +++ b/models/csharp/generic/FloatList.cs @@ -1,6 +1,6 @@ - + public struct FloatList { public string ID; diff --git a/models/csharp/generic/IDData.cs b/models/csharp/generic/IDData.cs index 045740c..753b5bd 100644 --- a/models/csharp/generic/IDData.cs +++ b/models/csharp/generic/IDData.cs @@ -1,6 +1,6 @@ - + public struct IDData { public string ID; diff --git a/models/csharp/generic/IDList.cs b/models/csharp/generic/IDList.cs index 9623341..12d84ba 100644 --- a/models/csharp/generic/IDList.cs +++ b/models/csharp/generic/IDList.cs @@ -1,6 +1,6 @@ - + public struct IDList { public string[] IDs; diff --git a/models/csharp/generic/IDListBoolData.cs b/models/csharp/generic/IDListBoolData.cs index 747b337..2178df2 100644 --- a/models/csharp/generic/IDListBoolData.cs +++ b/models/csharp/generic/IDListBoolData.cs @@ -1,6 +1,6 @@ - + public struct IDListBoolData { public string[] IDs; diff --git a/models/csharp/generic/IDListBoolList.cs b/models/csharp/generic/IDListBoolList.cs index b48c729..815f0bb 100644 --- a/models/csharp/generic/IDListBoolList.cs +++ b/models/csharp/generic/IDListBoolList.cs @@ -1,6 +1,6 @@ - + public struct IDListBoolList { public string[] IDs; diff --git a/models/csharp/generic/IDListColorData.cs b/models/csharp/generic/IDListColorData.cs index 81e7064..b5109a2 100644 --- a/models/csharp/generic/IDListColorData.cs +++ b/models/csharp/generic/IDListColorData.cs @@ -1,6 +1,6 @@ using UnityEngine; - + public struct IDListColorData { public string[] IDs; diff --git a/models/csharp/generic/IDListColorList.cs b/models/csharp/generic/IDListColorList.cs index 36dabda..4903fc9 100644 --- a/models/csharp/generic/IDListColorList.cs +++ b/models/csharp/generic/IDListColorList.cs @@ -1,6 +1,6 @@ using UnityEngine; - + public struct IDListColorList { public string[] IDs; diff --git a/models/csharp/generic/IDListFloatData.cs b/models/csharp/generic/IDListFloatData.cs index 8b938ef..141884f 100644 --- a/models/csharp/generic/IDListFloatData.cs +++ b/models/csharp/generic/IDListFloatData.cs @@ -1,6 +1,6 @@ - + public struct IDListFloatData { public string[] IDs; diff --git a/models/csharp/generic/IDListFloatList.cs b/models/csharp/generic/IDListFloatList.cs index b730607..1e23944 100644 --- a/models/csharp/generic/IDListFloatList.cs +++ b/models/csharp/generic/IDListFloatList.cs @@ -1,6 +1,6 @@ - + public struct IDListFloatList { public string[] IDs; diff --git a/models/csharp/generic/IDListIntData.cs b/models/csharp/generic/IDListIntData.cs index 9e905dc..0918ce7 100644 --- a/models/csharp/generic/IDListIntData.cs +++ b/models/csharp/generic/IDListIntData.cs @@ -1,6 +1,6 @@ - + public struct IDListIntData { public string[] IDs; diff --git a/models/csharp/generic/IDListIntList.cs b/models/csharp/generic/IDListIntList.cs index 33bcf21..43eb022 100644 --- a/models/csharp/generic/IDListIntList.cs +++ b/models/csharp/generic/IDListIntList.cs @@ -1,6 +1,6 @@ - + public struct IDListIntList { public string[] IDs; diff --git a/models/csharp/generic/IDListStringData.cs b/models/csharp/generic/IDListStringData.cs index 1c299d6..3709752 100644 --- a/models/csharp/generic/IDListStringData.cs +++ b/models/csharp/generic/IDListStringData.cs @@ -1,6 +1,6 @@ - + public struct IDListStringData { public string[] IDs; diff --git a/models/csharp/generic/IDListStringList.cs b/models/csharp/generic/IDListStringList.cs index fe19b6a..29af512 100644 --- a/models/csharp/generic/IDListStringList.cs +++ b/models/csharp/generic/IDListStringList.cs @@ -1,6 +1,6 @@ - + public struct IDListStringList { public string[] IDs; diff --git a/models/csharp/generic/IDListVector3Data.cs b/models/csharp/generic/IDListVector3Data.cs index cb8b332..c06f685 100644 --- a/models/csharp/generic/IDListVector3Data.cs +++ b/models/csharp/generic/IDListVector3Data.cs @@ -1,6 +1,6 @@ using UnityEngine; - + public struct IDListVector3Data { public string[] IDs; diff --git a/models/csharp/generic/IDListVector3List.cs b/models/csharp/generic/IDListVector3List.cs index b976f00..0baf30d 100644 --- a/models/csharp/generic/IDListVector3List.cs +++ b/models/csharp/generic/IDListVector3List.cs @@ -1,6 +1,6 @@ using UnityEngine; - + public struct IDListVector3List { public string[] IDs; diff --git a/models/csharp/generic/IntData.cs b/models/csharp/generic/IntData.cs index ab89210..0ecbaa2 100644 --- a/models/csharp/generic/IntData.cs +++ b/models/csharp/generic/IntData.cs @@ -1,6 +1,6 @@ - + public struct IntData { public string ID; diff --git a/models/csharp/generic/IntList.cs b/models/csharp/generic/IntList.cs index c9426ec..321a1c9 100644 --- a/models/csharp/generic/IntList.cs +++ b/models/csharp/generic/IntList.cs @@ -1,6 +1,6 @@ - + public struct IntList { public string ID; diff --git a/models/csharp/generic/StringData.cs b/models/csharp/generic/StringData.cs index ed693b5..09c65ad 100644 --- a/models/csharp/generic/StringData.cs +++ b/models/csharp/generic/StringData.cs @@ -1,6 +1,6 @@ - + public struct StringData { public string ID; diff --git a/models/csharp/generic/StringList.cs b/models/csharp/generic/StringList.cs index 9c466ca..2cfb13c 100644 --- a/models/csharp/generic/StringList.cs +++ b/models/csharp/generic/StringList.cs @@ -1,6 +1,6 @@ - + public struct StringList { public string ID; diff --git a/models/csharp/generic/Vector3Data.cs b/models/csharp/generic/Vector3Data.cs index 7fa17d7..cda79c9 100644 --- a/models/csharp/generic/Vector3Data.cs +++ b/models/csharp/generic/Vector3Data.cs @@ -1,6 +1,6 @@ using UnityEngine; - + public struct Vector3Data { public string ID; diff --git a/models/csharp/generic/Vector3List.cs b/models/csharp/generic/Vector3List.cs index 8731989..c051380 100644 --- a/models/csharp/generic/Vector3List.cs +++ b/models/csharp/generic/Vector3List.cs @@ -1,6 +1,6 @@ using UnityEngine; - + public struct Vector3List { public string ID; diff --git a/models/csharp/logging/Log.cs b/models/csharp/logging/Log.cs index 226001f..a637ec5 100644 --- a/models/csharp/logging/Log.cs +++ b/models/csharp/logging/Log.cs @@ -1,6 +1,6 @@ - + public struct Log { public string Msg; diff --git a/models/csharp/logging/LogError.cs b/models/csharp/logging/LogError.cs index 50f646c..e3a1c57 100644 --- a/models/csharp/logging/LogError.cs +++ b/models/csharp/logging/LogError.cs @@ -1,6 +1,6 @@ - + public struct LogError { public string Msg; diff --git a/models/csharp/logging/LogWarning.cs b/models/csharp/logging/LogWarning.cs index 256ad03..1f84642 100644 --- a/models/csharp/logging/LogWarning.cs +++ b/models/csharp/logging/LogWarning.cs @@ -1,6 +1,6 @@ - + public struct LogWarning { public string Msg; diff --git a/models/csharp/pinpoint/CraniotomyGroup.cs b/models/csharp/pinpoint/CraniotomyGroup.cs index 6461c84..44f7362 100644 --- a/models/csharp/pinpoint/CraniotomyGroup.cs +++ b/models/csharp/pinpoint/CraniotomyGroup.cs @@ -1,6 +1,6 @@ - + public struct CraniotomyGroup { public string Atlas; diff --git a/models/csharp/pinpoint/CraniotomyModel.cs b/models/csharp/pinpoint/CraniotomyModel.cs index 7ea0a7d..a8943bb 100644 --- a/models/csharp/pinpoint/CraniotomyModel.cs +++ b/models/csharp/pinpoint/CraniotomyModel.cs @@ -1,6 +1,6 @@ using UnityEngine; - + public struct CraniotomyModel { public int Index; diff --git a/models/csharp/urchin/AreaGroupData.cs b/models/csharp/urchin/AreaGroupData.cs index 224fdbe..a78462f 100644 --- a/models/csharp/urchin/AreaGroupData.cs +++ b/models/csharp/urchin/AreaGroupData.cs @@ -1,6 +1,6 @@ - + public struct AreaGroupData { public string[] Acronyms; diff --git a/models/csharp/urchin/CameraModel.cs b/models/csharp/urchin/CameraModel.cs index 503816b..335043c 100644 --- a/models/csharp/urchin/CameraModel.cs +++ b/models/csharp/urchin/CameraModel.cs @@ -1,6 +1,6 @@ using UnityEngine; - + public struct CameraModel { public float Id; diff --git a/models/csharp/urchin/CustomAtlasModel.cs b/models/csharp/urchin/CustomAtlasModel.cs index 3c334ac..5fba79e 100644 --- a/models/csharp/urchin/CustomAtlasModel.cs +++ b/models/csharp/urchin/CustomAtlasModel.cs @@ -1,6 +1,6 @@ using UnityEngine; - + public struct CustomAtlasModel { public string Name; diff --git a/models/csharp/urchin/CustomMeshData.cs b/models/csharp/urchin/CustomMeshData.cs index 3bf6677..6f3815c 100644 --- a/models/csharp/urchin/CustomMeshData.cs +++ b/models/csharp/urchin/CustomMeshData.cs @@ -1,6 +1,6 @@ using UnityEngine; - + public struct CustomMeshData { public string Id; diff --git a/models/csharp/urchin/CustomMeshModel.cs b/models/csharp/urchin/CustomMeshModel.cs index d008ee9..9d413d1 100644 --- a/models/csharp/urchin/CustomMeshModel.cs +++ b/models/csharp/urchin/CustomMeshModel.cs @@ -1,6 +1,6 @@ using UnityEngine; - + public struct CustomMeshModel { public string Id; diff --git a/models/csharp/urchin/MeshModel.cs b/models/csharp/urchin/MeshModel.cs index 1c73219..f8b244f 100644 --- a/models/csharp/urchin/MeshModel.cs +++ b/models/csharp/urchin/MeshModel.cs @@ -1,6 +1,6 @@ using UnityEngine; - + public struct MeshModel { public string Id; diff --git a/models/csharp/urchin/ParticleGroupModel.cs b/models/csharp/urchin/ParticleGroupModel.cs index 6deeca5..aacd463 100644 --- a/models/csharp/urchin/ParticleGroupModel.cs +++ b/models/csharp/urchin/ParticleGroupModel.cs @@ -1,6 +1,6 @@ using UnityEngine; - + public struct ParticleGroupModel { public string Id; diff --git a/models/schemas/generic/ColorData.json b/models/schemas/generic/ColorData.json index 6bcc070..0adafbb 100644 --- a/models/schemas/generic/ColorData.json +++ b/models/schemas/generic/ColorData.json @@ -1 +1 @@ -{"$defs": {"Color": {"properties": {"r": {"maximum": 255.0, "minimum": 0.0, "title": "R", "type": "number"}, "g": {"maximum": 255.0, "minimum": 0.0, "title": "G", "type": "number"}, "b": {"maximum": 255.0, "minimum": 0.0, "title": "B", "type": "number"}, "a": {"default": 255, "maximum": 255.0, "minimum": 0.0, "title": "A", "type": "number"}}, "required": ["r", "g", "b"], "title": "Color", "type": "object"}}, "properties": {"ID": {"title": "Id", "type": "string"}, "Value": {"$ref": "#/$defs/Color"}}, "required": ["ID", "Value"], "title": "ColorData", "type": "object"} \ No newline at end of file +{"$defs": {"Color": {"properties": {"r": {"maximum": 1.0, "minimum": 0.0, "title": "R", "type": "number"}, "g": {"maximum": 1.0, "minimum": 0.0, "title": "G", "type": "number"}, "b": {"maximum": 1.0, "minimum": 0.0, "title": "B", "type": "number"}, "a": {"default": 1, "maximum": 1.0, "minimum": 0.0, "title": "A", "type": "number"}}, "required": ["r", "g", "b"], "title": "Color", "type": "object"}}, "properties": {"ID": {"title": "Id", "type": "string"}, "Value": {"$ref": "#/$defs/Color"}}, "required": ["ID", "Value"], "title": "ColorData", "type": "object"} \ No newline at end of file diff --git a/models/schemas/generic/ColorList.json b/models/schemas/generic/ColorList.json index 43b88d8..a4c11dc 100644 --- a/models/schemas/generic/ColorList.json +++ b/models/schemas/generic/ColorList.json @@ -1 +1 @@ -{"$defs": {"Color": {"properties": {"r": {"maximum": 255.0, "minimum": 0.0, "title": "R", "type": "number"}, "g": {"maximum": 255.0, "minimum": 0.0, "title": "G", "type": "number"}, "b": {"maximum": 255.0, "minimum": 0.0, "title": "B", "type": "number"}, "a": {"default": 255, "maximum": 255.0, "minimum": 0.0, "title": "A", "type": "number"}}, "required": ["r", "g", "b"], "title": "Color", "type": "object"}}, "properties": {"ID": {"title": "Id", "type": "string"}, "Values": {"items": {"$ref": "#/$defs/Color"}, "title": "Values", "type": "array"}}, "required": ["ID", "Values"], "title": "ColorList", "type": "object"} \ No newline at end of file +{"$defs": {"Color": {"properties": {"r": {"maximum": 1.0, "minimum": 0.0, "title": "R", "type": "number"}, "g": {"maximum": 1.0, "minimum": 0.0, "title": "G", "type": "number"}, "b": {"maximum": 1.0, "minimum": 0.0, "title": "B", "type": "number"}, "a": {"default": 1, "maximum": 1.0, "minimum": 0.0, "title": "A", "type": "number"}}, "required": ["r", "g", "b"], "title": "Color", "type": "object"}}, "properties": {"ID": {"title": "Id", "type": "string"}, "Values": {"items": {"$ref": "#/$defs/Color"}, "title": "Values", "type": "array"}}, "required": ["ID", "Values"], "title": "ColorList", "type": "object"} \ No newline at end of file diff --git a/models/schemas/generic/IDListColorData.json b/models/schemas/generic/IDListColorData.json index a22f6e2..8ed8748 100644 --- a/models/schemas/generic/IDListColorData.json +++ b/models/schemas/generic/IDListColorData.json @@ -1 +1 @@ -{"$defs": {"Color": {"properties": {"r": {"maximum": 255.0, "minimum": 0.0, "title": "R", "type": "number"}, "g": {"maximum": 255.0, "minimum": 0.0, "title": "G", "type": "number"}, "b": {"maximum": 255.0, "minimum": 0.0, "title": "B", "type": "number"}, "a": {"default": 255, "maximum": 255.0, "minimum": 0.0, "title": "A", "type": "number"}}, "required": ["r", "g", "b"], "title": "Color", "type": "object"}}, "properties": {"IDs": {"items": {"type": "string"}, "title": "Ids", "type": "array"}, "Value": {"$ref": "#/$defs/Color"}}, "required": ["IDs", "Value"], "title": "IDListColorData", "type": "object"} \ No newline at end of file +{"$defs": {"Color": {"properties": {"r": {"maximum": 1.0, "minimum": 0.0, "title": "R", "type": "number"}, "g": {"maximum": 1.0, "minimum": 0.0, "title": "G", "type": "number"}, "b": {"maximum": 1.0, "minimum": 0.0, "title": "B", "type": "number"}, "a": {"default": 1, "maximum": 1.0, "minimum": 0.0, "title": "A", "type": "number"}}, "required": ["r", "g", "b"], "title": "Color", "type": "object"}}, "properties": {"IDs": {"items": {"type": "string"}, "title": "Ids", "type": "array"}, "Value": {"$ref": "#/$defs/Color"}}, "required": ["IDs", "Value"], "title": "IDListColorData", "type": "object"} \ No newline at end of file diff --git a/models/schemas/generic/IDListColorList.json b/models/schemas/generic/IDListColorList.json index a978ec0..b5d23e6 100644 --- a/models/schemas/generic/IDListColorList.json +++ b/models/schemas/generic/IDListColorList.json @@ -1 +1 @@ -{"$defs": {"Color": {"properties": {"r": {"maximum": 255.0, "minimum": 0.0, "title": "R", "type": "number"}, "g": {"maximum": 255.0, "minimum": 0.0, "title": "G", "type": "number"}, "b": {"maximum": 255.0, "minimum": 0.0, "title": "B", "type": "number"}, "a": {"default": 255, "maximum": 255.0, "minimum": 0.0, "title": "A", "type": "number"}}, "required": ["r", "g", "b"], "title": "Color", "type": "object"}}, "properties": {"IDs": {"items": {"type": "string"}, "title": "Ids", "type": "array"}, "Values": {"items": {"$ref": "#/$defs/Color"}, "title": "Values", "type": "array"}}, "required": ["IDs", "Values"], "title": "IDListColorList", "type": "object"} \ No newline at end of file +{"$defs": {"Color": {"properties": {"r": {"maximum": 1.0, "minimum": 0.0, "title": "R", "type": "number"}, "g": {"maximum": 1.0, "minimum": 0.0, "title": "G", "type": "number"}, "b": {"maximum": 1.0, "minimum": 0.0, "title": "B", "type": "number"}, "a": {"default": 1, "maximum": 1.0, "minimum": 0.0, "title": "A", "type": "number"}}, "required": ["r", "g", "b"], "title": "Color", "type": "object"}}, "properties": {"IDs": {"items": {"type": "string"}, "title": "Ids", "type": "array"}, "Values": {"items": {"$ref": "#/$defs/Color"}, "title": "Values", "type": "array"}}, "required": ["IDs", "Values"], "title": "IDListColorList", "type": "object"} \ No newline at end of file diff --git a/models/schemas/urchin/CustomMeshModel.json b/models/schemas/urchin/CustomMeshModel.json index 37cb15e..b164791 100644 --- a/models/schemas/urchin/CustomMeshModel.json +++ b/models/schemas/urchin/CustomMeshModel.json @@ -1 +1 @@ -{"$defs": {"Color": {"properties": {"r": {"maximum": 255.0, "minimum": 0.0, "title": "R", "type": "number"}, "g": {"maximum": 255.0, "minimum": 0.0, "title": "G", "type": "number"}, "b": {"maximum": 255.0, "minimum": 0.0, "title": "B", "type": "number"}, "a": {"default": 255, "maximum": 255.0, "minimum": 0.0, "title": "A", "type": "number"}}, "required": ["r", "g", "b"], "title": "Color", "type": "object"}, "Vector3": {"properties": {"x": {"default": 0.0, "title": "X", "type": "number"}, "y": {"default": 0.0, "title": "Y", "type": "number"}, "z": {"default": 0.0, "title": "Z", "type": "number"}}, "title": "Vector3", "type": "object"}}, "properties": {"Id": {"title": "Id", "type": "string"}, "Position": {"$ref": "#/$defs/Vector3"}, "UseReference": {"title": "Usereference", "type": "boolean"}, "Material": {"title": "Material", "type": "string"}, "Scale": {"$ref": "#/$defs/Vector3"}, "Color": {"$ref": "#/$defs/Color"}}, "required": ["Id", "Position", "UseReference", "Material", "Scale", "Color"], "title": "CustomMeshModel", "type": "object"} \ No newline at end of file +{"$defs": {"Color": {"properties": {"r": {"maximum": 1.0, "minimum": 0.0, "title": "R", "type": "number"}, "g": {"maximum": 1.0, "minimum": 0.0, "title": "G", "type": "number"}, "b": {"maximum": 1.0, "minimum": 0.0, "title": "B", "type": "number"}, "a": {"default": 1, "maximum": 1.0, "minimum": 0.0, "title": "A", "type": "number"}}, "required": ["r", "g", "b"], "title": "Color", "type": "object"}, "Vector3": {"properties": {"x": {"default": 0.0, "title": "X", "type": "number"}, "y": {"default": 0.0, "title": "Y", "type": "number"}, "z": {"default": 0.0, "title": "Z", "type": "number"}}, "title": "Vector3", "type": "object"}}, "properties": {"Id": {"title": "Id", "type": "string"}, "Position": {"$ref": "#/$defs/Vector3"}, "UseReference": {"title": "Usereference", "type": "boolean"}, "Material": {"title": "Material", "type": "string"}, "Scale": {"$ref": "#/$defs/Vector3"}, "Color": {"$ref": "#/$defs/Color"}}, "required": ["Id", "Position", "UseReference", "Material", "Scale", "Color"], "title": "CustomMeshModel", "type": "object"} \ No newline at end of file diff --git a/models/schemas/urchin/MeshModel.json b/models/schemas/urchin/MeshModel.json index 4fc5d1f..9eee5a3 100644 --- a/models/schemas/urchin/MeshModel.json +++ b/models/schemas/urchin/MeshModel.json @@ -1 +1 @@ -{"$defs": {"Color": {"properties": {"r": {"maximum": 255.0, "minimum": 0.0, "title": "R", "type": "number"}, "g": {"maximum": 255.0, "minimum": 0.0, "title": "G", "type": "number"}, "b": {"maximum": 255.0, "minimum": 0.0, "title": "B", "type": "number"}, "a": {"default": 255, "maximum": 255.0, "minimum": 0.0, "title": "A", "type": "number"}}, "required": ["r", "g", "b"], "title": "Color", "type": "object"}, "Vector3": {"properties": {"x": {"default": 0.0, "title": "X", "type": "number"}, "y": {"default": 0.0, "title": "Y", "type": "number"}, "z": {"default": 0.0, "title": "Z", "type": "number"}}, "title": "Vector3", "type": "object"}}, "properties": {"Id": {"title": "Id", "type": "string"}, "Shape": {"title": "Shape", "type": "string"}, "Position": {"$ref": "#/$defs/Vector3"}, "Color": {"$ref": "#/$defs/Color"}, "Scale": {"$ref": "#/$defs/Vector3"}, "Material": {"title": "Material", "type": "string"}, "Interactive": {"title": "Interactive", "type": "boolean"}}, "required": ["Id", "Shape", "Position", "Color", "Scale", "Material", "Interactive"], "title": "MeshModel", "type": "object"} \ No newline at end of file +{"$defs": {"Color": {"properties": {"r": {"maximum": 1.0, "minimum": 0.0, "title": "R", "type": "number"}, "g": {"maximum": 1.0, "minimum": 0.0, "title": "G", "type": "number"}, "b": {"maximum": 1.0, "minimum": 0.0, "title": "B", "type": "number"}, "a": {"default": 1, "maximum": 1.0, "minimum": 0.0, "title": "A", "type": "number"}}, "required": ["r", "g", "b"], "title": "Color", "type": "object"}, "Vector3": {"properties": {"x": {"default": 0.0, "title": "X", "type": "number"}, "y": {"default": 0.0, "title": "Y", "type": "number"}, "z": {"default": 0.0, "title": "Z", "type": "number"}}, "title": "Vector3", "type": "object"}}, "properties": {"Id": {"title": "Id", "type": "string"}, "Shape": {"title": "Shape", "type": "string"}, "Position": {"$ref": "#/$defs/Vector3"}, "Color": {"$ref": "#/$defs/Color"}, "Scale": {"$ref": "#/$defs/Vector3"}, "Material": {"title": "Material", "type": "string"}, "Interactive": {"title": "Interactive", "type": "boolean"}}, "required": ["Id", "Shape", "Position", "Color", "Scale", "Material", "Interactive"], "title": "MeshModel", "type": "object"} \ No newline at end of file diff --git a/models/schemas/urchin/ParticleGroupModel.json b/models/schemas/urchin/ParticleGroupModel.json index 8fb01fc..f4e347f 100644 --- a/models/schemas/urchin/ParticleGroupModel.json +++ b/models/schemas/urchin/ParticleGroupModel.json @@ -1 +1 @@ -{"$defs": {"Color": {"properties": {"r": {"maximum": 255.0, "minimum": 0.0, "title": "R", "type": "number"}, "g": {"maximum": 255.0, "minimum": 0.0, "title": "G", "type": "number"}, "b": {"maximum": 255.0, "minimum": 0.0, "title": "B", "type": "number"}, "a": {"default": 255, "maximum": 255.0, "minimum": 0.0, "title": "A", "type": "number"}}, "required": ["r", "g", "b"], "title": "Color", "type": "object"}, "Vector3": {"properties": {"x": {"default": 0.0, "title": "X", "type": "number"}, "y": {"default": 0.0, "title": "Y", "type": "number"}, "z": {"default": 0.0, "title": "Z", "type": "number"}}, "title": "Vector3", "type": "object"}}, "properties": {"Id": {"title": "Id", "type": "string"}, "Scale": {"$ref": "#/$defs/Vector3"}, "Shape": {"title": "Shape", "type": "string"}, "Material": {"title": "Material", "type": "string"}, "Xs": {"items": {"type": "number"}, "title": "Xs", "type": "array"}, "Ys": {"items": {"type": "number"}, "title": "Ys", "type": "array"}, "Zs": {"items": {"type": "number"}, "title": "Zs", "type": "array"}, "Colors": {"items": {"$ref": "#/$defs/Color"}, "title": "Colors", "type": "array"}}, "required": ["Id", "Scale", "Shape", "Material", "Xs", "Ys", "Zs", "Colors"], "title": "ParticleGroupModel", "type": "object"} \ No newline at end of file +{"$defs": {"Color": {"properties": {"r": {"maximum": 1.0, "minimum": 0.0, "title": "R", "type": "number"}, "g": {"maximum": 1.0, "minimum": 0.0, "title": "G", "type": "number"}, "b": {"maximum": 1.0, "minimum": 0.0, "title": "B", "type": "number"}, "a": {"default": 1, "maximum": 1.0, "minimum": 0.0, "title": "A", "type": "number"}}, "required": ["r", "g", "b"], "title": "Color", "type": "object"}, "Vector3": {"properties": {"x": {"default": 0.0, "title": "X", "type": "number"}, "y": {"default": 0.0, "title": "Y", "type": "number"}, "z": {"default": 0.0, "title": "Z", "type": "number"}}, "title": "Vector3", "type": "object"}}, "properties": {"Id": {"title": "Id", "type": "string"}, "Scale": {"$ref": "#/$defs/Vector3"}, "Shape": {"title": "Shape", "type": "string"}, "Material": {"title": "Material", "type": "string"}, "Xs": {"items": {"type": "number"}, "title": "Xs", "type": "array"}, "Ys": {"items": {"type": "number"}, "title": "Ys", "type": "array"}, "Zs": {"items": {"type": "number"}, "title": "Zs", "type": "array"}, "Colors": {"items": {"$ref": "#/$defs/Color"}, "title": "Colors", "type": "array"}}, "required": ["Id", "Scale", "Shape", "Material", "Xs", "Ys", "Zs", "Colors"], "title": "ParticleGroupModel", "type": "object"} \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 349dc5d..9853b02 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,6 +36,9 @@ Documentation = "https://github.com/VirtualBrainLab/vbl-aquarium/blob/main/READM Issues = "https://github.com/VirtualBrainLab/vbl-aquarium/issues" Source = "https://github.com/VirtualBrainLab/vbl-aquarium" +[project.scripts] +vbl_aquarium_build = "vbl_aquarium.build:main" + [tool.hatch.version] path = "src/vbl_aquarium/__about__.py" @@ -45,6 +48,7 @@ dependencies = [ "coverage[toml]>=6.5", "pytest", ] + [tool.hatch.envs.default.scripts] test = "pytest {args:tests}" test-cov = "coverage run -m pytest {args:tests}" @@ -84,4 +88,4 @@ exclude_lines = [ ] [tool.ruff.lint] -ignore=["TCH001"] \ No newline at end of file +ignore=["A003", "EM101", "FBT002", "T201", "TCH001", "TRY002", "TRY003"] \ No newline at end of file diff --git a/src/vbl_aquarium/build.py b/src/vbl_aquarium/build.py index 1865f14..64be5d3 100644 --- a/src/vbl_aquarium/build.py +++ b/src/vbl_aquarium/build.py @@ -1,55 +1,47 @@ -import vbl_aquarium.unity as unity -from vbl_aquarium.models import generic -from vbl_aquarium.models import urchin -from vbl_aquarium.models import logging -from vbl_aquarium.models import pinpoint -from vbl_aquarium.models import ephys_link -from vbl_aquarium.models import dock +from enum import Enum +from json import dumps +from os import makedirs +from os.path import abspath, dirname, exists -from vbl_aquarium.models.vbl_base_model import VBLBaseModel +from vbl_aquarium.generate_cs import pydantic_to_csharp +from vbl_aquarium.models import dock, ephys_link, generic, logging, pinpoint, unity, urchin +from vbl_aquarium.utils.common import get_classes +from vbl_aquarium.utils.vbl_base_model import VBLBaseModel -from generate_cs import * -import json -import os +def main(): + def remove_ignored_classes(module): + return [c for c in get_classes(module) if c not in ignored_classes] -def get_classes(module): - # Get a list of all attributes in the module - attributes = dir(module) - # Filter out classes - classes = [getattr(module, attr) for attr in attributes if isinstance(getattr(module, attr), type)] - return classes + ignored_classes = get_classes(unity) + ignored_classes.append(Enum) + ignored_classes.append(VBLBaseModel) + unity_class_names = [x.__name__ for x in get_classes(unity)] -def remove_ignored_classes(module): - return [c for c in get_classes(module) if c not in ignored_classes] + module_list = [generic, urchin, logging, pinpoint, ephys_link, dock] + folder_prefix = ["generic", "urchin", "logging", "pinpoint", "ephys_link", "dock"] -ignored_classes = get_classes(unity) -ignored_classes.append(VBLBaseModel) -unity_class_names = [x.__name__ for x in get_classes(unity)] + cdir = dirname(abspath(__file__)) -module_list = [generic, urchin, logging, pinpoint, ephys_link, dock] -folder_prefix = ['generic', 'urchin', 'logging', 'pinpoint', 'ephys_link', 'dock'] + for _, (module, cfolder) in enumerate(zip(module_list, folder_prefix)): + classes = remove_ignored_classes(module) + for cclass in classes: + if cclass.__name__ not in unity_class_names: + path = f"{cdir}/../../models/schemas/{cfolder}" + if not exists(path): + makedirs(path) -cdir = os.path.dirname(os.path.abspath(__file__)) + with open(f"{path}/{cclass.__name__}.json", "w") as f: + f.write(dumps(cclass.model_json_schema())) -for i, (module, cfolder) in enumerate(zip(module_list, folder_prefix)): - classes = remove_ignored_classes(module) - - for cclass in classes: - - if not cclass.__name__ in unity_class_names: + path = f"{cdir}/../../models/csharp/{cfolder}" + if not exists(path): + makedirs(path) - path = f"{cdir}/../../models/schemas/{cfolder}" - if not os.path.exists(path): - os.makedirs(path) + with open(f"{path}/{cclass.__name__}.cs", "w") as f: + f.write(pydantic_to_csharp(cclass, cclass.model_json_schema())) - with open(f"{path}/{cclass.__name__}.json", "w") as f: - f.write(json.dumps(cclass.model_json_schema())) - path = f"{cdir}/../../models/csharp/{cfolder}" - if not os.path.exists(path): - os.makedirs(path) - - with open(f'{path}/{cclass.__name__}.cs', 'w') as f: - f.write(pydantic_to_csharp(cclass, cclass.model_json_schema())) \ No newline at end of file +if __name__ == "__main__": + main() diff --git a/src/vbl_aquarium/generate_cs.py b/src/vbl_aquarium/generate_cs.py index 948fd9d..5b8eef8 100644 --- a/src/vbl_aquarium/generate_cs.py +++ b/src/vbl_aquarium/generate_cs.py @@ -1,32 +1,26 @@ -from vbl_aquarium import * +from __future__ import annotations -import typing -from typing import List -import inspect -import vbl_aquarium.unity as unity +from typing import get_args, get_origin + +from vbl_aquarium.models import unity +from vbl_aquarium.utils.common import get_classes p2c_types = { - 'str': 'string', + "str": "string", } -def get_classes(module): - # Get a list of all attributes in the module - attributes = dir(module) - # Filter out classes - classes = [getattr(module, attr) for attr in attributes if isinstance(getattr(module, attr), type)] - return classes - unity_class_names = [x.__name__ for x in get_classes(unity)] -def generate_csharp_struct(class_name: str, fields: List[str], enums = None, has_unity_classes = False): - #build using statements - usings = '' + +def generate_csharp_struct(class_name: str, fields: list[str], enums=None, has_unity_classes=False): + # build using statements + usings = "" # if enums is not None: # usings += 'using System;\nusing UnityEngine;' # else: if has_unity_classes: - usings += 'using UnityEngine;' + usings += "using UnityEngine;" # build field declartions field_declarations = "\n".join(f" public {field};" for field in fields) @@ -41,68 +35,68 @@ def generate_csharp_struct(class_name: str, fields: List[str], enums = None, has {enum_array} }} """ - + # build the full class file string return f""" {usings} - + public struct {class_name} {{ {field_declarations} }}{enum_str} """ + def pydantic_to_csharp(pydantic_class, class_json): class_name = pydantic_class.__name__ fields = [] - enums = None # when enums are active this should be a tuple (ClassName, [(Option1, Value1), (Option2, Value2)]) + enums = None # when enums are active this should be a tuple (ClassName, [(Option1, Value1), (Option2, Value2)]) has_unity_classes = False for name, data in pydantic_class.model_fields.items(): - field_data = '' + field_data = "" # first, catch enums - if 'enum' in str(data.annotation): + if "enum" in str(data.annotation): # get the name of the enum enum_name = data.annotation.__name__ # pull the defs - enum_data = class_json["$defs"][enum_name]['enum'] + enum_data = class_json["$defs"][enum_name]["enum"] data_list = [] for i, v in enumerate(enum_data): data_list.append((v, i)) enums = (enum_name, data_list) - field_data = f'{enum_name} {alias if (alias := data.alias) else name}' + field_data = f"{enum_name} {alias if (alias := data.alias) else name}" # finally, deal with arrays - elif typing.get_origin(data.annotation) == list: - arg_class = typing.get_args(data.annotation) + elif get_origin(data.annotation) == list: + arg_class = get_args(data.annotation) type_name = arg_class[0].__name__ # convert str -> string properly - if type_name in p2c_types.keys(): + if type_name in p2c_types: type_name = p2c_types[type_name] if hasattr(arg_class[0], "__name__"): - field_data = f'{type_name}[] {alias if (alias := data.alias) else name}' + field_data = f"{type_name}[] {alias if (alias := data.alias) else name}" else: print(arg_class[0]) # next, deal with base classes elif hasattr(data.annotation, "__name__"): - # convert str -> string properly type_name = data.annotation.__name__ - if type_name in p2c_types.keys(): + if type_name in p2c_types: type_name = p2c_types[type_name] - field_data = f'{type_name} {alias if (alias := data.alias) else name}' + field_data = f"{type_name} {alias if (alias := data.alias) else name}" else: raise Exception("need to write a new parser for a missing type") - + if not has_unity_classes: for uc in unity_class_names: if uc in field_data: @@ -111,4 +105,4 @@ def pydantic_to_csharp(pydantic_class, class_json): fields.append(field_data) - return generate_csharp_struct(class_name, fields, enums, has_unity_classes) \ No newline at end of file + return generate_csharp_struct(class_name, fields, enums, has_unity_classes) diff --git a/src/vbl_aquarium/models/dock.py b/src/vbl_aquarium/models/dock.py index 3319708..e2986ce 100644 --- a/src/vbl_aquarium/models/dock.py +++ b/src/vbl_aquarium/models/dock.py @@ -1,20 +1,24 @@ -from vbl_aquarium.models.vbl_base_model import VBLBaseModel +from vbl_aquarium.utils.vbl_base_model import VBLBaseModel # File IO - + + class BucketModel(VBLBaseModel): token: str bucket: str password: str - + + class SaveModel(VBLBaseModel): bucket: str password: str + class SaveManagerModel(VBLBaseModel): bucket: str manager: str password: str + class LoadModel(VBLBaseModel): - bucket: str \ No newline at end of file + bucket: str diff --git a/src/vbl_aquarium/models/ephys_link.py b/src/vbl_aquarium/models/ephys_link.py index a17b27b..756eb6b 100644 --- a/src/vbl_aquarium/models/ephys_link.py +++ b/src/vbl_aquarium/models/ephys_link.py @@ -1,7 +1,9 @@ from __future__ import annotations -from vbl_aquarium.models.vbl_base_model import VBLBaseModel -from vbl_aquarium.unity import Vector3, Vector4 +from pydantic import Field + +from vbl_aquarium.models.unity import Vector3, Vector4 +from vbl_aquarium.utils.vbl_base_model import VBLBaseModel class GotoPositionRequest(VBLBaseModel): @@ -15,9 +17,9 @@ class GotoPositionRequest(VBLBaseModel): :type speed: float """ - manipulator_id: str + manipulator_id: str = Field(min_length=1) position: Vector4 - speed: float + speed: float = Field(gt=0) class InsideBrainRequest(VBLBaseModel): @@ -29,7 +31,7 @@ class InsideBrainRequest(VBLBaseModel): :type inside: bool """ - manipulator_id: str + manipulator_id: str = Field(min_length=1) inside: bool @@ -44,9 +46,9 @@ class DriveToDepthRequest(VBLBaseModel): :type speed: float """ - manipulator_id: str + manipulator_id: str = Field(min_length=1) depth: float - speed: float + speed: float = Field(gt=0) class CanWriteRequest(VBLBaseModel): @@ -56,13 +58,13 @@ class CanWriteRequest(VBLBaseModel): :type manipulator_id: str :param can_write: Whether the manipulator can write. :type can_write: bool - :param hours: Number of hours the manipulator can write for. + :param hours: Number of hours the manipulator can write for (0 = indefinitely). :type hours: float """ - manipulator_id: str + manipulator_id: str = Field(min_length=1) can_write: bool - hours: float + hours: float = Field(ge=0) class GetManipulatorsResponse(VBLBaseModel): @@ -78,10 +80,10 @@ class GetManipulatorsResponse(VBLBaseModel): :type error: str """ - manipulators: list[str] - num_axes: int - dimensions: Vector3 - error: str + manipulators: list[str] = Field(default_factory=list) + num_axes: int = Field(default=0, ge=-1) + dimensions: Vector3 = Vector3() + error: str = "" class PositionalResponse(VBLBaseModel): @@ -91,8 +93,8 @@ class PositionalResponse(VBLBaseModel): :type position: Vector4 """ - position: Vector4 - error: str + position: Vector4 = Vector4() + error: str = "" class AngularResponse(VBLBaseModel): @@ -102,8 +104,8 @@ class AngularResponse(VBLBaseModel): :type angles: Vector3 """ - angles: Vector3 - error: str + angles: Vector3 = Vector3() + error: str = "" class ShankCountResponse(VBLBaseModel): @@ -115,8 +117,8 @@ class ShankCountResponse(VBLBaseModel): :type error: str """ - shank_count: int - error: str + shank_count: int = Field(default=1, ge=1) + error: str = "" class DriveToDepthResponse(VBLBaseModel): @@ -128,8 +130,8 @@ class DriveToDepthResponse(VBLBaseModel): :type error: str """ - depth: float - error: str + depth: float = 0 + error: str = "" class BooleanStateResponse(VBLBaseModel): @@ -141,5 +143,5 @@ class BooleanStateResponse(VBLBaseModel): :type error: str """ - state: bool - error: str + state: bool = False + error: str = "" diff --git a/src/vbl_aquarium/models/generic.py b/src/vbl_aquarium/models/generic.py index 1269709..3fd2205 100644 --- a/src/vbl_aquarium/models/generic.py +++ b/src/vbl_aquarium/models/generic.py @@ -1,108 +1,138 @@ -from vbl_aquarium.models.vbl_base_model import VBLBaseModel -from typing import List -from vbl_aquarium.unity import * +from __future__ import annotations + +from pydantic import Field + +from vbl_aquarium.models.unity import Color, Vector3 +from vbl_aquarium.utils.vbl_base_model import VBLBaseModel + # Standard types and lists class IDData(VBLBaseModel): - id: str = Field(..., alias='ID') + id: str = Field(..., alias="ID") + class Vector3Data(VBLBaseModel): - id: str = Field(..., alias='ID') + id: str = Field(..., alias="ID") value: Vector3 + class Vector3List(VBLBaseModel): - id: str = Field(..., alias='ID') - values: List[Vector3] + id: str = Field(..., alias="ID") + values: list[Vector3] + class ColorData(VBLBaseModel): - id: str = Field(..., alias='ID') + id: str = Field(..., alias="ID") value: Color + class ColorList(VBLBaseModel): - id: str = Field(..., alias='ID') - values: List[Color] + id: str = Field(..., alias="ID") + values: list[Color] + class StringData(VBLBaseModel): - id: str = Field(..., alias='ID') + id: str = Field(..., alias="ID") value: str + class StringList(VBLBaseModel): - id: str = Field(..., alias='ID') - values: List[str] + id: str = Field(..., alias="ID") + values: list[str] + class FloatData(VBLBaseModel): - id: str = Field(..., alias='ID') + id: str = Field(..., alias="ID") value: float + class FloatList(VBLBaseModel): - id: str = Field(..., alias='ID') - values: List[float] + id: str = Field(..., alias="ID") + values: list[float] + class IntData(VBLBaseModel): - id: str = Field(..., alias='ID') + id: str = Field(..., alias="ID") value: int + class IntList(VBLBaseModel): - id: str = Field(..., alias='ID') - values: List[int] + id: str = Field(..., alias="ID") + values: list[int] + class BoolData(VBLBaseModel): - id: str = Field(..., alias='ID') + id: str = Field(..., alias="ID") value: bool + class BoolList(VBLBaseModel): - id: str = Field(..., alias='ID') - values: List[bool] + id: str = Field(..., alias="ID") + values: list[bool] + + +# ID lists + -# ID lists - class IDList(VBLBaseModel): - ids: List[str] = Field(..., alias='IDs') + ids: list[str] = Field(..., alias="IDs") + class IDListVector3Data(VBLBaseModel): - ids: List[str] = Field(..., alias='IDs') + ids: list[str] = Field(..., alias="IDs") value: Vector3 + class IDListVector3List(VBLBaseModel): - ids: List[str] = Field(..., alias='IDs') - values: List[Vector3] + ids: list[str] = Field(..., alias="IDs") + values: list[Vector3] + class IDListColorData(VBLBaseModel): - ids: List[str] = Field(..., alias='IDs') + ids: list[str] = Field(..., alias="IDs") value: Color + class IDListColorList(VBLBaseModel): - ids: List[str] = Field(..., alias='IDs') - values: List[Color] + ids: list[str] = Field(..., alias="IDs") + values: list[Color] + class IDListStringData(VBLBaseModel): - ids: List[str] = Field(..., alias='IDs') + ids: list[str] = Field(..., alias="IDs") value: str + class IDListStringList(VBLBaseModel): - ids: List[str] = Field(..., alias='IDs') - values: List[str] + ids: list[str] = Field(..., alias="IDs") + values: list[str] + class IDListFloatData(VBLBaseModel): - ids: List[str] = Field(..., alias='IDs') + ids: list[str] = Field(..., alias="IDs") value: float + class IDListFloatList(VBLBaseModel): - ids: List[str] = Field(..., alias='IDs') - values: List[float] + ids: list[str] = Field(..., alias="IDs") + values: list[float] + class IDListIntData(VBLBaseModel): - ids: List[str] = Field(..., alias='IDs') + ids: list[str] = Field(..., alias="IDs") value: int + class IDListIntList(VBLBaseModel): - ids: List[str] = Field(..., alias='IDs') - values: List[int] + ids: list[str] = Field(..., alias="IDs") + values: list[int] + class IDListBoolData(VBLBaseModel): - ids: List[str] = Field(..., alias='IDs') + ids: list[str] = Field(..., alias="IDs") value: bool + class IDListBoolList(VBLBaseModel): - ids: List[str] = Field(..., alias='IDs') - values: List[bool] \ No newline at end of file + ids: list[str] = Field(..., alias="IDs") + values: list[bool] diff --git a/src/vbl_aquarium/models/logging.py b/src/vbl_aquarium/models/logging.py index 8b407b6..e447b0c 100644 --- a/src/vbl_aquarium/models/logging.py +++ b/src/vbl_aquarium/models/logging.py @@ -1,12 +1,13 @@ -from vbl_aquarium.models.vbl_base_model import VBLBaseModel +from vbl_aquarium.utils.vbl_base_model import VBLBaseModel + class LogError(VBLBaseModel): msg: str - + + class LogWarning(VBLBaseModel): msg: str + class Log(VBLBaseModel): msg: str - - \ No newline at end of file diff --git a/src/vbl_aquarium/models/pinpoint.py b/src/vbl_aquarium/models/pinpoint.py index cd215c0..44b34a8 100644 --- a/src/vbl_aquarium/models/pinpoint.py +++ b/src/vbl_aquarium/models/pinpoint.py @@ -1,15 +1,18 @@ -from vbl_aquarium.models.vbl_base_model import VBLBaseModel -from typing import List -from vbl_aquarium.unity import * +from __future__ import annotations + +from vbl_aquarium.models.unity import Vector2, Vector3 +from vbl_aquarium.utils.vbl_base_model import VBLBaseModel # CRANIOTOMY + class CraniotomyModel(VBLBaseModel): index: int size: Vector2 position: Vector3 rectangle: bool = False + class CraniotomyGroup(VBLBaseModel): atlas: str - data: List[CraniotomyModel] \ No newline at end of file + data: list[CraniotomyModel] diff --git a/src/vbl_aquarium/unity.py b/src/vbl_aquarium/models/unity.py similarity index 54% rename from src/vbl_aquarium/unity.py rename to src/vbl_aquarium/models/unity.py index 89a31a2..e8d5cb7 100644 --- a/src/vbl_aquarium/unity.py +++ b/src/vbl_aquarium/models/unity.py @@ -1,26 +1,29 @@ -from pydantic import BaseModel, Field, confloat -from enum import Enum - +from pydantic import BaseModel, Field +from typing_extensions import Annotated # Unity models don't get generated as .cs files since they exist in UnityEngine + class Color(BaseModel): - r: confloat(ge=0, le=255) - g: confloat(ge=0, le=255) - b: confloat(ge=0, le=255) - a: confloat(ge=0, le=255) = 255 + r: Annotated[float, Field(ge=0, le=1)] + g: Annotated[float, Field(ge=0, le=1)] + b: Annotated[float, Field(ge=0, le=1)] + a: Annotated[float, Field(default=1, ge=0, le=1)] + class Vector2(BaseModel): x: float = 0.0 y: float = 0.0 + class Vector3(BaseModel): x: float = 0.0 y: float = 0.0 z: float = 0.0 + class Vector4(BaseModel): x: float = 0.0 y: float = 0.0 z: float = 0.0 - w: float = 0.0 \ No newline at end of file + w: float = 0.0 diff --git a/src/vbl_aquarium/models/urchin.py b/src/vbl_aquarium/models/urchin.py index 4a97e7c..6fd4c35 100644 --- a/src/vbl_aquarium/models/urchin.py +++ b/src/vbl_aquarium/models/urchin.py @@ -1,21 +1,28 @@ -from vbl_aquarium.models.vbl_base_model import VBLBaseModel -from typing import List -from vbl_aquarium.unity import * +from __future__ import annotations + +from enum import Enum + +from vbl_aquarium.models.unity import Color, Vector2, Vector3 +from vbl_aquarium.utils.vbl_base_model import VBLBaseModel # CustomAtlas + class CustomAtlasModel(VBLBaseModel): name: str dimensions: Vector3 resolution: Vector3 + # CustomMesh + class CustomMeshData(VBLBaseModel): id: str - vertices: List[Vector3] - triangles: List[int] - normals: List[Vector3] = None + vertices: list[Vector3] + triangles: list[int] + normals: list[Vector3] = None + class CustomMeshModel(VBLBaseModel): id: str @@ -25,15 +32,19 @@ class CustomMeshModel(VBLBaseModel): scale: Vector3 color: Color + # Area - + + class AreaGroupData(VBLBaseModel): - acronyms: List[str] - visible: List[bool] - side: List[int] + acronyms: list[str] + visible: list[bool] + side: list[int] + # Camera - + + class CameraModel(VBLBaseModel): class CameraMode(str, Enum): orthographic = "orthographic" @@ -49,9 +60,11 @@ class CameraMode(str, Enum): mode: CameraMode controllable: bool main: bool - + + # Individual mesh neuron - + + class MeshModel(VBLBaseModel): id: str shape: str @@ -61,16 +74,18 @@ class MeshModel(VBLBaseModel): material: str interactive: bool + # Particle group - + + class ParticleGroupModel(VBLBaseModel): id: str scale: Vector3 shape: str material: str - xs: List[float] - ys: List[float] - zs: List[float] + xs: list[float] + ys: list[float] + zs: list[float] - colors: List[Color] \ No newline at end of file + colors: list[Color] diff --git a/src/vbl_aquarium/utils/__init__.py b/src/vbl_aquarium/utils/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/vbl_aquarium/utils/common.py b/src/vbl_aquarium/utils/common.py new file mode 100644 index 0000000..9c118c5 --- /dev/null +++ b/src/vbl_aquarium/utils/common.py @@ -0,0 +1,5 @@ +def get_classes(module): + # Get a list of all attributes in the module + attributes = dir(module) + # Filter out classes + return [getattr(module, attr) for attr in attributes if isinstance(getattr(module, attr), type)] diff --git a/src/vbl_aquarium/models/vbl_base_model.py b/src/vbl_aquarium/utils/vbl_base_model.py similarity index 72% rename from src/vbl_aquarium/models/vbl_base_model.py rename to src/vbl_aquarium/utils/vbl_base_model.py index e00eba7..20c6545 100644 --- a/src/vbl_aquarium/models/vbl_base_model.py +++ b/src/vbl_aquarium/utils/vbl_base_model.py @@ -8,4 +8,7 @@ class VBLBaseModel(BaseModel): Configured to use PascalCase for field names and be immutable. """ - model_config = ConfigDict(alias_generator=to_pascal, frozen=True) + model_config = ConfigDict(alias_generator=to_pascal, frozen=True, populate_by_name=True) + + def to_string(self) -> str: + return self.model_dump_json(by_alias=True)