Skip to content

Commit

Permalink
Fix bug with requirements of merged packages
Browse files Browse the repository at this point in the history
Signed-off-by: Jean-Christophe Morin <[email protected]>
  • Loading branch information
JeanChristopheMorinPerso committed Feb 4, 2024
1 parent c7edc67 commit 2f44f75
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
3 changes: 1 addition & 2 deletions src/rez_pip/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,9 @@ def _run(args: argparse.Namespace, pipArgs: typing.List[str], pipWorkArea: str)
for group in packageGroups:
print(list(package.name for package in group.packages))
rez_pip.rez.createPackage(
group.dists,
group,
rez.version.Version(pythonVersion),
installedWheelsDir,
group.downloadUrls,
prefix=args.prefix,
release=args.release,
)
Expand Down
35 changes: 26 additions & 9 deletions src/rez_pip/rez.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,37 +26,54 @@


def createPackage(
dists: typing.List[importlib_metadata.Distribution],
packageGroup: rez_pip.pip.PackageGroup,
pythonVersion: rez.version.Version,
installedWheelsDir: str,
urls: typing.List[str],
prefix: typing.Optional[str] = None,
release: bool = False,
) -> None:
_LOG.info(
"Creating rez package for {0}".format(" + ".join(dist.name for dist in dists))
"Creating rez package for {0}".format(
" + ".join(dist.name for dist in packageGroup.dists)
)
)

rezNames = [
rez_pip.utils.pythontDistributionNameToRez(dist.name)
for dist in packageGroup.dists
]

name = rezNames[0]
version = rez_pip.utils.pythonDistributionVersionToRez(
packageGroup.dists[0].version
)
name = rez_pip.utils.pythontDistributionNameToRez(dists[0].name)
version = rez_pip.utils.pythonDistributionVersionToRez(dists[0].version)

requires = []
variant_requires = []
metadata: typing.Dict[str, typing.Any] = {}
isPure = True
for dist in dists:
for dist in packageGroup.dists:
requirements = rez_pip.utils.getRezRequirements(dist, pythonVersion, [])
if not metadata:
# For now we only use the metadata from the first package. Far from ideal...
metadata = requirements.metadata

# TODO: Remove grouped packages (PySide-Addons, etc)
requires += [
require for require in requirements.requires if require not in requires
require
for require in requirements.requires
if require not in requires
# Check that the rez requirement isn't in the group name since it would be
# an invalid requirement (because we merge them).
and rez.version.Requirement(require).name not in rezNames[1:]
]
variant_requires += [
require
for require in requirements.variant_requires
if require not in variant_requires
# Check that the rez requirement isn't in the group name since it would be
# an invalid requirement (because we merge them).
and rez.version.Requirement(require).name not in rezNames[1:]
]
if isPure:
isPure = metadata["is_pure_python"]
Expand All @@ -80,7 +97,7 @@ def make_root(variant: rez.packages.Variant, path: str) -> None:
_LOG.info(
rf"Installing {variant.qualified_package_name} \[{formattedRequirements}]"
)
for dist in dists:
for dist in packageGroup.dists:
if not dist.files:
raise RuntimeError(
f"{dist.name} package has no files registered! Something is wrong maybe?"
Expand Down Expand Up @@ -140,7 +157,7 @@ def make_root(variant: rez.packages.Variant, path: str) -> None:
"name": dist.name,
"version": dist.version,
"is_pure_python": isPure,
"wheel_urls": urls,
"wheel_urls": packageGroup.downloadUrls,
"rez_pip_version": importlib_metadata.version("rez-pip"),
}

Expand Down

0 comments on commit 2f44f75

Please sign in to comment.