Skip to content

Commit

Permalink
feat(rez): add "rezPackageCreationCallback"
Browse files Browse the repository at this point in the history
help at achieving specific override per rez package when using rez_pip as python library
  • Loading branch information
MrLixm committed Jan 12, 2024
1 parent 845e61f commit f7b6519
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/rez_pip/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ def run_full_installation(
constraintPath: typing.Optional[typing.List[str]] = None,
rezInstallPath: typing.Optional[str] = None,
rezRelease: bool = False,
rezPackageCreationCallback: typing.Optional[
typing.Callable[
[
rez.package_maker.PackageMaker,
importlib_metadata.Distribution,
rez.version.Version,
bool,
],
None,
]
] = None,
) -> typing.Dict[str, typing.List[rez.package_maker.PackageMaker]]:
"""
Convert and install the given pip packages to rez packages compatible with the given python versions.
Expand All @@ -49,6 +60,10 @@ def run_full_installation(
:param pipArgs: additional argument passed directly to pip
:param pipWorkArea:
filesystem path to an existing directory that can be used for pip to install packages.
:param rezPackageCreationCallback:
a function that is called for each rez package created, signature is as follows:
``callable("package being created", "pip distribution", "python version", "being released")``.
It is being called after the package has been configured by rez_pip.
:return:
dict of rez packages created per python version: ``{"pythonVersion": PackageMaker()}``
Note the PackageMaker object are already "close" and written to disk.
Expand Down Expand Up @@ -126,6 +141,7 @@ def run_full_installation(
wheelURL=package.download_info.url,
prefix=rezInstallPath,
release=rezRelease,
creationCallback=rezPackageCreationCallback,
)
rezPackages.setdefault(pythonVersion, []).append(rezPackage)

Expand Down
14 changes: 14 additions & 0 deletions src/rez_pip/rez.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,17 @@ def createPackage(
wheelURL: str,
prefix: typing.Optional[str] = None,
release: bool = False,
creationCallback: typing.Optional[
typing.Callable[
[
rez.package_maker.PackageMaker,
importlib_metadata.Distribution,
rez.version.Version,
bool,
],
None,
]
] = None,
) -> rez.package_maker.PackageMaker:
_LOG.info(f"Creating rez package for {dist.name}")
name = rez_pip.utils.pythontDistributionNameToRez(dist.name)
Expand Down Expand Up @@ -126,6 +137,9 @@ def make_root(variant: rez.packages.Variant, path: str) -> None:

pkg.pip["metadata"] = remainingMetadata

if creationCallback is not None:
creationCallback(pkg, dist, pythonVersion, release)

_LOG.info(
f"[bold]Created {len(pkg.installed_variants)} variants and skipped {len(pkg.skipped_variants)}"
)
Expand Down

0 comments on commit f7b6519

Please sign in to comment.