Skip to content

Commit

Permalink
Compute URL for URL packages
Browse files Browse the repository at this point in the history
  • Loading branch information
koterpillar committed Oct 8, 2023
1 parent a93a0c0 commit a3fb348
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions mybox/package/url.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
from urllib.parse import urlparse

from ..utils import url_version
from pydantic import Field

from ..compute import Const, Value
from ..utils import async_cached, url_version
from .archive import ArchivePackage


class URLPackage(ArchivePackage):
url: str
url_: Value = Field(..., alias="url")

@async_cached
async def url(self) -> str:
return await self.url_.compute()

async def archive_url(self) -> str:
return self.url
return await self.url()

def derive_name(self) -> str:
url = urlparse(self.url)
if isinstance(self.url_, Const):
url_str = self.url_.value
else:
raise ValueError("Cannot derive name from computed URL and no name override.")

url = urlparse(url_str)

name = url.hostname or ""

Expand All @@ -21,4 +33,4 @@ def derive_name(self) -> str:
return name

async def get_remote_version(self) -> str:
return url_version(self.url)
return url_version(await self.url())

0 comments on commit a3fb348

Please sign in to comment.