Skip to content

refactor(python): move TextServiceManager into Server and load from directory - #963

Merged
PCMan merged 1 commit into
masterfrom
refactor/server-text-service-manager
Oct 18, 2026
Merged

PCMan merged 1 commit into
masterfrom
refactor/server-text-service-manager

Conversation

@PCMan

@PCMan PCMan commented Oct 18, 2026 •

Copy link
Copy Markdown
Member

Summary of Changes

  • Caller-provided directory loading: Added TextServiceManager.load(input_methods_dir: str) so callers provide the directory to scan instead of hardcoding input_methods. Follows EAFP and allows OSError to propagate to callers.
  • Decoupled initialization and loading: TextServiceManager.__init__ initializes an empty instance (self.services = {}) without auto-loading.
  • Dependency Injection in Server:
    • Server.__init__(self, input_methods_dir: str = None) now accepts an optional injected input_methods_dir instead of hardcoding it.
    • main() resolves the default input_methods directory and injects it into Server(input_methods_dir).
    • Added Server.createService to encapsulate service manager operations and updated Client.init to delegate to self.server.createService.
    • Removed module-level global textServiceMgr = TextServiceManager() and unused threading import from serviceManager.py.
  • API Documentation: Added comprehensive docstrings to TextServiceInfo and TextServiceManager.
  • Unit Tests: Added unit tests in tests/test_service_manager.py covering manager initialization, directory loading, raising OSError on invalid directory, service creation, and isolated server delegation.

Rationale

Instantiating TextServiceManager at the module level ran filesystem enumeration during import and exposed global mutable state. Decoupling manager instantiation from directory loading and injecting input_methods_dir into Server ensures components remain valid even if loading fails. This makes Server and TextServiceManager modular, decoupled from fixed filesystem paths, and straightforward to test in isolation.

Generated with assistance from Antigravity (Gemini 3.8 Flash).

