Skip to content

Commit

Permalink
Allow packages to customize their name in resolve()
Browse files Browse the repository at this point in the history
  • Loading branch information
elprans committed Oct 13, 2024
1 parent 59711f4 commit 9f33cd5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
12 changes: 9 additions & 3 deletions metapkg/packages/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def slot_suffix(self) -> str:
@classmethod
def get_dep_pkg_name(cls) -> str:
"""Name used by pkg-config or CMake to refer to this package."""
return str(cls.name).upper()
return str(cls.ident).upper()

def get_dep_pkg_config_script(self) -> str | None:
return None
Expand Down Expand Up @@ -435,7 +435,7 @@ class PkgConfigMeta:


class BundledPackage(BasePackage):
name: ClassVar[packaging.utils.NormalizedName]
ident: ClassVar[str]
title: ClassVar[str | None] = None
aliases: ClassVar[list[str] | None] = None
description: str = ""
Expand Down Expand Up @@ -683,6 +683,7 @@ def resolve(
cls: Type[BundledPackage_T],
io: cleo_io.IO,
*,
name: NormalizedName | None = None,
version: str | None = None,
revision: str | None = None,
is_release: bool = False,
Expand Down Expand Up @@ -757,6 +758,7 @@ def resolve(
source_version=source_version,
resolved_sources=sources,
requires=requires,
name=name,
)

@classmethod
Expand Down Expand Up @@ -810,14 +812,18 @@ def __init__(
requires: list[poetry_dep.Dependency] | None = None,
options: Mapping[str, Any] | None = None,
resolved_sources: list[af_sources.BaseSource] | None = None,
name: NormalizedName | None = None,
) -> None:
if self.title is None:
raise RuntimeError(
f"{type(self)!r} does not define the required "
f"title attribute"
)

super().__init__(self.name, version, pretty_version=pretty_version)
if name is None:
name = self.__class__.ident

super().__init__(name, version, pretty_version=pretty_version)

if requires is not None:
reqs = list(requires)
Expand Down
4 changes: 3 additions & 1 deletion metapkg/packages/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def package(
return package

def get_package_info(
self, name: packaging.utils.NormalizedName
self, name: base.NormalizedName
) -> dict[str, Any]:
if name.startswith("pypkg-"):
name = packaging.utils.canonicalize_name(name[len("pypkg-") :])
Expand Down Expand Up @@ -604,6 +604,7 @@ def resolve(
cls: Type[BundledPythonPackage_T],
io: cleo_io.IO,
*,
name: base.NormalizedName | None = None,
version: str | None = None,
revision: str | None = None,
is_release: bool = False,
Expand Down Expand Up @@ -633,6 +634,7 @@ def resolve(

package = cls(
ver,
name=name,
pretty_version=pretty_version,
requires=requires,
source_version=cls.resolve_vcs_version(io, repo),
Expand Down
2 changes: 2 additions & 0 deletions metapkg/packages/rust.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def resolve(
cls,
io: cleo_io.IO,
*,
name: base.NormalizedName | None = None,
version: str | None = None,
revision: str | None = None,
is_release: bool = False,
Expand Down Expand Up @@ -136,6 +137,7 @@ def resolve(
version, pretty_version = cls.format_version(ver)

return cls(
name=name,
version=version,
pretty_version=pretty_version,
source_version=version,
Expand Down

0 comments on commit 9f33cd5

Please sign in to comment.