-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
89 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from ._backoffice import BackOffice |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import os | ||
from typing import Literal, Optional | ||
|
||
from bioimageio.spec.model.v0_5 import WeightsFormat | ||
from dotenv import load_dotenv | ||
|
||
from backoffice.backup import backup | ||
from backoffice.run_dynamic_tests import run_dynamic_tests | ||
from backoffice.utils.remote_resource import ( | ||
PublishedVersion, | ||
RemoteResource, | ||
StagedVersion, | ||
) | ||
from backoffice.utils.s3_client import Client | ||
from backoffice.validate_format import validate_format | ||
|
||
_ = load_dotenv() | ||
|
||
|
||
class BackOffice: | ||
def __init__( | ||
self, | ||
host: str = os.environ["S3_HOST"], | ||
bucket: str = os.environ["S3_BUCKET"], | ||
prefix: str = os.environ["S3_FOLDER"], | ||
) -> None: | ||
super().__init__() | ||
self.client = Client(host=host, bucket=bucket, prefix=prefix) | ||
|
||
def stage(self, resource_id: str, package_url: str): | ||
resource = RemoteResource(client=Client(), id=resource_id) | ||
staged = resource.stage_new_version(package_url) | ||
validate_format(staged) | ||
|
||
def test( | ||
self, | ||
resource_id: str, | ||
version: int, | ||
weight_format: Optional[WeightsFormat] = None, | ||
create_env_outcome: Literal["success", ""] = "success", | ||
): | ||
staged = StagedVersion(self.client, resource_id, version) | ||
run_dynamic_tests( | ||
staged=staged, | ||
weight_format=weight_format, | ||
create_env_outcome=create_env_outcome, | ||
) | ||
|
||
def await_review(self, resource_id: str, stage_nr: int): | ||
staged = StagedVersion(self.client, resource_id, stage_nr) | ||
staged.await_review() | ||
|
||
def publish(self, resource_id: str, stage_nr: int): | ||
staged = StagedVersion(self.client, resource_id, stage_nr) | ||
published = staged.publish() | ||
assert isinstance(published, PublishedVersion) | ||
|
||
def backup(self, destination: str = os.environ["ZENODO_URL"]): | ||
_ = backup(self.client, destination) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
import os | ||
|
||
from dotenv import load_dotenv | ||
from loguru import logger | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import os | ||
|
||
from backoffice import BackOffice | ||
|
||
|
||
def test_backoffice( | ||
backoffice: BackOffice, package_url: str, package_id: str, s3_test_folder_url: str | ||
): | ||
backoffice.stage(resource_id=package_id, package_url=package_url) | ||
backoffice.await_review(resource_id=package_id, stage_nr=1) | ||
backoffice.publish(resource_id=package_id, stage_nr=1) | ||
backoffice.backup(os.environ["ZENODO_TEST_URL"]) |