Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
57 changes: 49 additions & 8 deletions metapkg/packages/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import sys
import textwrap

import packaging.version
import packaging.utils

from poetry.core.packages import dependency as poetry_dep
Expand Down Expand Up @@ -62,6 +63,32 @@

Args: TypeAlias = dict[str, Union[str, pathlib.Path, None]]

_PEP440_PATTERN = re.sub(
r"\?P<\w+>",
"",
packaging.version.VERSION_PATTERN,
)

# fmt: off
_PATCH_FILE_RE = re.compile(
r"""^
(?P<pkg_name>[A-Za-z0-9]+(?:[._-][A-Za-z0-9]+)*)
__
(?P<patch_name>[A-Za-z0-9]+(?:[._-][A-Za-z0-9]+)*)
(?:
__
(?:
(?P<v1>""" + _PEP440_PATTERN + r""")
(?:(?P<vrange>-)(?P<v2>""" + _PEP440_PATTERN + r""")?)?
|
- (?P<v2_open>""" + _PEP440_PATTERN + r""")
)
)?
$""",
re.VERBOSE | re.IGNORECASE,
)
# fmt: on


class AliasPackage(poetry_pkg.Package):
def __repr__(self) -> str:
Expand Down Expand Up @@ -853,15 +880,29 @@ def get_patches(
modpath = pathlib.Path(sys.modules[self.__module__].__path__[0])
patches_dir = modpath / "patches"

if not patches_dir.exists():
return {}

patches = collections.defaultdict(list)
if patches_dir.exists():
for path in patches_dir.glob("*.patch"):
with open(path, "r") as f:
pkg, _, rest = path.stem.partition("__")
patches[pkg].append((rest, f.read()))

for pkg, plist in patches.items():
plist.sort(key=lambda i: i[0])
for path in patches_dir.glob("*.patch"):
m = _PATCH_FILE_RE.match(path.stem)
if not m:
raise ValueError(f"malformed patch name: {path.name}")

pkg: str = m.group("pkg_name")
patch_name: str = m.group("patch_name")
constraints = []
if min_ver_str := m.group("v1"):
op = ">=" if m.group("vrange") else "=="
constraints.append(f"{op} {min_ver_str}")

if max_ver_str := (m.group("v2") or m.group("v2_open")):
constraints.append(f"< {max_ver_str}")

if not constraints or poetry_version.parse_constraint(
",".join(constraints)
).allows(self.version):
patches[pkg].append((patch_name, path.read_text()))

return patches

Expand Down
6 changes: 3 additions & 3 deletions metapkg/targets/macos/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ def _package(self, files: list[pathlib.Path]) -> None:

dist_xml = minidom.parse(str(distribution))
gui_xml = dist_xml.documentElement
assert gui_xml is not None

for name in resources:
res_type = pathlib.Path(name).stem.lower()
Expand All @@ -255,9 +256,8 @@ def _package(self, files: list[pathlib.Path]) -> None:
title_el.appendChild(title_text)
gui_xml.appendChild(title_el)

options = gui_xml.getElementsByTagName("options")
if options:
options = options[0]
if options_els := gui_xml.getElementsByTagName("options"):
options = options_els[0]
else:
options = dist_xml.createElement("options")
gui_xml.appendChild(options)
Expand Down
Loading