PCMan added a commit that referenced this pull request Oct 18, 2026
…irectory (#963)

- Remove module-level textServiceMgr global from serviceManager.py.
- Make TextServiceManager.__init__ initialize an empty manager without auto-loading.
- Add TextServiceManager.load(inputMethodsDir) so callers provide the directory to load.
- Add class factory TextServiceManager.fromDir(inputMethodsDir).
- Retain enumerateServices(inputMethodsDir=None) for backward compatibility.
- Instantiate TextServiceManager in Server.__init__ and call load(input_methods_dir) in a try/except block.
- Add createService to Server and update Client.init to delegate to self.server.createService.
- Add docstrings to TextServiceInfo and TextServiceManager.
- Add unit tests in tests/test_service_manager.py.

WHY:
Instantiating TextServiceManager at module import time ran filesystem enumeration during import and exposed global mutable state. Decoupling manager instantiation from directory loading ensures the manager remains valid even if loading fails. Allowing callers to pass directories enables loading services from arbitrary locations and makes the code modular, reusable, and easy to test.

Generated with assistance from Antigravity (Gemini 3.8 Flash).
@PCMan
PCMan force-pushed the refactor/server-text-service-manager branch from 37d75da to 6a3ad90 Compare October 18, 2026 17:22
@PCMan PCMan changed the title refactor(python): move TextServiceManager instantiation into Server refactor(python): move TextServiceManager into Server and load from directory Oct 18, 2026
PCMan added a commit that referenced this pull request Oct 18, 2026
…irectory (#963)

- Remove module-level textServiceMgr global from serviceManager.py.
- Make TextServiceManager.__init__ initialize an empty manager without auto-loading.
- Add TextServiceManager.load(inputMethodsDir) so callers provide the directory to load.
- Retain enumerateServices(inputMethodsDir=None) for backward compatibility.
- Instantiate TextServiceManager in Server.__init__ and call load(input_methods_dir) in a try/except block.
- Add createService to Server and update Client.init to delegate to self.server.createService.
- Add docstrings to TextServiceInfo and TextServiceManager.
- Add unit tests in tests/test_service_manager.py.

WHY:
Instantiating TextServiceManager at module import time ran filesystem enumeration during import and exposed global mutable state. Decoupling manager instantiation from directory loading ensures the manager remains valid even if loading fails. Allowing callers to pass directories enables loading services from arbitrary locations and makes the code modular, reusable, and easy to test.

Generated with assistance from Antigravity (Gemini 3.8 Flash).
@PCMan
PCMan force-pushed the refactor/server-text-service-manager branch from 6a3ad90 to 1e87bca Compare October 18, 2026 17:28
PCMan added a commit that referenced this pull request Oct 18, 2026
…irectory (#963)

- Remove module-level textServiceMgr global from serviceManager.py.
- Make TextServiceManager.__init__ initialize an empty manager without auto-loading.
- Add TextServiceManager.load(inputMethodsDir) so callers provide the directory to load.
- Instantiate TextServiceManager in Server.__init__ and call load(input_methods_dir) in a try/except block.
- Add createService to Server and update Client.init to delegate to self.server.createService.
- Add docstrings to TextServiceInfo and TextServiceManager.
- Add unit tests in tests/test_service_manager.py.

WHY:
Instantiating TextServiceManager at module import time ran filesystem enumeration during import and exposed global mutable state. Decoupling manager instantiation from directory loading ensures the manager remains valid even if loading fails. Allowing callers to pass directories enables loading services from arbitrary locations and makes the code modular, reusable, and easy to test.

Generated with assistance from Antigravity (Gemini 3.8 Flash).
@PCMan
PCMan force-pushed the refactor/server-text-service-manager branch from 1e87bca to 738f16e Compare October 18, 2026 17:31
PCMan added a commit that referenced this pull request Oct 18, 2026
…irectory (#963)

- Remove module-level textServiceMgr global from serviceManager.py.
- Make TextServiceManager.__init__ initialize an empty manager without auto-loading.
- Add TextServiceManager.load(input_methods_dir) so callers provide the directory to load.
- Instantiate TextServiceManager in Server.__init__ and call load(input_methods_dir) in a try/except block.
- Add createService to Server and update Client.init to delegate to self.server.createService.
- Add docstrings to TextServiceInfo and TextServiceManager.
- Add unit tests in tests/test_service_manager.py.

WHY:
Instantiating TextServiceManager at module import time ran filesystem enumeration during import and exposed global mutable state. Decoupling manager instantiation from directory loading ensures the manager remains valid even if loading fails. Allowing callers to pass directories enables loading services from arbitrary locations and makes the code modular, reusable, and easy to test.

Generated with assistance from Antigravity (Gemini 3.8 Flash).
@PCMan
PCMan force-pushed the refactor/server-text-service-manager branch from 738f16e to b302d72 Compare October 18, 2026 17:32
PCMan added a commit that referenced this pull request Oct 18, 2026
…irectory (#963)

- Remove module-level textServiceMgr global from serviceManager.py.
- Make TextServiceManager.__init__ initialize an empty manager without auto-loading.
- Add TextServiceManager.load(input_methods_dir) so callers provide the directory to load.
- Instantiate TextServiceManager in Server.__init__ and call load(input_methods_dir) in a try/except block.
- Add createService to Server and update Client.init to delegate to self.server.createService.
- Add docstrings to TextServiceInfo and TextServiceManager.
- Add unit tests in tests/test_service_manager.py.

WHY:
Instantiating TextServiceManager at module import time ran filesystem enumeration during import and exposed global mutable state. Decoupling manager instantiation from directory loading ensures the manager remains valid even if loading fails. Allowing callers to pass directories enables loading services from arbitrary locations and makes the code modular, reusable, and easy to test.

Generated with assistance from Antigravity (Gemini 3.8 Flash).
@PCMan
PCMan force-pushed the refactor/server-text-service-manager branch from b302d72 to 54c2063 Compare October 18, 2026 17:33
PCMan added a commit that referenced this pull request Oct 18, 2026
…irectory (#963)

- Remove module-level textServiceMgr global from serviceManager.py.
- Make TextServiceManager.__init__ initialize an empty manager without auto-loading.
- Add TextServiceManager.load(input_methods_dir) so callers provide the directory to load.
- Instantiate TextServiceManager in Server.__init__ and call load(input_methods_dir) in a try/except block.
- Add createService to Server and update Client.init to delegate to self.server.createService.
- Add docstrings to TextServiceInfo and TextServiceManager.
- Add unit tests in tests/test_service_manager.py.

WHY:
Instantiating TextServiceManager at module import time ran filesystem enumeration during import and exposed global mutable state. Decoupling manager instantiation from directory loading ensures the manager remains valid even if loading fails. Allowing callers to pass directories enables loading services from arbitrary locations and makes the code modular, reusable, and easy to test.

Generated with assistance from Antigravity (Gemini 3.8 Flash).
@PCMan
PCMan force-pushed the refactor/server-text-service-manager branch from 54c2063 to af5e3a7 Compare October 18, 2026 17:35
PCMan added a commit that referenced this pull request Oct 18, 2026
…irectory (#963)

- Remove module-level textServiceMgr global from serviceManager.py.
- Make TextServiceManager.__init__ initialize an empty manager without auto-loading.
- Add TextServiceManager.load(input_methods_dir) so callers provide the directory to load.
- Instantiate TextServiceManager in Server.__init__ and call load(input_methods_dir) in a try/except block.
- Add createService to Server and update Client.init to delegate to self.server.createService.
- Add docstrings to TextServiceInfo and TextServiceManager.
- Add unit tests in tests/test_service_manager.py.

WHY:
Instantiating TextServiceManager at module import time ran filesystem enumeration during import and exposed global mutable state. Decoupling manager instantiation from directory loading ensures the manager remains valid even if loading fails. Allowing callers to pass directories enables loading services from arbitrary locations and makes the code modular, reusable, and easy to test.

Generated with assistance from Antigravity (Gemini 3.8 Flash).
@PCMan
PCMan force-pushed the refactor/server-text-service-manager branch from af5e3a7 to b98b423 Compare October 18, 2026 17:37
…irectory (#963)

- Remove module-level textServiceMgr global from serviceManager.py.
- Make TextServiceManager.__init__ initialize an empty manager without auto-loading.
- Add TextServiceManager.load(input_methods_dir) so callers provide the directory to load.
- Instantiate TextServiceManager in Server.__init__ and accept injected input_methods_dir.
- Inject input_methods_dir from main() into Server(input_methods_dir).
- Add createService to Server and update Client.init to delegate to self.server.createService.
- Add docstrings to TextServiceInfo and TextServiceManager.
- Add unit tests in tests/test_service_manager.py.

WHY:
Instantiating TextServiceManager at module import time ran filesystem enumeration during import and exposed global mutable state. Decoupling manager instantiation from directory loading ensures the manager remains valid even if loading fails. Injecting input_methods_dir into Server and TextServiceManager enables loading services from arbitrary locations, simplifies dependency management, and improves test isolation.

Generated with assistance from Antigravity (Gemini 3.8 Flash).
@PCMan
PCMan force-pushed the refactor/server-text-service-manager branch from b98b423 to 277dac5 Compare October 18, 2026 17:39
@PCMan PCMan self-assigned this Oct 18, 2026
@PCMan
PCMan merged commit 32a23fc into master Oct 18, 2026
4 of 6 checks passed
@PCMan
PCMan deleted the refactor/server-text-service-manager branch October 18, 2026 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant