Skip to content
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

Introduce a new enum class to clean up conditional URL logic in the PolarisHubClient #180

Open
Andrewq11 opened this issue Aug 20, 2024 · 0 comments

Comments

@Andrewq11
Copy link
Contributor

Context

Due to the addition of competitions on Polaris, we've had to introduce many conditionals in the PolarisHubClient to manage which APIs are triggered based on the artifact type (e.g. standard or competition) being processed. While these conditional work, they introduce complexities that reduce readability and future extensibility.

As per this comment on #121, we should introduce an additional enum class to better handle these conditionals in a way that is cleaner and offers better extensibility when new artifacts are introduced in the future.

Description

A new enum class should be created that will abstract away much of the complexity associated with managing important data points that are tied to an artifact but not included in the artifact's model (e.g. hub_url). It could look something like this (as suggested in the above PR comment):

from enum import Enum

class ArtifactType(Enum):
    DATASET = ("dataset", "{api_url}/v1/dataset/{owner}/{name}", Dataset)
    BENCHMARK = ("benchmark", "{api_url}/v1/benchmark/{owner}/{name}", BenchmarkSpecification)
    COMPETITION = ("competition", "{api_url}/v2/competition/{owner}/{name}", Competition)
    COMPETITION_DATASET = ("competition_dataset", "{api_url}/v2/competition/datasets/{owner}/{name}", CompetitionDataset)

    def __init__(self, name: str, url_pattern: str, model: BaseArtifactModel):
        self.name = name
        self.url_pattern = url_pattern
        self.model = model

    def get_url(self, owner: str, name: str):
        return self.url_pattern.format(api_url=settings.api_url, owner=owner, name=name)

Acceptance Criteria

  • The enum should expose the correct base Hub URL for an artifact based on the artifact type
  • Replace the conditionals in the PolarisHubClient to use an instantiated object from the new enum class
  • All impacted client methods must trigger the correct Hub URL given the artifact type being processed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant