Skip to content

Conversation

@cvanelteren
Copy link
Collaborator

@cvanelteren cvanelteren commented Oct 27, 2025

This PR moves the global variables of rc_ultraplot and rc_matplotlib internal to the Configurator class.

Why?

Currently we have global variables that are being passed around which causes us to track rc_matplotlib, rc_ultraplotand rc separately. If we wanna move to a thread safe rc setter our Configurator class needs to encapsulate the rc parameters properly. It eases our understanding of the how UltraPlot is configured without having to see where the rc are update. The general use of rc is focused on the Configurator anyway so making them apart of this setting is a logical encapsulation.

It also moves the logic from __init__.py to a new sync class method.

Todos

  • Refactor rc dicts inside Configurator
  • Remove old deprication warnings
  • adjust document if necessary
  • add unittests

@cvanelteren cvanelteren marked this pull request as draft October 27, 2025 16:41
@cvanelteren cvanelteren requested a review from Copilot October 27, 2025 16:51

This comment was marked as resolved.

cvanelteren and others added 2 commits October 27, 2025 17:52
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@cvanelteren cvanelteren requested a review from Copilot October 27, 2025 16:54

This comment was marked as resolved.

@codecov
Copy link

codecov bot commented Oct 27, 2025

Codecov Report

❌ Patch coverage is 88.33333% with 21 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
ultraplot/config.py 79.41% 11 Missing and 10 partials ⚠️

📢 Thoughts on this report? Let us know!

@cvanelteren
Copy link
Collaborator Author

Note: I may just remove the inputs as the user should not be concerned with the defaults rc`s

@cvanelteren cvanelteren marked this pull request as ready for review October 27, 2025 18:17
@cvanelteren cvanelteren requested a review from beckermr October 27, 2025 18:17
@cvanelteren
Copy link
Collaborator Author

Still reaching the time-out ...

Copy link
Collaborator

@beckermr beckermr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way we can do this without breaking the API?

return kw_ultraplot


def config_inline_backend(fmt=None):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this function removed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is moved as a class function now. It was moved there as it was referencing as global var (rc_ultraplot). The encapsulation is more appropriate with this recent change.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is here now: https://github.com/Ultraplot/UltraPlot/pull/384/files#diff-849c439d454bf26e1102dce232b08a417344e1d97a4add022d4088cd00b743caR1060

Note this PR looks more heavy than it is. I moved _int and __init__ to the top of the class to make it read easier. The only major change is moving rc_ultraplot and rc_matplotlib as class variables and adjusting the logic elsewhere in the code (mainly a couple of references in figure.py)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To add to this. I looked into to how this function is called, and it also happens inside Configurator. I first thought the function was called by IPython directly -- but it is not.

@cvanelteren
Copy link
Collaborator Author

Is there a way we can do this without breaking the API?

It doesn't change the api that much. Users are guided to use rc (the Configurator class) anyway. That remains unchanged here. The only difference here is that we don't have to manage the rc params separately. Before we had 3 objects (rc,rc_ultraplot and rc_matplotlib). The rc objects would ensure that we are retrieving or setting the correct matplotlib settings. I think it is cleaner to just use rc and make the respective rc params for ultraplot and matplotlib available from this configuration rather bookkeeping them separately. In this way, we could also ensure that we can do thread safety by providing blocks and proper context protection in the class.

@beckermr
Copy link
Collaborator

An API change is an API change even if it is small. We'll need to bump to 2.0 after this IMHO.

@cvanelteren
Copy link
Collaborator Author

I see a version increase merely as a version increase, but perhaps we should add an api warning for few Y releases (x.Y) before we make the change.

@cvanelteren cvanelteren added this to the v2.0 milestone Oct 29, 2025
Comment on lines +1818 to +1830
def sync(self):
"""
Sync settings between ultraplot and matplotlib rc dictionaries.
"""
for _src in (self.rc_ultraplot, self.rc_matplotlib):
for _key in _src: # loop through unsynced properties
if "color" not in _key:
continue
try:
_src[_key] = _src[_key]
except ValueError as err:
warnings._warn_ultraplot(f"Invalid user rc file setting: {err}")
_src[_key] = "black" # fill value
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't follow how this code works to be honest. Also the method should probably be called sync_colors since it only deals with colors?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code was originally part of init. Merely wrapped it. I think it triggers the validators.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't follow how this code works to be honest. Also the method should probably be called sync_colors since it only deals with colors?

actually taht is a good point -- will change it for clarity

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see how the settings from one rc object end up in the other. It must happen on the backend as you say.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least for the rc_ultraplot it will run a validator on setting a key (see rcsetup.py); matplotlib prolly has a similar setting.

Initially I was also scratching my head at this section in the code. Will replace it as we progress to something a bit cleaner.

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.

2 participants