Fixes lazy load server protocols#4984
Open
jasonb5 wants to merge 1 commit into
Open
Conversation
Contributor
|
You can preview documentation at https://esmci.github.io/cime/branch/fix/refactor-servers-lazyload/html/index.html |
jasonb5
force-pushed
the
fix/refactor-servers-lazyload
branch
from
June 18, 2026 20:17
834066b to
3bbc14f
Compare
jasonb5
marked this pull request as ready for review
July 16, 2026 16:53
jgfouca
approved these changes
Jul 17, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors CIME.Servers to lazily detect protocol support on first access (rather than during module import), introduces a public is_protocol_available(protocol) API, updates input-data download logic to use the new API, and adds unit tests to cover the new behavior.
Changes:
- Refactor
CIME/Servers/__init__.pyto lazy-load server classes andhas_*flags via module__getattr__, and addis_protocol_available(). - Update
CIME/case/check_input_data.pyto useis_protocol_available(protocol)instead ofprotocol in vars(CIME.Servers). - Add unit tests in
CIME/tests/test_unit_servers.pyfor lazy loading, protocol availability, and backward-compatible attribute access.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
CIME/Servers/__init__.py |
Adds lazy protocol availability checks and lazy class/flag resolution via __getattr__. |
CIME/case/check_input_data.py |
Switches protocol enablement checks to the new is_protocol_available() API. |
CIME/tests/test_unit_servers.py |
Adds unit tests intended to validate lazy loading and backward-compat behaviors. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Returns: | ||
| True if the protocol is available, False otherwise. | ||
| """ | ||
| protocol = protocol.lower() |
Comment on lines
+15
to
+19
| def test_import_does_not_run_which(self): | ||
| """Importing CIME.Servers should not run shutil.which().""" | ||
| import CIME.Servers | ||
|
|
||
| assert CIME.Servers is not None |
Comment on lines
+21
to
+34
| def test_availability_not_checked_at_import(self): | ||
| """Availability flags should be unchecked after import.""" | ||
| import importlib | ||
| import sys | ||
|
|
||
| # Force reimport | ||
| for mod in list(sys.modules.keys()): | ||
| if "CIME.Servers" in mod: | ||
| del sys.modules[mod] | ||
|
|
||
| import CIME.Servers | ||
|
|
||
| assert CIME.Servers is not None | ||
|
|
Comment on lines
+3
to
+6
| These tests verify: | ||
| 1. Lazy loading behavior (no subprocess at import time) | ||
| 2. Backward compatibility with existing usage patterns | ||
| 3. is_protocol_available() API |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
CIME/Servers/__init__.pyto use lazy loading via__getattr__and@lru_cacheshutil.which()at import time forsvn,wget,globus-url-copyis_protocol_available(protocol)public APIcheck_input_data.pyto use new APIDepends on: #4982
Checklist