Fix circular import rc setting#365
Merged
cvanelteren merged 11 commits intoUltraplot:mainfrom Oct 8, 2025
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
beckermr
requested changes
Oct 8, 2025
beckermr
reviewed
Oct 8, 2025
Collaborator
Author
|
@beckermr I am pushing a more profound change that is more robust and less frail as the one pushed now. I will update the text above. One moment. |
50b913a to
79b45de
Compare
beckermr
reviewed
Oct 8, 2025
Collaborator
Author
|
Note that the handlers are only intended for settings that are "problematic" like the one with cycle. I think this PR is cleaner now as we separate the dependency between the |
beckermr
reviewed
Oct 8, 2025
Collaborator
Author
|
Fingers crossed that the test pass 🤞 |
beckermr
approved these changes
Oct 8, 2025
Collaborator
Author
|
Will wait for the tests to pass and then merge this. Just added the API docs for this -- in case we forget in the future (likely ;-)). |
Collaborator
Author
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.

Closes #364
This pull request resolves a circular import error that occurred when setting the
cycleparameter from a userrcfile. It also includes a major architectural refactoring of the configuration system to make it more robust, extensible, and easier to maintain.The Problem
The initial issue was caused by a circular dependency:
ultraplot.configneeded to import fromultraplot.colorsto validate and process thecyclesetting.ultraplot.colorsneeded to import thercobject fromultraplot.configfor its own internal configuration.This circular dependency made the application's initialization fragile and order-dependent, leading to the reported
ImportError.The solution: adding handlers to Configurator
Instead of a temporary patch, this PR implements a more fundamental solution by refactoring the configuration system to follow the Dependency Inversion Principle.
The key changes are:
configandcolorsmodules: TheConfiguratorinconfig.pyis now completely agnostic of color-specific logic. It no longer imports fromcolors.py.Configuratornow has a mechanism (register_handler) that allows other modules to register their own functions for handling specific settings.cyclesetting has been moved into a_cycle_handlerfunction withincolors.py. This module is now responsible for registering its handler with theConfigurator.skip_cycleparameter and the complex deferred settings logic.Added tests
This refactoring was accompanied by a significant testing effort to ensure its correctness and prevent regressions:
test_handlers.py, was created to specifically unit-test the new handler registration and execution mechanism.rcfiles (test_config.py) was completely rewritten to be more robust. After a long debugging process, the final version now directly and atomically tests therc.load()method, ensuring the test is isolated from the user's local environment and any module-reloading side effects.PR fixes: