Skip to content

Commit 1ca4a2f

Browse files
committed
Revert changes to plugin manager
1 parent b8dd358 commit 1ca4a2f

File tree

7 files changed

+120
-71
lines changed

7 files changed

+120
-71
lines changed

mypy-baseline.txt

Lines changed: 72 additions & 56 deletions
Large diffs are not rendered by default.

src/rez/build_process.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def create_build_process(process_type: str,
6060
if process_type not in process_types:
6161
raise BuildProcessError("Unknown build process: %r" % process_type)
6262

63-
cls = plugin_manager.get_plugin_class('build_process', process_type, BuildProcess)
63+
cls = plugin_manager.get_plugin_class('build_process', process_type)
6464

6565
return cls(working_dir, # ignored (deprecated)
6666
build_system,

src/rez/build_system.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,13 @@ def get_valid_build_systems(working_dir: str,
6969

7070
# package explicitly specifies build system
7171
if buildsys_name:
72-
cls = plugin_manager.get_plugin_class('build_system', buildsys_name, BuildSystem)
72+
cls = plugin_manager.get_plugin_class('build_system', buildsys_name)
7373
return [cls]
7474

7575
# detect valid build systems
7676
clss = []
7777
for buildsys_name_ in get_buildsys_types():
78-
cls = plugin_manager.get_plugin_class('build_system', buildsys_name_, BuildSystem)
78+
cls = plugin_manager.get_plugin_class('build_system', buildsys_name_)
7979
if cls.is_valid_root(working_dir, package=package):
8080
clss.append(cls)
8181

@@ -115,7 +115,7 @@ def create_build_system(working_dir: str,
115115
buildsys_type = next(iter(clss)).name()
116116

117117
# create instance of build system
118-
cls_ = plugin_manager.get_plugin_class('build_system', buildsys_type, BuildSystem)
118+
cls_ = plugin_manager.get_plugin_class('build_system', buildsys_type)
119119

120120
return cls_(working_dir,
121121
opts=opts,

src/rez/package_repository.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def create_memory_package_repository(repository_data: dict) -> MemoryPackageRepo
4040
`PackageRepository` object.
4141
"""
4242
from rezplugins.package_repository.memory import MemoryPackageRepository # noqa
43-
cls_ = plugin_manager.get_plugin_class("package_repository", "memory", MemoryPackageRepository)
43+
cls_ = plugin_manager.get_plugin_class("package_repository", "memory")
4444
return cls_.create_repository(repository_data)
4545

4646

@@ -658,7 +658,7 @@ def clear_caches(self) -> None:
658658

659659
def _get_repository(self, path: str, **repo_args: Any) -> PackageRepository:
660660
repo_type, location = path.split('@', 1)
661-
cls = plugin_manager.get_plugin_class('package_repository', repo_type, PackageRepository)
661+
cls = plugin_manager.get_plugin_class('package_repository', repo_type)
662662
repo = cls(location, self.pool, **repo_args)
663663
return repo
664664

src/rez/plugin_managers.py

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,22 @@
1414
from rez.utils.logging_ import print_debug, print_warning
1515
from rez.exceptions import RezPluginError
1616
from zipimport import zipimporter
17-
from typing import overload, Any, TypeVar
17+
from typing import overload, Any, TypeVar, TYPE_CHECKING
1818
import pkgutil
1919
import os.path
2020
import sys
2121
import types
2222

23+
if TYPE_CHECKING:
24+
from typing import Literal # not available in typing module until 3.8
25+
from rez.shells import Shell
26+
from rez.release_vcs import ReleaseVCS
27+
from rez.release_hook import ReleaseHook
28+
from rez.build_process import BuildProcess
29+
from rez.build_system import BuildSystem
30+
from rez.package_repository import PackageRepository
31+
from rez.command import Command
32+
2333
T = TypeVar("T")
2434

2535

@@ -362,18 +372,41 @@ def get_plugins(self, plugin_type: str) -> list[str]:
362372
return list(self._get_plugin_type(plugin_type).plugin_classes.keys())
363373

364374
@overload
365-
def get_plugin_class(self, plugin_type: str, plugin_name: str) -> type:
375+
def get_plugin_class(self, plugin_type: Literal["shell"], plugin_name: str) -> type[Shell]:
376+
pass
377+
378+
@overload
379+
def get_plugin_class(self, plugin_type: Literal["release_vcs"], plugin_name: str) -> type[ReleaseVCS]:
380+
pass
381+
382+
@overload
383+
def get_plugin_class(self, plugin_type: Literal["release_hook"], plugin_name: str) -> type[ReleaseHook]:
384+
pass
385+
386+
@overload
387+
def get_plugin_class(self, plugin_type: Literal["package_repository"], plugin_name: str) -> type[PackageRepository]:
366388
pass
367389

368390
@overload
369-
def get_plugin_class(self, plugin_type: str, plugin_name: str, expected_type: type[T]) -> type[T]:
391+
def get_plugin_class(self, plugin_type: Literal["build_system"], plugin_name: str) -> type[BuildSystem]:
370392
pass
371393

372-
def get_plugin_class(self, plugin_type: str, plugin_name: str, expected_type: type | None = None) -> type:
394+
@overload
395+
def get_plugin_class(self, plugin_type: Literal["package_repository"], plugin_name: str) -> type[PackageRepository]:
396+
pass
397+
398+
@overload
399+
def get_plugin_class(self, plugin_type: Literal["build_process"], plugin_name: str) -> type[BuildProcess]:
400+
pass
401+
402+
@overload
403+
def get_plugin_class(self, plugin_type: Literal["command"], plugin_name: str) -> type[Command]:
404+
pass
405+
406+
def get_plugin_class(self, plugin_type: str, plugin_name: str) -> type:
373407
"""Return the class registered under the given plugin name."""
374408
plugin = self._get_plugin_type(plugin_type)
375-
cls = plugin.get_plugin_class(plugin_name)
376-
return cls
409+
return plugin.get_plugin_class(plugin_name)
377410

378411
def get_plugin_module(self, plugin_type: str, plugin_name: str) -> types.ModuleType:
379412
"""Return the module defining the class registered under the given

src/rez/release_vcs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ def create_release_vcs(path: str, vcs_name: str | None = None) -> ReleaseVCS:
2727
if vcs_name:
2828
if vcs_name not in vcs_types:
2929
raise ReleaseVCSError("Unknown version control system: %r" % vcs_name)
30-
cls = plugin_manager.get_plugin_class('release_vcs', vcs_name, expected_type=ReleaseVCS)
30+
cls = plugin_manager.get_plugin_class('release_vcs', vcs_name)
3131
return cls(path)
3232

3333
classes_by_level = {}
3434
for vcs_name in vcs_types:
35-
cls = plugin_manager.get_plugin_class('release_vcs', vcs_name, expected_type=ReleaseVCS)
35+
cls = plugin_manager.get_plugin_class('release_vcs', vcs_name)
3636
result = cls.find_vcs_root(path)
3737
if not result:
3838
continue

src/rez/shells.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def get_shell_class(shell: str | None = None) -> type[Shell]:
5252
shell = system.shell
5353

5454
from rez.plugin_managers import plugin_manager
55-
return plugin_manager.get_plugin_class("shell", shell, Shell)
55+
return plugin_manager.get_plugin_class("shell", shell)
5656

5757

5858
def create_shell(shell: str | None = None, **kwargs: Any) -> Shell:

0 commit comments

Comments
 (0)