Skip to content

Define pkg as a PackageURL class attribute - #184

Merged
tdruez merged 4 commits into
package-url:mainfrom
jaimergp:pkg-class-attr
Jun 6, 2025
Merged

Define pkg as a PackageURL class attribute#184
tdruez merged 4 commits into
package-url:mainfrom
jaimergp:pkg-class-attr

Conversation

@jaimergp

@jaimergpjaimergp commented Mar 6, 2025

Copy link
Copy Markdown
Contributor

This will allow library users to subclass PackageURL and redefine the scheme to create PURL-like derivatives. (e.g. for the dep: idea described here):

classDependencyURL(PackageURL):
SCHEME="dep"

Which can be used in the same way and happily accepts PEP440-like version ranges in the version field 🥳:

>>>dep=DependencyURL.from_string("dep:pypi/requests@>=2.0")
>>>depDependencyURL(type='pypi', namespace=None, name='requests', version='>=2.0', qualifiers={}, subpath=None)

@pombredanne

Copy link
Copy Markdown
Member

@jaimergp this is fine by me BTW... no objections to make it easier to reuse!

@pombredanne

Copy link
Copy Markdown
Member

Ah, I see, this is now with #186

@jaimergp

Copy link
Copy Markdown
ContributorAuthor

Ah, @pombredanne, if you are fine with this type of change, yes, please, let's reopen!

@johnmhoranjohnmhoran reopened this May 14, 2025
@jaimergp

Copy link
Copy Markdown
ContributorAuthor

@pombredanne (or anyone with merge rights!) gentle ping for a hopefully uncontroversial review!

Comment threadsrc/packageurl/__init__.py Outdated
https://github.com/package-url/purl-spec
"""

SCHEME: str = "pkg"

Copy link
Copy Markdown
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
Copy Markdown
ContributorAuthor

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
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Changed to ClassVar[str]

Comment threadsrc/packageurl/__init__.py Outdated
@jaimergp

Copy link
Copy Markdown
ContributorAuthor

Thanks @tdruez, let me know if I addressed your concerns!

@tdruez

Copy link
Copy Markdown
Collaborator

@jaimergp Thanks! LGTM.

@pombredanne Could you give it another look and take care of the merge?

@pombredannepombredanne left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

All fine! Thanks!

@tdruez
tdruez merged commit d96295c into package-url:mainJun 6, 2025
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@jaimergp@pombredanne@tdruez@johnmhoran