Skip to content
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

Draft
wants to merge 10 commits into
base: devel
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 8 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
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @rapyuta-robotics/io-cli-owner @rapyuta-robotics/io-first-reviewer
20 changes: 20 additions & 0 deletions .github/workflows/conventional-commits.yml
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 }}
10 changes: 10 additions & 0 deletions .gitignore
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

Copy link
Member

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.

# venv
.venv
3 changes: 3 additions & 0 deletions .idea/.gitignore

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

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

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

7 changes: 7 additions & 0 deletions .idea/misc.xml

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

8 changes: 8 additions & 0 deletions .idea/modules.xml

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

10 changes: 10 additions & 0 deletions .idea/rapyuta-io-sdk-v2.iml

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

6 changes: 6 additions & 0 deletions .idea/vcs.xml

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

1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12.5
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# rapyuta-io-sdk-v2

Describe your project here.
Empty file added pydantic_configs/__init__.py
Empty file.
96 changes: 96 additions & 0 deletions pydantic_configs/app_config_settings.py
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,
)
63 changes: 63 additions & 0 deletions pydantic_configs/app_config_source.py
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

Choose a reason for hiding this comment

The 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 ?

Choose a reason for hiding this comment

The 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
25 changes: 25 additions & 0 deletions pyproject.toml
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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
description = "Version:2 for Rapyuta.io SDK"
description = "A Python SDK for rapyuta.io v2 APIs"

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"]
1 change: 1 addition & 0 deletions rapyuta_io_sdk_v2/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from rapyuta_io_sdk_v2.config import Configuration
Loading
Loading