Skip to content

Commit

Permalink
upgraded pydantic version
Browse files Browse the repository at this point in the history
  • Loading branch information
krishnaglodha committed Aug 12, 2024
2 parents 97199ac + 4baa8cd commit 9d21f30
Show file tree
Hide file tree
Showing 17 changed files with 1,106 additions and 911 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/constraints.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pip==23.0
poetry==1.3.2
virtualenv==20.19.0
pip==24.0
poetry==1.8.3
virtualenv==20.26.0
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ jobs:

- name: Upgrade pip
run: |
pip install --constraint=.github/workflows/constraints.txt pip
pip install --upgrade pip
pip --version
- name: Install Poetry
run: |
pip install --constraint=.github/workflows/constraints.txt poetry
pip install poetry
poetry --version
- name: Check if there is a parent commit
id: check-parent-commit
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:

- name: Upgrade pip
run: |
pip install --constraint=.github/workflows/constraints.txt pip
pip install pip
pip --version
- name: Upgrade pip in virtual environments
shell: python
Expand All @@ -45,7 +45,7 @@ jobs:
print(f"VIRTUALENV_PIP={pip.__version__}", file=io)
- name: Install Poetry
run: |
pipx install --pip-args=--constraint=.github/workflows/constraints.txt poetry
pip install poetry
poetry --version
- name: Install dependencies
run: poetry install
Expand Down
1,406 changes: 773 additions & 633 deletions poetry.lock

Large diffs are not rendered by default.

24 changes: 12 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "geoserverx"
version = "0.0.1"
version = "0.0.3"
description = ""
authors = [
"krishnaglodha <krishnaglodha@gmail.com>",
Expand All @@ -12,19 +12,19 @@ gsx = "geoserverx.cli.cli:app"

[tool.poetry.dependencies]
python = "^3.9"
httpx = "^0.24.1"
pydantic = "<2.0"
typer = "^0.4.1"
rich = "^12.5.1"
mkdocs-material = "^9.0.14"
httpx = "*"
pydantic = "^2.7.2"
typer = "*"
rich = "*"
mkdocs-material = "*"

[tool.poetry.group.dev.dependencies]
pytest = "^7.1.2"
respx = "^0.20.1"
mypy = "^0.960"
black = "^22.3.0"
isort = "^5.10.1"
pytest-asyncio = "^0.21.0"
pytest = "*"
respx = "*"
mypy = "*"
black = "*"
isort = "*"
pytest-asyncio = "*"
anyio = {extras = ["trio"], version = "^3.3.4"}

[build-system]
Expand Down
102 changes: 42 additions & 60 deletions src/geoserverx/_async/gsx.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,16 +94,18 @@ def response_recognise(self, r) -> GSResponse:
resp = GSResponseEnum._403.value
elif r == 201:
resp = GSResponseEnum._201.value
elif r == 200:
resp = GSResponseEnum._200.value
elif r == 409:
resp = GSResponseEnum._409.value
return GSResponse.parse_obj(resp)
return GSResponse.model_validate(resp)

# Get all workspaces
async def get_all_workspaces(self) -> Union[WorkspacesModel, GSResponse]:
Client = self.http_client
responses = await Client.get(f"workspaces")
if responses.status_code == 200:
return WorkspacesModel.parse_obj(responses.json())
return WorkspacesModel.model_validate(responses.json())
else:
results = self.response_recognise(responses.status_code)
return results
Expand All @@ -113,7 +115,7 @@ async def get_workspace(self, workspace: str) -> Union[WorkspaceModel, GSRespons
Client = self.http_client
responses = await Client.get(f"workspaces/{workspace}")
if responses.status_code == 200:
return WorkspaceModel.parse_obj(responses.json())
return WorkspaceModel.model_validate(responses.json())
else:
results = self.response_recognise(responses.status_code)
return results
Expand All @@ -128,7 +130,7 @@ async def create_workspace(
)
responses = await Client.post(
f"workspaces?default={default}",
data=payload.json(),
data=payload.model_dump_json(),
headers=self.head,
)
results = self.response_recognise(responses.status_code)
Expand All @@ -139,7 +141,7 @@ async def get_vector_stores_in_workspaces(self, workspace: str) -> DataStoresMod
Client = self.http_client
responses = await Client.get(f"workspaces/{workspace}/datastores")
if responses.status_code == 200:
return DataStoresModel.parse_obj(responses.json())
return DataStoresModel.model_validate(responses.json())
else:
results = self.response_recognise(responses.status_code)
return results
Expand All @@ -151,7 +153,7 @@ async def get_raster_stores_in_workspaces(
Client = self.http_client
responses = await Client.get(f"workspaces/{workspace}/coveragestores")
if responses.status_code == 200:
return CoveragesStoresModel.parse_obj(responses.json())
return CoveragesStoresModel.model_validate(responses.json())
else:
results = self.response_recognise(responses.status_code)
return results
Expand All @@ -162,7 +164,7 @@ async def get_vector_store(self, workspace: str, store: str) -> DataStoreModel:
Client = self.http_client
responses = await Client.get(url)
if responses.status_code == 200:
return DataStoreModel.parse_obj(responses.json())
return DataStoreModel.model_validate(responses.json())
else:
results = self.response_recognise(responses.status_code)
return results
Expand All @@ -173,7 +175,7 @@ async def get_raster_store(self, workspace: str, store: str) -> CoveragesStoreMo
Client = self.http_client
responses = await Client.get(url)
if responses.status_code == 200:
return CoveragesStoreModel.parse_obj(responses.json())
return CoveragesStoreModel.model_validate(responses.json())
else:
results = self.response_recognise(responses.status_code)
return results
Expand All @@ -183,7 +185,7 @@ async def get_allstyles(self) -> AllStylesModel:
Client = self.http_client
responses = await Client.get(f"styles")
if responses.status_code == 200:
return AllStylesModel.parse_obj(responses.json())
return AllStylesModel.model_validate(responses.json())
else:
results = self.response_recognise(responses.status_code)
return results
Expand All @@ -193,7 +195,7 @@ async def get_style(self, style: str) -> StyleModel:
Client = self.http_client
responses = await Client.get(f"styles/{style}.json")
if responses.status_code == 200:
return StyleModel.parse_obj(responses.json())
return StyleModel.model_validate(responses.json())
else:
results = self.response_recognise(responses.status_code)
return results
Expand All @@ -219,13 +221,13 @@ async def create_pg_store(
user=username,
passwd=password,
dbtype="postgis",
).dict(exclude_none=True),
).model_dump(exclude_none=True),
)
)
Client = self.http_client
responses = await Client.post(
f"workspaces/{workspace}/datastores/",
data=payload.json(),
data=payload.model_dump_json(),
headers=self.head,
)
results = self.response_recognise(responses.status_code)
Expand All @@ -236,7 +238,7 @@ async def get_allstyles(self) -> AllStylesModel:
Client = self.http_client
responses = await Client.get(f"styles")
if responses.status_code == 200:
return AllStylesModel.parse_obj(responses.json())
return AllStylesModel.model_validate(responses.json())
else:
results = self.response_recognise(responses.status_code)
return results
Expand All @@ -246,7 +248,7 @@ async def get_style(self, style: str) -> StyleModel:
Client = self.http_client
responses = await Client.get(f"styles/{style}.json")
if responses.status_code == 200:
return StyleModel.parse_obj(responses.json())
return StyleModel.model_validate(responses.json())
else:
results = self.response_recognise(responses.status_code)
return results
Expand Down Expand Up @@ -279,60 +281,40 @@ async def get_all_layer_groups(self) -> Union[LayerGroupsModel, GSResponse]:
responses = await Client.get(f"layergroups")
if responses.status_code == 200:
return LayerGroupsModel.parse_obj(responses.json())
else:
raise ValueError(f"Service type {service_type} not supported")
await service.addFile(self.http_client, workspace, store)

