Skip to content

Commit

Permalink
repo: permit file URLs (#93)
Browse files Browse the repository at this point in the history
  • Loading branch information
lengau authored Jul 3, 2023
1 parent be875b0 commit 6f787ea
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion craft_archives/repo/package_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from pydantic import (
AnyUrl,
ConstrainedStr,
FileUrl,
root_validator, # pyright: ignore[reportUnknownVariableType]
validator, # pyright: ignore[reportUnknownVariableType]
)
Expand Down Expand Up @@ -220,7 +221,7 @@ def pin(self) -> str:
class PackageRepositoryApt(PackageRepository):
"""An APT package repository."""

url: AnyUrl
url: Union[AnyUrl, FileUrl]
key_id: KeyIdStr = pydantic.Field(alias="key-id")
architectures: Optional[List[str]]
formats: Optional[List[Literal["deb", "deb-src"]]]
Expand Down
8 changes: 7 additions & 1 deletion tests/unit/repo/test_package_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,20 @@ def test_apt_name():
"key-server": "my-key-server",
"suites": ["some", "suites"],
},
{ # File URLs. See: https://github.com/canonical/craft-archives/issues/92
"type": "apt",
"url": "file:///tmp/apt-repo",
"path": "my/path",
"key-id": "BCDEF12345" * 4,
},
],
)
def test_apt_valid(repo, priority):
if priority is not None:
repo["priority"] = priority
apt_deb = PackageRepositoryApt.unmarshal(repo)
assert apt_deb.type == "apt"
assert apt_deb.url == "https://some/url"
assert apt_deb.url == repo["url"]
assert apt_deb.key_id == "BCDEF12345" * 4
assert apt_deb.formats == (["deb"] if "formats" in repo else None)
assert apt_deb.components == (
Expand Down

0 comments on commit 6f787ea

Please sign in to comment.