-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit adding a plugin system and a PySide6 plugin
Signed-off-by: Jean-Christophe Morin <[email protected]>
- Loading branch information
1 parent
b593438
commit 5163f94
Showing
9 changed files
with
369 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
======= | ||
Plugins | ||
======= | ||
|
||
.. autoclass:: rez_pip.plugins.PluginSpec |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
"""PySide6 plugin. | ||
For PySide6, we need a merge hook. If User says "install PySide6", we need to install PySide6, PySide6-Addons and PySide6-Essentials and shiboken6. | ||
But PySide6, PySide6-Addons and PySide6-Essentials have to be merged. Additionally, shiboken6 needs to be broken down to remove PySide6 (core). | ||
Because shiboken6 vendors PySide6-core... See https://inspector.pypi.io/project/shiboken6/6.6.1/packages/bb/72/e54f758e49e8da0dcd9490d006c41a814b0e56898ce4ca054d60cdba97bd/shiboken6-6.6.1-cp38-abi3-manylinux_2_28_x86_64.whl/. | ||
On Windows, the PySide6/openssl folder has to be added to PATH, see https://inspector.pypi.io/project/pyside6/6.6.1/packages/ec/3d/1da1b88d74cb5318466156bac91f17ad4272c6c83a973e107ad9a9085009/PySide6-6.6.1-cp38-abi3-win_amd64.whl/PySide6/__init__.py#line.81. | ||
So it's at least a 3 steps process: | ||
1. Merge PySide6, PySide6-Essentials and PySide6-Addons into the same install. Unvendor shiboken. | ||
2. Install shiboken + cleanup. The Cleanup could be its own hook here specific to shiboken. | ||
""" | ||
import sys | ||
import typing | ||
import logging | ||
import collections | ||
|
||
if sys.version_info >= (3, 10): | ||
import importlib.metadata as importlib_metadata | ||
else: | ||
import importlib_metadata | ||
|
||
import packaging.utils | ||
import packaging.version | ||
import packaging.specifiers | ||
import packaging.requirements | ||
|
||
import rez_pip.pip | ||
import rez_pip.plugins | ||
import rez_pip.exceptions | ||
|
||
# PySide6 was initiall a single package that had shiboken as a dependency. | ||
# Starting from 6.3.0, the package was spit in 3, PySide6, PySide6-Essentials and | ||
# PySide6-Addons. | ||
|
||
|
||
_LOG = logging.getLogger(__name__) | ||
|
||
|
||
@rez_pip.plugins.hookimpl | ||
def prePipResolve( | ||
packages: typing.List[str], | ||
) -> None: | ||
_LOG.debug(f"prePipResolve start") | ||
pyside6Seen = False | ||
variantsSeens = [] | ||
|
||
for package in packages: | ||
req = packaging.requirements.Requirement(package) | ||
name = packaging.utils.canonicalize_name(req.name) | ||
|
||
if name == "pyside6": | ||
pyside6Seen = True | ||
elif name in ["pyside6-essentials", "pyside6-addons"]: | ||
variantsSeens.append(req.name) | ||
|
||
if variantsSeens and not pyside6Seen: | ||
variants = " and ".join(variantsSeens) | ||
verb = "was" if len(variantsSeens) == 1 else "were" | ||
raise rez_pip.exceptions.RezPipError( | ||
f"{variants} {verb} requested but PySide6 was not. You must explicitly request PySide6 in addition to {variants}." | ||
) | ||
|
||
|
||
@rez_pip.plugins.hookimpl | ||
def postPipResolve(packages: typing.List[rez_pip.pip.PackageInfo]) -> None: | ||
""" | ||
This hook is implemented out of extra caution. We really don't want PySide6-Addons | ||
or PySide6-Essentials to be installed without PySide6. | ||
In this case, we cover cases where a user requests a package X and that package | ||
depends on PySide6-Addons or PySide6-Essentials. | ||
""" | ||
pyside6Seen = False | ||
variantsSeens = [] | ||
|
||
for package in packages: | ||
name = packaging.utils.canonicalize_name(package.name) | ||
if name == "pyside6": | ||
pyside6Seen = True | ||
elif name in ["pyside6-essentials", "pyside6-addons"]: | ||
variantsSeens.append(package.name) | ||
|
||
if variantsSeens and not pyside6Seen: | ||
variants = " and ".join(variantsSeens) | ||
verb = "is" if len(variantsSeens) == 1 else "are" | ||
raise rez_pip.exceptions.RezPipError( | ||
f"{variants} {verb} part of the resolved packages but PySide6 was not. Dependencies and or you must explicitly request PySide6 in addition to {variants}." | ||
) | ||
|
||
|
||
@rez_pip.plugins.hookimpl | ||
def groupPackages( | ||
packages: typing.List[rez_pip.pip.PackageInfo], | ||
) -> typing.List[rez_pip.pip.PackageGroup]: | ||
data = [] | ||
for index, package in enumerate(packages[:]): | ||
if packaging.utils.canonicalize_name(package.name) in [ | ||
"pyside6", | ||
"pyside6-addons", | ||
"pyside6-essentials", | ||
]: | ||
data.append(package) | ||
packages.remove(package) | ||
return [rez_pip.pip.PackageGroup(data)] |
Oops, something went wrong.