Skip to content
Merged
Changes from 2 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
10 changes: 7 additions & 3 deletions src/packageurl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ class PackageURL(
https://github.com/package-url/purl-spec
"""

SCHEME: str = "pkg"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if using lower-caps scheme for consistency with existing vars would make more sense. I don't see anything declared as upper-caps in that module.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used uppercase because it's supposed to be constant for the class, maybe I can indicate that with ClassVar[str] instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to ClassVar[str]


type: str
namespace: str | None
name: str
Expand Down Expand Up @@ -409,7 +411,7 @@ def to_string(self) -> str:
encode=True,
)

purl = ["pkg:", type, "/"]
purl = [f"{self.SCHEME}:", type, "/"]

if namespace:
purl.extend((namespace, "/"))
Expand Down Expand Up @@ -440,8 +442,10 @@ def from_string(cls, purl: str) -> Self:
raise ValueError("A purl string argument is required.")

scheme, sep, remainder = purl.partition(":")
if not sep or scheme != "pkg":
raise ValueError(f'purl is missing the required "pkg" scheme component: {purl!r}.')
if not sep or scheme != cls.SCHEME:
raise ValueError(
f'purl is missing the required "{cls.SCHEME}" scheme component: {purl!r}.'
)

# this strip '/, // and /// as possible in :// or :///
remainder = remainder.strip().lstrip("/")
Expand Down
Loading