8000 Refactor/Chore: Remove access parameters in client by j279li · Pull Request #290 · polaris-hub/polaris · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Refactor/Chore: Remove access parameters in client #290

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions polaris/benchmark/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
from polaris.utils.dict2html import dict2html
from polaris.utils.errors import InvalidBenchmarkError
from polaris.utils.types import (
AccessType,
HubOwner,
IncomingPredictionsType,
TargetType,
Expand Down Expand Up @@ -171,7 +170,6 @@ def upload_to_hub(
self,
settings: PolarisHubSettings | None = None,
cache_auth_token: bool = True,
access: AccessType = "private",
owner: HubOwner | str | None = None,
parent_artifact_id: str | None = None,
**kwargs: dict,
Expand All @@ -187,9 +185,7 @@ def upload_to_hub(
cache_auth_token=cache_auth_token,
**kwargs,
) as client:
return client.upload_benchmark(
self, access=access, owner=owner, parent_artifact_id=parent_artifact_id
)
return client.upload_benchmark(self, owner=owner, parent_artifact_id=parent_artifact_id)

def to_json(self, destination: str) -> str:
"""Save the benchmark to a destination directory as a JSON file.
Expand Down
2 changes: 0 additions & 2 deletions polaris/dataset/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
from polaris.utils.dict2html import dict2html
from polaris.utils.errors import InvalidDatasetError
from polaris.utils.types import (
AccessType,
ChecksumStrategy,
DatasetIndex,
HttpUrlString,
Expand Down Expand Up @@ -304,7 +303,6 @@ def get_data(
@abc.abstractmethod
def upload_to_hub(
self,
access: AccessType = "private",
owner: HubOwner | str | None = None,
parent_artifact_id: str | None = None,
):
Expand Down
4 changes: 1 addition & 3 deletions polaris/dataset/_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from polaris.mixins._checksum import ChecksumMixin
from polaris.utils.errors import InvalidDatasetError
from polaris.utils.types import (
AccessType,
ChecksumStrategy,
HubOwner,
ZarrConflictResolution,
Expand Down Expand Up @@ -220,7 +219,6 @@ def get_data(

def upload_to_hub(
self,
access: AccessType = "private",
owner: HubOwner | str | None = None,
parent_artifact_id: str | None = None,
):
Expand All @@ -231,7 +229,7 @@ def upload_to_hub(
from polaris.hub.client import PolarisHubClient

with PolarisHubClient() as client:
client.upload_dataset(self, owner=owner, access=access, parent_artifact_id=parent_artifact_id)
client.upload_dataset(self, owner=owner, parent_artifact_id=parent_artifact_id)

@classmethod
def from_json(cls, path: str):
Expand Down
5 changes: 2 additions & 3 deletions polaris/dataset/_dataset_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from polaris.dataset._base import BaseDataset
from polaris.dataset.zarr._manifest import calculate_file_md5, generate_zarr_manifest
from polaris.utils.errors import InvalidDatasetError
from polaris.utils.types import AccessType, ChecksumStrategy, HubOwner, ZarrConflictResolution
from polaris.utils.types import ChecksumStrategy, HubOwner, ZarrConflictResolution

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -194,7 +194,6 @@ def get_data(self, row: int, col: str, adapters: dict[str, Adapter] | None = Non

def upload_to_hub(
self,
access: AccessType = "private",
owner: HubOwner | str | None = None,
parent_artifact_id: str | None = None,
):
Expand All @@ -205,7 +204,7 @@ def upload_to_hub(
from polaris.hub.client import PolarisHubClient

with PolarisHubClient() as client:
client.upload_dataset(self, owner=owner, access=access, parent_artifact_id=parent_artifact_id)
client.upload_dataset(self, owner=owner, parent_artifact_id=parent_artifact_id)

@classmethod
def from_json(cls, path: str):
Expand Down
4 changes: 1 addition & 3 deletions polaris/evaluate/_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from polaris.utils.errors import InvalidResultError
from polaris.utils.misc import slugify
from polaris.utils.types import (
AccessType,
HubOwner,
SlugCompatibleStringType,
)
Expand Down Expand Up @@ -173,7 +172,6 @@ def set_benchmark_artifact_id(self):

def upload_to_hub(
self,
access: AccessType = "private",
owner: HubOwner | str | None = None,
**kwargs: dict,
):
Expand All @@ -184,7 +182,7 @@ def upload_to_hub(
from polaris.hub.client import PolarisHubClient

with PolarisHubClient(**kwargs) as client:
return client.upload_results(self, access=access, owner=owner)
return client.upload_results(self, owner=owner)


class BenchmarkResultsV1(EvaluationResultV1, BaseBenchmarkResults):
Expand Down
31 changes: 6 additions & 25 deletions polaris/hub/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
PolarisUnauthorizedError,
)
from polaris.utils.types import (
AccessType,
ChecksumStrategy,
HubOwner,
SupportedLicenseType,
Expand Down Expand Up @@ -497,7 +496,6 @@ def _get_v2_benchmark(self, owner: str | HubOwner, slug: str) -> BenchmarkV2Spec
def upload_results(
self,
results: BenchmarkResultsV1 | BenchmarkResultsV2,
access: AccessType = "private",
owner: HubOwner | str | None = None,
):
"""Upload the results to the Polaris Hub.
Expand All @@ -515,7 +513,6 @@ def upload_results(

Args:
results: The results to upload.
access: Grant public or private access to result
owner: Which Hub user or organization owns the artifact. Takes precedence over `results.owner`.
"""
with track_progress(description="Uploading results", total=1) as (progress, task):
Expand All @@ -524,9 +521,7 @@ def upload_results(
result_json = results.model_dump(by_alias=True, exclude_none=True)

# Make a request to the Hub
response = self._base_request_to_hub(
url="/v2/result", method="POST", json={"access": access, **result_json}
)
response = self._base_request_to_hub(url="/v2/result", method="POST", json=result_json)

# Inform the user about where to find their newly created artifact.
result_url = urljoin(self.settings.hub_url, response.headers.get("Content-Location"))
Expand All @@ -538,7 +533,6 @@ def upload_results(
def upload_dataset(
self,
dataset: DatasetV1 | DatasetV2,
access: AccessType = "private",
timeout: TimeoutTypes = (10, 200),
owner: HubOwner | str | None = None,
if_exists: ZarrConflictResolution = "replace",
Expand All @@ -558,7 +552,6 @@ def upload_dataset(

Args:
dataset: The dataset to upload.
access: Grant public or private access to result
timeout: Request timeout values. User can modify the value when uploading large dataset as needed.
This can be a single value with the timeout in seconds for all IO operations, or a more granular
tuple with (connect_timeout, write_timeout). The type of the the timout parameter comes from `httpx`.
Expand All @@ -580,15 +573,14 @@ def upload_dataset(
)

if isinstance(dataset, DatasetV1):
self._upload_v1_dataset(dataset, timeout, access, owner, if_exists, parent_artifact_id)
self._upload_v1_dataset(dataset, timeout, owner, if_exists, parent_artifact_id)
elif isinstance(dataset, DatasetV2):
self._upload_v2_dataset(dataset, timeout, access, owner, if_exists, parent_artifact_id)
self._upload_v2_dataset(dataset, timeout, owner, if_exists, parent_artifact_id)

def _upload_v1_dataset(
self,
dataset: DatasetV1,
timeout: TimeoutTypes,
access: AccessType,
owner: HubOwner | str | None,
if_exists: ZarrConflictResolution,
parent_artifact_id: str | None,
Expand Down Expand Up @@ -632,7 +624,6 @@ def _upload_v1_dataset(
"md5Sum": parquet_md5,
},
"zarrContent": [md5sum.model_dump() for md5sum in dataset._zarr_md5sum_manifest],
"access": access,
"parentArtifactId": parent_artifact_id,
**dataset_json,
},
Expand Down Expand Up @@ -677,7 +668,6 @@ def _upload_v2_dataset(
self,
dataset: DatasetV2,
timeout: TimeoutTypes,
access: AccessType,
owner: HubOwner | str | None,
if_exists: ZarrConflictResolution,
parent_artifact_id: str | None,
Expand All @@ -700,7 +690,6 @@ def _upload_v2_dataset(
"zarrManifestFileContent": {
"md5Sum": dataset.zarr_manifest_md5sum,
},
"access": access,
"parentArtifactId": parent_artifact_id,
**dataset_json,
},
Expand Down Expand Up @@ -748,7 +737,6 @@ def _upload_v2_dataset(
def upload_benchmark(
self,
benchmark: BenchmarkV1Specification | BenchmarkV2Specification,
access: AccessType = "private",
owner: HubOwner | str | None = None,
parent_artifact_id: str | None = None,
):
Expand All @@ -770,20 +758,18 @@ def upload_benchmark(

Args:
benchmark: The benchmark to upload.
access: Grant public or private access to result
owner: Which Hub user or organization owns the artifact. Takes precedence over `benchmark.owner`.
parent_artifact_id: The `owner/slug` of the parent benchmark, if uploading a new version of a benchmark.
"""
match benchmark:
case BenchmarkV1Specification():
self._upload_v1_benchmark(benchmark, access, owner, parent_artifact_id)
self._upload_v1_benchmark(benchmark, owner, parent_artifact_id)
case BenchmarkV2Specification():
self._upload_v2_benchmark(benchmark, access, owner, parent_artifact_id)
self._upload_v2_benchmark(benchmark, owner, parent_artifact_id)

def _upload_v1_benchmark(
self,
benchmark: BenchmarkV1Specification,
access: AccessType = "private",
owner: HubOwner | str | None = None,
parent_artifact_id: str | None = None,
):
Expand All @@ -796,7 +782,6 @@ def _upload_v1_benchmark(
benchmark.owner = HubOwner.normalize(owner or benchmark.owner)
benchmark_json = benchmark.model_dump(exclude={"dataset"}, exclude_none=True, by_alias=True)
benchmark_json["datasetArtifactId"] = benchmark.dataset.artifact_id
benchmark_json["access"] = access

url = f"/v1/benchmark/{benchmark.artifact_id}"
response = self._base_request_to_hub(
Expand All @@ -811,7 +796,6 @@ def _upload_v1_benchmark(
def _upload_v2_benchmark(
self,
benchmark: BenchmarkV2Specification,
access: AccessType = "private",
owner: HubOwner | str | None = None,
parent_artifact_id: str | None = None,
):
Expand All @@ -834,7 +818,6 @@ def _upload_v2_benchmark(
url=url,
method="PUT",
json={
"access": access,
"datasetArtifactId": benchmark.dataset.artifact_id,
"parentArtifactId": parent_artifact_id,
**benchmark_json,
Expand Down Expand Up @@ -940,7 +923,6 @@ def get_model(self, artifact_id: str) -> Model:
def upload_model(
self,
model: Model,
access: AccessType = "private",
owner: HubOwner | str | None = None,
parent_artifact_id: str | None = None,
):
Expand All @@ -958,7 +940,6 @@ def upload_model(

Args:
model: The model to upload.
access: Grant public or private access to result
owner: Which Hub user or organization owns the artifact. Takes precedence over `model.owner`.
parent_artifact_id: The `owner/slug` of the parent model, if uploading a new version of a model.
"""
Expand All @@ -972,7 +953,7 @@ def upload_model(
response = self._base_request_to_hub(
url=url,
method="PUT",
json={"access": access, "parentArtifactId": parent_artifact_id, **model_json},
json={"parentArtifactId": parent_artifact_id, **model_json},
)

# NOTE: When we merge in the competition model feature, we will need to update the slug with the inserted model slug to make sure we write to the correct storage location.
Expand Down
9 changes: 4 additions & 5 deletions polaris/model/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from polaris._artifact import BaseArtifactModel
from polaris.utils.types import HttpUrlString
from polaris.utils.types import AccessType, HubOwner
from polaris.utils.types import HubOwner
from pydantic import Field


Expand Down Expand Up @@ -35,8 +35,8 @@ class Model(BaseArtifactModel):
artifact_changelog: A description of the changes made in this model version.

Methods:
upload_to_hub(access: AccessType = "private", owner: HubOwner | str | None = None):
Uploads the model artifact to the Polaris Hub, associating it with a specified owner and access level.
upload_to_hub(owner: HubOwner | str | None = None):
Uploads the model artifact to the Polaris Hub, associating it with a specified owner.

For additional metadata attributes, see the base class.
"""
Expand All @@ -53,7 +53,6 @@ class Model(BaseArtifactModel):

def upload_to_hub(
self,
access: AccessType = "private",
owner: HubOwner | str | None = None,
parent_artifact_id: str | None = None,
):
Expand All @@ -63,4 +62,4 @@ def upload_to_hub(
from polaris.hub.client import PolarisHubClient

with PolarisHubClient() as client:
client.upload_model(self, owner=owner, access=access, parent_artifact_id=parent_artifact_id)
client.upload_model(self, owner=owner, parent_artifact_id=parent_artifact_id)
5 changes: 0 additions & 5 deletions polaris/utils/types.py
528C
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,6 @@
This can be used to sort the metric score, indicate the optmization direction of endpoint.
"""

AccessType: TypeAlias = Literal["public", "private"]
"""
Type to specify access to a dataset, benchmark or result in the Hub.
"""

TimeoutTypes = tuple[int, int] | Literal["timeout", "never"]
"""
Timeout types for specifying maximum wait times.
Expand Down
0