Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
DimaAmega committed Mar 27, 2024
1 parent 1414f36 commit 5aebd1e
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 34 deletions.
87 changes: 56 additions & 31 deletions src/evidently/ui/workspace/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,15 @@ class RemoteBase:
def get_url(self):
raise NotImplementedError

def _prepare_request(self, path: str,
method: str,
query_params: Optional[dict] = None,
body: Optional[dict] = None,
cookies=None,
headers: Dict[str, str] = None):
def _prepare_request(
self,
path: str,
method: str,
query_params: Optional[dict] = None,
body: Optional[dict] = None,
cookies=None,
headers: Dict[str, str] = None,
):
# todo: better encoding
cookies = cookies or {}
headers = headers or {}
Expand All @@ -61,22 +64,27 @@ def _prepare_request(self, path: str,
headers["Content-Type"] = "application/json"

data = json.dumps(body, allow_nan=True, cls=NumpyEncoder).encode("utf8")
return Request(method, urllib.parse.urljoin(self.get_url(), path), params=query_params, data=data, headers=headers, cookies=cookies)
return Request(
method,
urllib.parse.urljoin(self.get_url(), path),
params=query_params,
data=data,
headers=headers,
cookies=cookies,
)

def _request(
self,
path: str,
method: str,
query_params: Optional[dict] = None,
body: Optional[dict] = None,
response_model=None,
cookies=None,
headers: Dict[str, str] = None
self,
path: str,
method: str,
query_params: Optional[dict] = None,
body: Optional[dict] = None,
response_model=None,
cookies=None,
headers: Dict[str, str] = None,
):

request = self._prepare_request(
path, method, query_params, body, cookies, headers
)
request = self._prepare_request(path, method, query_params, body, cookies, headers)
s = Session()
response = s.send(request.prepare())

Expand All @@ -99,12 +107,15 @@ class RemoteMetadataStorage(MetadataStorage, RemoteBase):
def get_url(self):
return self.base_url

def _prepare_request(self, path: str,
method: str,
query_params: Optional[dict] = None,
body: Optional[dict] = None,
cookies=None,
headers: Dict[str, str] = None):
def _prepare_request(
self,
path: str,
method: str,
query_params: Optional[dict] = None,
body: Optional[dict] = None,
cookies=None,
headers: Dict[str, str] = None,
):
r = super()._prepare_request(path, method, query_params, body, cookies, headers)
if self.secret is not None:
r.headers[SECRET_HEADER_NAME] = self.secret
Expand Down Expand Up @@ -146,7 +157,9 @@ def search_project(self, project_name: str, project_ids: Optional[Set[ProjectID]
for p in self._request(f"/api/projects/search/{project_name}", "GET", response_model=List[Project])
]

def list_snapshots(self, project_id: ProjectID, include_reports: bool = True, include_test_suites: bool = True) -> List[SnapshotMetadata]:
def list_snapshots(
self, project_id: ProjectID, include_reports: bool = True, include_test_suites: bool = True
) -> List[SnapshotMetadata]:
raise NotImplementedError

def get_snapshot_metadata(self, project_id: ProjectID, snapshot_id: SnapshotID) -> SnapshotMetadata:
Expand Down Expand Up @@ -175,13 +188,25 @@ class NoopDataStorage(DataStorage):
def extract_points(self, project_id: ProjectID, snapshot: Snapshot):
pass

def load_points(self, project_id: ProjectID, filter: ReportFilter, values: List["PanelValue"],
timestamp_start: Optional[datetime.datetime],
timestamp_end: Optional[datetime.datetime]) -> DataPoints:
def load_points(
self,
project_id: ProjectID,
filter: ReportFilter,
values: List["PanelValue"],
timestamp_start: Optional[datetime.datetime],
timestamp_end: Optional[datetime.datetime],
) -> DataPoints:
return []

def load_test_results(self, project_id: ProjectID, filter: ReportFilter, test_filters: List[TestFilter], time_agg: Optional[str],
timestamp_start: Optional[datetime.datetime], timestamp_end: Optional[datetime.datetime]) -> TestResultPoints:
def load_test_results(
self,
project_id: ProjectID,
filter: ReportFilter,
test_filters: List[TestFilter],
time_agg: Optional[str],
timestamp_start: Optional[datetime.datetime],
timestamp_end: Optional[datetime.datetime],
) -> TestResultPoints:
return {}


Expand All @@ -200,7 +225,7 @@ def __init__(self, base_url: str, secret: Optional[str] = None):
metadata=(RemoteMetadataStorage(base_url=self.base_url, secret=self.secret)),
blob=(NoopBlobStorage()),
data=(NoopDataStorage()),
auth=(NoopAuthManager())
auth=(NoopAuthManager()),
)
super().__init__(None, pm)
self.verify()
Expand Down
18 changes: 15 additions & 3 deletions src/evidently/ui/workspace/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,27 @@


class WorkspaceView(WorkspaceBase):
def __init__(self, user_id: Optional[UserID], project_manager: ProjectManager, team_id: Optional[TeamID] = None, org_id: Optional[OrgID] = None):
def __init__(
self,
user_id: Optional[UserID],
project_manager: ProjectManager,
team_id: Optional[TeamID] = None,
org_id: Optional[OrgID] = None,
):
self.project_manager = project_manager
self.user_id = user_id or ZERO_UUID
self.team_id = team_id or ZERO_UUID
self.org_id = org_id or ZERO_UUID

def create_project(self, name: str, description: Optional[str] = None, team_id: TeamID = None) -> Project:
return self.project_manager.create_project(name, user_id=self.user_id, team_id=team_id or self.team_id, org_id=self.org_id, description=description)
return self.project_manager.create_project(
name, user_id=self.user_id, team_id=team_id or self.team_id, org_id=self.org_id, description=description
)

def add_project(self, project: Project, team_id: TeamID = None) -> Project:
project = self.project_manager.add_project(project, user_id=self.user_id, team_id=team_id or self.team_id, org_id=self.org_id)
project = self.project_manager.add_project(
project, user_id=self.user_id, team_id=team_id or self.team_id, org_id=self.org_id
)
return project

def get_project(self, project_id: STR_UUID) -> Optional[Project]:
Expand Down Expand Up @@ -59,6 +69,7 @@ def search_project(self, project_name: str) -> List[Project]:
class LocalWorkspaceView(WorkspaceView):
def __init__(self, path: str):
from evidently.ui.storage.local import create_local_project_manager

self.path = path
super().__init__(None, create_local_project_manager(path=path, autorefresh=False))

Expand All @@ -68,6 +79,7 @@ def create(cls, path: str):

def refresh(self):
from evidently.ui.storage.local import create_local_project_manager

self.project_manager = create_local_project_manager(path=self.path, autorefresh=False)


Expand Down

0 comments on commit 5aebd1e

Please sign in to comment.