# Get all layers
async def get_all_layers(
self, workspace: Optional[str] = None
) -> Union[LayersModel, GSResponse]:
Client = self.http_client
if workspace:
responses = await Client.get(f"/workspaces/{workspace}/layers")
else:
responses = await Client.get(f"layers")
if responses.status_code == 200:
return LayersModel.model_validate(responses.json())
else:
results = self.response_recognise(responses.status_code)
return results

# Get single layer groups
async def get_layer_group(
self, name: str
) -> Union[SingleLayerGroupModel, GSResponse]:
# Get specific layer
async def get_layer(
self, workspace: str, layer: str
) -> Union[LayerModel, GSResponse]:
Client = self.http_client
responses = await Client.get(f"layergroups/{name}")
responses = await Client.get(f"layers/{workspace}:{layer}")
if responses.status_code == 200:
return SingleLayerGroupModel.parse_obj(responses.json())
return LayerModel.model_validate(responses.json())
else:
results = self.response_recognise(responses.status_code)
return results

async def create_layer_group(
self,
layers: List[str],
name: str,
mode: ModeEnum = ModeEnum.single,
abstract: Optional[str] = None,
keywords: Optional[List[str]] = None,
styles: Optional[List[str]] = None,
workspace: Optional[str] = None,
title: Optional[str] = None,
) -> GSResponse:
# Delete specific layer
async def delete_layer(self, workspace: str, layer: str) -> GSResponse:
Client = self.http_client
payload = LayerGroupPayload(
layerGroup=LayerGroupModel(
name=name,
mode=mode.value,
title=title if title else name,
layers=LayerListModel(layer=[]),
)
)
if abstract:
payload.layerGroup.abstractTxt = abstract
if workspace:
payload.layerGroup.workspace = WorkspaceModel(name=workspace)
if styles:
payload.layerGroup.styles = LayerGroupStylesModel(style=[])
for style in styles:
payload.layerGroup.styles.style.append(style)
if keywords:
payload.layerGroup.keywords = LayerGroupKeywordsModel(keyword=[])
for keyword in keywords:
payload.layerGroup.keywords.keyword.append(keyword)

for layername in layers:
payload.layerGroup.layers.layer.append(BaseLayerGroup(name=layername))
res = await Client.post(
f"layergroups",
content=payload.json(),
headers=self.head,
)
return self.response_recognise(res.status_code)
responses = await Client.delete(f"layers/{workspace}:{layer}")
results = self.response_recognise(responses.status_code)
return results
Loading

0 comments on commit 9d21f30

Please sign in to comment.