From 1ef4dd212c1b04b4a4adcf2de43a17844ace352d Mon Sep 17 00:00:00 2001 From: Datata1 <> Date: Sat, 8 Nov 2025 20:32:32 +0100 Subject: [PATCH] refactor(filetree): reorganize files --- examples/metadata/get_workspace_base_image.py | 2 +- examples/metadata/get_workspace_plans.py | 2 +- examples/teams/delete_team.py | 2 +- examples/teams/get_team.py | 2 +- src/codesphere/__init__.py | 3 +-- src/codesphere/client.py | 8 ++++---- src/codesphere/core/__init__.py | 11 +++++++++++ src/codesphere/{resources => core}/base.py | 4 ++-- src/codesphere/{cs_types/rest => core}/handler.py | 2 +- src/codesphere/{cs_types/rest => core}/operations.py | 0 src/codesphere/cs_types/__init__.py | 0 .../{cs_types/exceptions => }/exceptions.py | 0 src/codesphere/{cs_types/rest => }/http_client.py | 2 +- src/codesphere/resources/metadata/resources.py | 4 ++-- src/codesphere/resources/team/models.py | 3 +-- src/codesphere/resources/team/resources.py | 3 +-- .../workspace/env-vars/{model.py => models.py} | 2 +- .../resources/workspace/env-vars/resources.py | 2 +- src/codesphere/resources/workspace/models.py | 2 +- src/codesphere/resources/workspace/resources.py | 3 +-- 20 files changed, 32 insertions(+), 25 deletions(-) create mode 100644 src/codesphere/core/__init__.py rename src/codesphere/{resources => core}/base.py (55%) rename src/codesphere/{cs_types/rest => core}/handler.py (99%) rename src/codesphere/{cs_types/rest => core}/operations.py (100%) delete mode 100644 src/codesphere/cs_types/__init__.py rename src/codesphere/{cs_types/exceptions => }/exceptions.py (100%) rename src/codesphere/{cs_types/rest => }/http_client.py (98%) rename src/codesphere/resources/workspace/env-vars/{model.py => models.py} (98%) diff --git a/examples/metadata/get_workspace_base_image.py b/examples/metadata/get_workspace_base_image.py index 1eeca58..7985e1e 100644 --- a/examples/metadata/get_workspace_base_image.py +++ b/examples/metadata/get_workspace_base_image.py @@ -8,7 +8,7 @@ async def main(): """Fetches base images.""" async with CodesphereSDK() as sdk: - images = await sdk.metadata.images() + images = await sdk.metadata.list_images() for image in images: print(image.model_dump_json(indent=2)) diff --git a/examples/metadata/get_workspace_plans.py b/examples/metadata/get_workspace_plans.py index 81393ed..9a3bf91 100644 --- a/examples/metadata/get_workspace_plans.py +++ b/examples/metadata/get_workspace_plans.py @@ -8,7 +8,7 @@ async def main(): """Fetches workspace plans.""" async with CodesphereSDK() as sdk: - plans = await sdk.metadata.plans() + plans = await sdk.metadata.list_plans() for plan in plans: print(plan.model_dump_json(indent=2)) diff --git a/examples/teams/delete_team.py b/examples/teams/delete_team.py index 29362f4..7a3cfee 100644 --- a/examples/teams/delete_team.py +++ b/examples/teams/delete_team.py @@ -8,7 +8,7 @@ async def main(): try: async with CodesphereSDK() as sdk: - team_to_delete = await sdk.teams.get(team_id="") + team_to_delete = await sdk.teams.get(team_id=11111) print(team_to_delete.model_dump_json(indent=2)) await team_to_delete.delete() print(f"Team with ID {team_to_delete.id} was successfully deleted.") diff --git a/examples/teams/get_team.py b/examples/teams/get_team.py index 38be3a8..31aef3c 100644 --- a/examples/teams/get_team.py +++ b/examples/teams/get_team.py @@ -8,7 +8,7 @@ async def main(): try: async with CodesphereSDK() as sdk: - team = await sdk.teams.get(team_id="") + team = await sdk.teams.get(team_id=12312) print(team.model_dump_json(indent=2)) except Exception as e: diff --git a/src/codesphere/__init__.py b/src/codesphere/__init__.py index fd3f493..c4f9eca 100644 --- a/src/codesphere/__init__.py +++ b/src/codesphere/__init__.py @@ -22,8 +22,7 @@ import logging from .client import CodesphereSDK -from .cs_types.exceptions.exceptions import CodesphereError, AuthenticationError - +from .exceptions import CodesphereError, AuthenticationError from .resources.team import Team, TeamCreate, TeamBase from .resources.workspace import ( Workspace, diff --git a/src/codesphere/client.py b/src/codesphere/client.py index 4d74240..d076df4 100644 --- a/src/codesphere/client.py +++ b/src/codesphere/client.py @@ -4,10 +4,10 @@ This module provides the main client class, CodesphereSDK. """ -from .cs_types.rest.http_client import APIHttpClient -from .resources.metadata.resources import MetadataResource -from .resources.team.resources import TeamsResource -from .resources.workspace.resources import WorkspacesResource +from .http_client import APIHttpClient +from .resources.metadata import MetadataResource +from .resources.team import TeamsResource +from .resources.workspace import WorkspacesResource class CodesphereSDK: diff --git a/src/codesphere/core/__init__.py b/src/codesphere/core/__init__.py new file mode 100644 index 0000000..1df8f8f --- /dev/null +++ b/src/codesphere/core/__init__.py @@ -0,0 +1,11 @@ +from .base import ResourceBase +from .operations import APIOperation, AsyncCallable +from .handler import _APIOperationExecutor, APIRequestHandler + +__all__ = [ + "ResourceBase", + "APIOperation", + "_APIOperationExecutor", + "APIRequestHandler", + "AsyncCallable", +] diff --git a/src/codesphere/resources/base.py b/src/codesphere/core/base.py similarity index 55% rename from src/codesphere/resources/base.py rename to src/codesphere/core/base.py index 28eff64..07d9452 100644 --- a/src/codesphere/resources/base.py +++ b/src/codesphere/core/base.py @@ -1,5 +1,5 @@ -from ..cs_types.rest.http_client import APIHttpClient -from ..cs_types.rest.handler import _APIOperationExecutor +from ..http_client import APIHttpClient +from .handler import _APIOperationExecutor class ResourceBase(_APIOperationExecutor): diff --git a/src/codesphere/cs_types/rest/handler.py b/src/codesphere/core/handler.py similarity index 99% rename from src/codesphere/cs_types/rest/handler.py rename to src/codesphere/core/handler.py index 16e2288..397149c 100644 --- a/src/codesphere/cs_types/rest/handler.py +++ b/src/codesphere/core/handler.py @@ -5,7 +5,7 @@ import httpx from pydantic import BaseModel, PrivateAttr, ValidationError -from .http_client import APIHttpClient +from ..http_client import APIHttpClient from .operations import APIOperation log = logging.getLogger(__name__) diff --git a/src/codesphere/cs_types/rest/operations.py b/src/codesphere/core/operations.py similarity index 100% rename from src/codesphere/cs_types/rest/operations.py rename to src/codesphere/core/operations.py diff --git a/src/codesphere/cs_types/__init__.py b/src/codesphere/cs_types/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/codesphere/cs_types/exceptions/exceptions.py b/src/codesphere/exceptions.py similarity index 100% rename from src/codesphere/cs_types/exceptions/exceptions.py rename to src/codesphere/exceptions.py diff --git a/src/codesphere/cs_types/rest/http_client.py b/src/codesphere/http_client.py similarity index 98% rename from src/codesphere/cs_types/rest/http_client.py rename to src/codesphere/http_client.py index ea9ee67..09d4401 100644 --- a/src/codesphere/cs_types/rest/http_client.py +++ b/src/codesphere/http_client.py @@ -3,7 +3,7 @@ import httpx from pydantic import BaseModel from typing import Optional, Any -from ...config import settings +from .config import settings log = logging.getLogger(__name__) diff --git a/src/codesphere/resources/metadata/resources.py b/src/codesphere/resources/metadata/resources.py index 4cb1168..a514e4b 100644 --- a/src/codesphere/resources/metadata/resources.py +++ b/src/codesphere/resources/metadata/resources.py @@ -3,8 +3,8 @@ """ from typing import List -from ...cs_types.rest.operations import APIOperation, AsyncCallable -from ..base import ResourceBase +from ...core import APIOperation, AsyncCallable +from ...core import ResourceBase from .models import Datacenter, WsPlan, Image diff --git a/src/codesphere/resources/team/models.py b/src/codesphere/resources/team/models.py index 2a0104c..4004935 100644 --- a/src/codesphere/resources/team/models.py +++ b/src/codesphere/resources/team/models.py @@ -9,8 +9,7 @@ from pydantic import BaseModel, Field from typing import Optional -from ...cs_types.rest.handler import _APIOperationExecutor -from ...cs_types.rest.operations import APIOperation, AsyncCallable +from ...core import _APIOperationExecutor, APIOperation, AsyncCallable class TeamCreate(BaseModel): diff --git a/src/codesphere/resources/team/resources.py b/src/codesphere/resources/team/resources.py index c2ba118..730a072 100644 --- a/src/codesphere/resources/team/resources.py +++ b/src/codesphere/resources/team/resources.py @@ -4,8 +4,7 @@ from typing import List, Protocol -from ...cs_types.rest.operations import APIOperation, AsyncCallable -from ..base import ResourceBase +from ...core import APIOperation, AsyncCallable, ResourceBase from .models import Team, TeamCreate diff --git a/src/codesphere/resources/workspace/env-vars/model.py b/src/codesphere/resources/workspace/env-vars/models.py similarity index 98% rename from src/codesphere/resources/workspace/env-vars/model.py rename to src/codesphere/resources/workspace/env-vars/models.py index 105506b..4a7d1fb 100644 --- a/src/codesphere/resources/workspace/env-vars/model.py +++ b/src/codesphere/resources/workspace/env-vars/models.py @@ -3,7 +3,7 @@ from typing import Optional, List, TYPE_CHECKING if TYPE_CHECKING: - from ...client import APIHttpClient + from ....http_client import APIHttpClient class EnvVarPair(BaseModel): diff --git a/src/codesphere/resources/workspace/env-vars/resources.py b/src/codesphere/resources/workspace/env-vars/resources.py index 58f640a..6a44930 100644 --- a/src/codesphere/resources/workspace/env-vars/resources.py +++ b/src/codesphere/resources/workspace/env-vars/resources.py @@ -1,5 +1,5 @@ from typing import List -from ..base import ResourceBase, APIOperation +from ....core import ResourceBase, APIOperation from .models import Workspace, WorkspaceCreate, WorkspaceUpdate diff --git a/src/codesphere/resources/workspace/models.py b/src/codesphere/resources/workspace/models.py index 563453e..a2e6362 100644 --- a/src/codesphere/resources/workspace/models.py +++ b/src/codesphere/resources/workspace/models.py @@ -3,7 +3,7 @@ from typing import Optional, List, TYPE_CHECKING, Union, Dict if TYPE_CHECKING: - from ...client import APIHttpClient + from ...http_client import APIHttpClient class EnvVarPair(BaseModel): diff --git a/src/codesphere/resources/workspace/resources.py b/src/codesphere/resources/workspace/resources.py index 55015a8..cba51b0 100644 --- a/src/codesphere/resources/workspace/resources.py +++ b/src/codesphere/resources/workspace/resources.py @@ -1,7 +1,6 @@ from typing import List, Protocol -from ...cs_types.rest.operations import APIOperation -from ..base import ResourceBase +from ...core import APIOperation, ResourceBase from .models import Workspace, WorkspaceCreate