Skip to content

Commit

Permalink
Merge pull request #355 from SevanSSP/dependabot/pip/pydantic-2.8.2
Browse files Browse the repository at this point in the history
Bump pydantic from 1.10.13 to 2.8.2
  • Loading branch information
snorrefjellvang authored Aug 13, 2024
2 parents 8fa87e3 + 8efca94 commit 8f9452d
Show file tree
Hide file tree
Showing 26 changed files with 2,012 additions and 1,674 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install dependencies
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: '3.9'
- name: Install dependencies
run: pip install nox poetry
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/security_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python: ["3.9", "3.10"]
python: ["3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}

Expand All @@ -29,8 +29,8 @@ jobs:
if: always()
run: bandit -r app -o path/to/file/bandit_report.txt

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
if: always()
with:
name: Safety Reports
name: Safety Reports py${{ matrix.python }}
path: path/to/file
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python: ["3.9", "3.10"]
python: ["3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v3
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
Expand Down
5 changes: 3 additions & 2 deletions modeltestsdk/api/campaign.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
Campaign, Campaigns
)
from modeltestsdk.query import create_query_parameters
from pydantic import parse_obj_as
from pydantic import TypeAdapter
from .base import BaseAPI
from typing import List


class CampaignAPI(BaseAPI):
Expand Down Expand Up @@ -79,7 +80,7 @@ def get(self, filter_by: list = None, sort_by: list = None, skip: int = None, li
params = create_query_parameters(filter_expressions=filter_by, sorting_expressions=sort_by)
data = self.client.get(self._resource_path, parameters=dict(**params, skip=skip, limit=limit))

return Campaigns([parse_obj_as(Campaign, dict(**i, client=self.client)) for i in data])
return Campaigns(TypeAdapter(List[Campaign]).validate_python([dict(**i, client=self.client) for i in data]))

def get_by_id(self, campaign_id: str) -> Campaign:
"""
Expand Down
7 changes: 4 additions & 3 deletions modeltestsdk/api/floater_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
FloaterConfig, FloaterConfigs
)
from modeltestsdk.query import create_query_parameters
from pydantic import parse_obj_as
from pydantic import TypeAdapter
from .base import BaseAPI
from typing import List


class FloaterConfigAPI(BaseAPI):
Expand Down Expand Up @@ -73,7 +74,7 @@ def get(self, filter_by: list = None, sort_by: list = None, skip: int = None,
params = create_query_parameters(filter_expressions=filter_by, sorting_expressions=sort_by)
data = self.client.get(self._resource_path, parameters=dict(**params, skip=skip, limit=limit))

return FloaterConfigs([parse_obj_as(FloaterConfig, dict(**i, client=self.client)) for i in data])
return FloaterConfigs(TypeAdapter(List[FloaterConfig]).validate_python([dict(**i, client=self.client) for i in data]))

def get_by_id(self, config_id: str) -> FloaterConfig:
"""
Expand Down Expand Up @@ -110,6 +111,6 @@ def get_by_campaign_id(self, campaign_id: str, limit=100, skip=0) -> FloaterConf
FloaterConfigs
Floater configurations
"""
configs = self.get(filter_by=[self.client.filter.campaign.id == campaign_id],
configs = self.get(filter_by=[self.client.filter.floater_config.campaign_id == campaign_id],
limit=limit, skip=skip)
return configs
5 changes: 3 additions & 2 deletions modeltestsdk/api/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
Sensor, Sensors
)
from modeltestsdk.query import create_query_parameters
from pydantic import parse_obj_as
from pydantic import TypeAdapter
from .base import BaseAPI
from typing import List


class SensorAPI(BaseAPI):
Expand Down Expand Up @@ -99,7 +100,7 @@ def get(self, filter_by: list = None, sort_by: list = None, skip: int = None, li
sort_by = list()
params = create_query_parameters(filter_expressions=filter_by, sorting_expressions=sort_by)
data = self.client.get(self._resource_path, parameters=dict(**params, skip=skip, limit=limit))
return Sensors([parse_obj_as(Sensor, dict(**i, client=self.client)) for i in data])
return Sensors(TypeAdapter(List[Sensor]).validate_python([dict(**i, client=self.client) for i in data]))

def get_by_id(self, sensor_id: str) -> Sensor:
"""
Expand Down
7 changes: 4 additions & 3 deletions modeltestsdk/api/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
Tag, Tags
)
from modeltestsdk.query import create_query_parameters
from pydantic import parse_obj_as
from pydantic import TypeAdapter
from .base import BaseAPI
from typing import List


class TagsAPI(BaseAPI):
Expand Down Expand Up @@ -79,7 +80,7 @@ def get(self, filter_by: list = None, sort_by: list = None, skip: int = None, li
sort_by = list()
params = create_query_parameters(filter_expressions=filter_by, sorting_expressions=sort_by)
data = self.client.get(self._resource_path, parameters=dict(**params, skip=skip, limit=limit))
return Tags([parse_obj_as(Tag, dict(**i, client=self.client)) for i in data])
return Tags(TypeAdapter(List[Tag]).validate_python([dict(**i, client=self.client) for i in data]))

def get_by_id(self, tag_id: str) -> Tag:
"""
Expand Down Expand Up @@ -184,4 +185,4 @@ def get_by_name(self, name: str, limit=100, skip=0) -> Tags:
"""
tags = self.get(filter_by=[self.client.filter.tag.name == name],
limit=limit, skip=skip)
return tags
return tags
10 changes: 5 additions & 5 deletions modeltestsdk/api/test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from typing import Union
from typing import Union, List
from modeltestsdk.resources import (
Test, Tests, FloaterTest, WaveCalibration, WindCalibration,
)
from modeltestsdk.query import create_query_parameters
from pydantic import parse_obj_as
from pydantic import TypeAdapter
from .base import BaseAPI


Expand Down Expand Up @@ -185,7 +185,7 @@ def get(self, filter_by: list = None, sort_by: list = None, skip: int = None, li
params = create_query_parameters(filter_expressions=filter_by, sorting_expressions=sort_by)
data = self.client.get(self._resource_path, parameters=dict(**params, skip=skip, limit=limit))

return Tests([parse_obj_as(FloaterTest, dict(**i, client=self.client)) for i in data])
return Tests(TypeAdapter(List[FloaterTest]).validate_python([dict(**i, client=self.client) for i in data]))

def get_by_id(self, test_id: str) -> FloaterTest:
"""
Expand Down Expand Up @@ -292,7 +292,7 @@ def get(self, filter_by: list = None, sort_by: list = None, skip: int = None, li
params = create_query_parameters(filter_expressions=filter_by, sorting_expressions=sort_by)
data = self.client.get(self._resource_path, parameters=dict(**params, skip=skip, limit=limit))

return Tests([parse_obj_as(WaveCalibration, dict(**i, client=self.client)) for i in data])
return Tests(TypeAdapter(List[WaveCalibration]).validate_python([dict(**i, client=self.client) for i in data]))

def get_by_id(self, test_id: str) -> WaveCalibration:
"""
Expand Down Expand Up @@ -389,7 +389,7 @@ def get(self, filter_by: list = None, sort_by: list = None, skip: int = None, li
params = create_query_parameters(filter_expressions=filter_by, sorting_expressions=sort_by)
data = self.client.get(self._resource_path, parameters=dict(**params, skip=skip, limit=limit))

return Tests([parse_obj_as(WindCalibration, dict(**i, client=self.client)) for i in data])
return Tests(TypeAdapter(List[WindCalibration]).validate_python([dict(**i, client=self.client) for i in data]))

def get_by_id(self, test_id: str) -> WindCalibration:
"""
Expand Down
6 changes: 3 additions & 3 deletions modeltestsdk/api/timeseries.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from typing import Union
from typing import Union, List
from modeltestsdk.resources import (
Statistics, DataPoints, Timeseries, TimeseriesList
)
from modeltestsdk.query import create_query_parameters
from pydantic import parse_obj_as
from pydantic import TypeAdapter
from .base import BaseAPI


Expand Down Expand Up @@ -77,7 +77,7 @@ def get(self, filter_by: list = None, sort_by: list = None, skip: int = None, li
params = create_query_parameters(filter_expressions=filter_by, sorting_expressions=sort_by)
data = self.client.get(self._resource_path, parameters=dict(**params, skip=skip, limit=limit))

return TimeseriesList([parse_obj_as(Timeseries, dict(**i, client=self.client)) for i in data])
return TimeseriesList(TypeAdapter(List[Timeseries]).validate_python([dict(**i, client=self.client) for i in data]))

def get_by_id(self, timeseries_id: str) -> Timeseries:
"""
Expand Down
13 changes: 9 additions & 4 deletions modeltestsdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
import requests_cache
import logging
import numpy as np
try:
from datetime import UTC
except ImportError:
from datetime import timezone
UTC = timezone.utc
from datetime import datetime
from .api import (TimeseriesAPI, CampaignAPI, SensorAPI, TestAPI, FloaterTestAPI, WindCalibrationAPI,
WaveCalibrationAPI, TagsAPI, FloaterConfigAPI)
Expand Down Expand Up @@ -78,7 +83,7 @@ def _request_token(self) -> str:
current_token = os.getenv("INQUIRE_MODELTEST_API_TOKEN")
token_expires_on = os.getenv("INQUIRE_MODELTEST_API_TOKEN_EXPIRES")
if current_token is not None and token_expires_on is not None and \
datetime.utcnow().timestamp() < float(token_expires_on):
datetime.now(UTC).timestamp() < float(token_expires_on):
logging.debug("Your current access token is still valid.")
return current_token

Expand Down Expand Up @@ -236,12 +241,12 @@ def _ensure_serializable(body: dict):

serializable_body = dict()
for key, value in body.items():
if type(value) == np.int64 or type(value) == np.int32:
if isinstance(value, np.int64) or isinstance(value, np.int32):
value = int(value)
elif type(value) == np.float64 or type(value) == np.float32:
elif isinstance(value, np.float64) or isinstance(value, np.float32):
value = float(value)

if (type(value) == float or type(value) == int) and np.isnan(value):
if (isinstance(value, float) or isinstance(value, int)) and np.isnan(value):
value = None

serializable_body[key] = value
Expand Down
2 changes: 1 addition & 1 deletion modeltestsdk/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def create_query_parameters(filter_expressions: list, sorting_expressions: list)
for query_filter in filter_expressions:
if not filter_s == '':
filter_s = filter_s + ','
if not type(query_filter['val']) == str:
if not isinstance(query_filter['val'], str):
query_filter['val'] = str(query_filter['val'])
filter_s = filter_s + query_filter['name'] + '[' + query_filter['op'] + ']' + '=' + query_filter['val']

Expand Down
Loading

0 comments on commit 8f9452d

Please sign in to comment.