-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(pydantic-settings): Initializes the pydantic settings for rio config-trees #2
base: devel
Are you sure you want to change the base?
Changes from 8 commits
9d30359
0f2990c
725a33b
6fc2706
70a6a75
5fcda9f
cd82549
52a5a05
7bf568f
4158609
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* @rapyuta-robotics/io-cli-owner @rapyuta-robotics/io-first-reviewer |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
name: 💬 Check Commit Hygiene | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
- devel | ||
|
||
jobs: | ||
verify: | ||
name: Conventional Commits | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- uses: actions/checkout@v3 | ||
name: Checkout code | ||
|
||
- uses: rapyuta-robotics/[email protected] | ||
name: Check if commit messages are compliant | ||
with: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# python generated files | ||
__pycache__/ | ||
*.py[oc] | ||
build/ | ||
dist/ | ||
wheels/ | ||
*.egg-info | ||
|
||
# venv | ||
.venv |
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.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
3.12.5 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# rapyuta-io-sdk-v2 | ||
|
||
Describe your project here. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2024 Rapyuta Robotics | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
from typing import Optional, Tuple, Type | ||
|
||
from pydantic_settings import ( | ||
BaseSettings, | ||
InitSettingsSource, | ||
PydanticBaseSettingsSource, | ||
SettingsConfigDict, | ||
) | ||
|
||
from pydantic_configs.app_config_source import RRConfigSettingsSource | ||
from rapyuta_io_sdk_v2 import Configuration | ||
|
||
|
||
class RIOAuthCredentials(BaseSettings): | ||
rio_auth_token: str = "" | ||
rio_organisation_guid: str = "" | ||
rio_project_id: str = "" | ||
|
||
|
||
class RIOConfigTree(BaseSettings): | ||
config_tree_name: str = "" | ||
config_tree_revision: Optional[str] = None | ||
|
||
|
||
class RRSettings(BaseSettings): | ||
model_config = SettingsConfigDict(extra="allow") | ||
|
||
rio_auth_token: str = "" | ||
config_tree_name: str | ||
config_tree_version: Optional[str] = None | ||
rio_organisation_guid: str = "" | ||
rio_project_id: str = "" | ||
|
||
@classmethod | ||
def settings_customise_sources( | ||
cls, | ||
settings_cls: Type[BaseSettings], | ||
init_settings: InitSettingsSource, # overriding the default init settings | ||
env_settings: PydanticBaseSettingsSource, | ||
dotenv_settings: PydanticBaseSettingsSource, | ||
file_secret_settings: PydanticBaseSettingsSource, | ||
) -> Tuple[PydanticBaseSettingsSource, ...]: | ||
|
||
rio_auth_creds = RIOAuthCredentials() | ||
rio_config_tree = RIOConfigTree() | ||
|
||
rio_auth_token = init_settings.init_kwargs.get( | ||
"rio_auth_token", rio_auth_creds.rio_auth_token | ||
) | ||
rio_organisation_guid = init_settings.init_kwargs.get( | ||
"rio_organisation_guid", rio_auth_creds.rio_organisation_guid | ||
) | ||
rio_project_id = init_settings.init_kwargs.get( | ||
"rio_project_id", rio_auth_creds.rio_project_id | ||
) | ||
config_tree_name = init_settings.init_kwargs.get( | ||
"config_tree_name", rio_config_tree.config_tree_name | ||
) | ||
config_tree_revision = init_settings.init_kwargs.get( | ||
"config_tree_version", rio_config_tree.config_tree_revision | ||
) | ||
|
||
_client_config = Configuration( | ||
auth_token=rio_auth_token, | ||
project_guid=rio_project_id, | ||
organization_guid=rio_organisation_guid | ||
) | ||
|
||
rr_config_settings_source = RRConfigSettingsSource( | ||
settings_cls, | ||
client_config=_client_config, | ||
config_tree_name=config_tree_name, | ||
config_tree_revision=config_tree_revision, | ||
) | ||
|
||
return ( | ||
init_settings, | ||
env_settings, | ||
dotenv_settings, | ||
file_secret_settings, | ||
rr_config_settings_source, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2024 Rapyuta Robotics | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import asyncio | ||
from typing import Any, Optional, Tuple, Type | ||
from pydantic.fields import FieldInfo | ||
from pydantic_settings import ( | ||
BaseSettings, | ||
PydanticBaseSettingsSource, | ||
) | ||
|
||
from rapyuta_io_sdk_v2.config import Configuration | ||
|
||
|
||
class RRConfigSettingsSource(PydanticBaseSettingsSource): | ||
def __init__( | ||
self, | ||
settings_cls: Type[BaseSettings], | ||
client_config: Configuration, | ||
config_tree_name: str, | ||
config_tree_revision: Optional[str] = None, | ||
): | ||
self._config_tree = None | ||
self.config_tree_aysnc_client = client_config.async_client() | ||
self.config_tree_name = config_tree_name | ||
self.config_tree_revision = config_tree_revision | ||
|
||
current_loop = asyncio.get_event_loop() | ||
current_loop.run_until_complete( | ||
self._retrieve_config_tree() | ||
) # set self._config_tree | ||
|
||
super().__init__( | ||
settings_cls, | ||
) | ||
|
||
async def _retrieve_config_tree(self) -> None: | ||
res = await self.config_tree_aysnc_client.get_config_tree( | ||
tree_name=self.config_tree_name, | ||
rev_id=self.config_tree_revision, | ||
) | ||
self._config_tree = res | ||
|
||
def get_field_value( | ||
self, | ||
field: FieldInfo, | ||
field_name: str, | ||
) -> Tuple[Any, str, bool]: | ||
return "dummy_val", "dummy_val", False | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why dummy_val ? we need to extract the field_name corresponding value from configtree fetched from upstream right ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @YaswanthKumar-eng ignore above comment, in the call method we are creating the dict which should be enough to get the complete dict, i think without overriding the get_field_value pydantic throws an error |
||
|
||
def __call__(self): | ||
return self._config_tree |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,25 @@ | ||||||
[project] | ||||||
name = "rapyuta-io-sdk-v2" | ||||||
version = "0.1.0" | ||||||
description = "Version:2 for Rapyuta.io SDK" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
dependencies = [ | ||||||
"httpx>=0.27.2", | ||||||
"pydantic-settings>=2.5.2", | ||||||
"python-benedict>=0.33.2", | ||||||
] | ||||||
readme = "README.md" | ||||||
requires-python = ">= 3.8" | ||||||
|
||||||
[build-system] | ||||||
requires = ["hatchling"] | ||||||
build-backend = "hatchling.build" | ||||||
|
||||||
[tool.rye] | ||||||
managed = true | ||||||
dev-dependencies = [] | ||||||
|
||||||
[tool.hatch.metadata] | ||||||
allow-direct-references = true | ||||||
|
||||||
[tool.hatch.build.targets.wheel] | ||||||
packages = ["rapyuta_io_sdk_v2"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from rapyuta_io_sdk_v2.config import Configuration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
todo: add
.idea
to this file.