Add a registry for SCMClient classes and move defaults into code.

Review Request #12525 — Created Aug. 10, 2022 and submitted

Information

RBTools
release-4.x

Reviewers

This introduces rbtools.clients.base.registry.SCMClientRegistry, which
keeps track of all the available BaseSCMClient subclasses. This
enables fetching a client by ID, iterating through all clients, and
registering new ones.

The registry is accessible via a rbtools.clients.scmclient_registry
instance.

SCMClient classes should now set a scmclient_id attribute. This will
be mandated in RBTools 5. For now, any loaded via entry point that lack
an ID will have one assigned, with a warning.

To improve performance and to avoid packaging-related complications,
the default list of clients are now fully inline, rather than
introspected via entrypoints. This matches what we've been doing within
Review Board. The registry still scans entrypoints for third-party
packages, but only when needed (if listing all clients or if a lookup
fails to find it in the built-in list).

Entry points use the modern importlib.metadata.entry_points API. This
has only solidified as of Python 3.10 (3.8/3.9 had it but it's not
compatible), so we pull in the official backport for those versions.

Unit tests pass.

Posted this change for review.

Ran mypy and pyright on the new registry code, with no errors
or warnings.

Summary ID
Add a registry for SCMClient classes and move defaults into code.
This introduces `rbtools.clients.base.registry.SCMClientRegistry`, which keeps track of all the available `BaseSCMClient` subclasses. This enables fetching a client by ID, iterating through all clients, and registering new ones. The registry is accessible via a `rbtools.clients.scmclient_registry` instance. `SCMClient` classes should now set a `scmclient_id` attribute. This will be mandated in RBTools 5. For now, any loaded via entry point that lack an ID will have one assigned, with a warning. To improve performance and to avoid packaging-related complications, the default list of clients are now fully inline, rather than introspected via entrypoints. This matches what we've been doing within Review Board. The registry still scans entrypoints for third-party packages, but only when needed (if listing all clients or if a lookup fails to find it in the built-in list).
483cf2eeac0ed8377ff9c00505a31ec1a8b33f7c
Description From Last Updated

local variable 'e' is assigned to but never used Column: 9 Error code: F841

reviewbotreviewbot

'typing.Optional' imported but unused Column: 1 Error code: F401

reviewbotreviewbot

undefined name 'RemovedInRBTools50Warning' Column: 9 Error code: F821

reviewbotreviewbot

local variable 'cm' is assigned to but never used Column: 75 Error code: F841

reviewbotreviewbot

local variable 'cm' is assigned to but never used Column: 75 Error code: F841

reviewbotreviewbot
Checks run (1 failed, 1 succeeded)
flake8 failed.
JSHint passed.

flake8

chipx86
david
  1. Ship It!
  2. 
      
chipx86
david
  1. Ship It!
  2. 
      
chipx86
Review request changed
Status:
Completed
Change Summary:
Pushed to release-4.x (d4d2e4f)