-
Notifications
You must be signed in to change notification settings - Fork 15
Fix circular import rc setting #365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix circular import rc setting #365
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
@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
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 |
Fingers crossed that the test pass 🤞 |
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 ;-)). |
Closes #364
This pull request resolves a circular import error that occurred when setting the
cycle
parameter from a userrc
file. 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.config
needed to import fromultraplot.colors
to validate and process thecycle
setting.ultraplot.colors
needed to import therc
object fromultraplot.config
for 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:
config
andcolors
modules: TheConfigurator
inconfig.py
is now completely agnostic of color-specific logic. It no longer imports fromcolors.py
.Configurator
now has a mechanism (register_handler
) that allows other modules to register their own functions for handling specific settings.cycle
setting has been moved into a_cycle_handler
function withincolors.py
. This module is now responsible for registering its handler with theConfigurator
.skip_cycle
parameter 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.rc
files (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: