Skip to content

Commit 5129f15

Browse files
committed
save state
1 parent 427367b commit 5129f15

File tree

8 files changed

+163
-170
lines changed

8 files changed

+163
-170
lines changed

.github/workflows/build-ultraplot.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
4444
- name: Test Ultraplot
4545
run: |
46-
pytest -n auto --cov=ultraplot --cov-branch --cov-report term-missing --cov-report=xml ultraplot
46+
pytest --cov=ultraplot --cov-branch --cov-report term-missing --cov-report=xml ultraplot
4747
4848
- name: Upload coverage reports to Codecov
4949
uses: codecov/codecov-action@v5
@@ -76,14 +76,14 @@ jobs:
7676
git fetch origin ${{ github.event.pull_request.base.sha }}
7777
git checkout ${{ github.event.pull_request.base.sha }}
7878
python -c "import ultraplot as plt; plt.config.Configurator()._save_yaml('ultraplot.yml')"
79-
pytest -n auto -W ignore --mpl-generate-path=baseline --mpl-default-style="./ultraplot.yml"
79+
pytest -W ignore --mpl-generate-path=baseline --mpl-default-style="./ultraplot.yml"
8080
git checkout ${{ github.sha }} # Return to PR branch
8181
8282
- name: Image Comparison Ultraplot
8383
run: |
8484
mkdir -p results
8585
python -c "import ultraplot as plt; plt.config.Configurator()._save_yaml('ultraplot.yml')"
86-
pytest -n auto -W ignore --mpl --mpl-baseline-path=baseline --mpl-generate-summary=html --mpl-results-path=./results/ --mpl-default-style="./ultraplot.yml" --store-failed-only ultraplot/tests
86+
pytest -W ignore --mpl --mpl-baseline-path=baseline --mpl-generate-summary=html --mpl-results-path=./results/ --mpl-default-style="./ultraplot.yml" --store-failed-only ultraplot/tests
8787
8888
# Return the html output of the comparison even if failed
8989
- name: Upload comparison failures

environment.yml

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,31 @@ name: ultraplot-dev
22
channels:
33
- conda-forge
44
dependencies:
5-
- basemap >=1.4.1
6-
- cartopy
7-
- jupyter
8-
- jupytext
9-
- matplotlib>=3.9
10-
- nbsphinx
11-
- networkx
5+
- python>=3.10,<3.14
126
- numpy
7+
- matplotlib>=3.9
8+
- cartopy
9+
- xarray
10+
- seaborn
1311
- pandas
14-
- pint
15-
- pip
16-
- pre-commit
17-
- pyarrow
1812
- pytest
19-
- pytest-cov
2013
- pytest-mpl
21-
- pytest-xdist
22-
- python>=3.10,<3.14
23-
- seaborn
14+
- pytest-cov
15+
- jupyter
16+
- pip
17+
- pint
2418
- sphinx
19+
- nbsphinx
20+
- jupytext
21+
- sphinx-copybutton
2522
- sphinx-autoapi
2623
- sphinx-automodapi
27-
- sphinx-copybutton
28-
- sphinx-design
2924
- sphinx-rtd-theme
3025
- typing-extensions
31-
- xarray
26+
- basemap >=1.4.1
27+
- pre-commit
28+
- sphinx-design
29+
- networkx
30+
- pyarrow
3231
- pip:
3332
- git+https://github.com/ultraplot/UltraTheme.git

ultraplot/config.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,19 @@ def __delitem__(self, key): # noqa: U100
841841
def __delattr__(self, attr): # noqa: U100
842842
raise RuntimeError("rc settings cannot be deleted.")
843843

844+
<<<<<<< HEAD
845+
=======
846+
@docstring._snippet_manager
847+
def __init__(self, local=True, user=True, default=True, **kwargs):
848+
"""
849+
Parameters
850+
----------
851+
%(rc.params)s
852+
"""
853+
self._context = []
854+
self._init(local=local, user=user, default=default, **kwargs)
855+
856+
>>>>>>> main
844857
def __getitem__(self, key):
845858
"""
846859
Return an `rc_matplotlib` or `rc_ultraplot` setting using dictionary notation
@@ -859,8 +872,13 @@ def __setitem__(self, key, value):
859872
(e.g., ``uplt.rc[name] = value``).
860873
"""
861874
kw_ultraplot, kw_matplotlib = self._get_item_dicts(key, value)
875+
<<<<<<< HEAD
862876
self.rc_ultraplot.update(kw_ultraplot)
863877
self.rc_matplotlib.update(kw_matplotlib)
878+
=======
879+
rc_ultraplot.update(kw_ultraplot)
880+
rc_matplotlib.update(kw_matplotlib)
881+
>>>>>>> main
864882

865883
def __getattr__(self, attr):
866884
"""
@@ -902,7 +920,11 @@ def __enter__(self):
902920
raise e
903921

904922
for rc_dict, kw_new in zip(
923+
<<<<<<< HEAD
905924
(self.rc_ultraplot, self.rc_matplotlib),
925+
=======
926+
(rc_ultraplot, rc_matplotlib),
927+
>>>>>>> main
906928
(kw_ultraplot, kw_matplotlib),
907929
):
908930
for key, value in kw_new.items():
@@ -920,11 +942,55 @@ def __exit__(self, *args): # noqa: U100
920942
context = self._context[-1]
921943
for key, value in context.rc_old.items():
922944
kw_ultraplot, kw_matplotlib = self._get_item_dicts(key, value)
945+
<<<<<<< HEAD
923946
self.rc_ultraplot.update(kw_ultraplot)
924947
self.rc_matplotlib.update(kw_matplotlib)
925948
del self._context[-1]
926949

927950
def _validate_key(self, key, value=None):
951+
=======
952+
rc_ultraplot.update(kw_ultraplot)
953+
rc_matplotlib.update(kw_matplotlib)
954+
del self._context[-1]
955+
956+
def _init(self, *, local, user, default, skip_cycle=False):
957+
"""
958+
Initialize the configurator.
959+
"""
960+
# Always remove context objects
961+
self._context.clear()
962+
963+
# Update from default settings
964+
# NOTE: see _remove_blacklisted_style_params bugfix
965+
if default:
966+
rc_matplotlib.update(_get_style_dict("original", filter=False))
967+
rc_matplotlib.update(rcsetup._rc_matplotlib_default)
968+
rc_ultraplot.update(rcsetup._rc_ultraplot_default)
969+
for key, value in rc_ultraplot.items():
970+
kw_ultraplot, kw_matplotlib = self._get_item_dicts(
971+
key, value, skip_cycle=skip_cycle
972+
)
973+
rc_matplotlib.update(kw_matplotlib)
974+
rc_ultraplot.update(kw_ultraplot)
975+
976+
# Update from user home
977+
user_path = None
978+
if user:
979+
user_path = self.user_file()
980+
if os.path.isfile(user_path):
981+
self.load(user_path)
982+
983+
# Update from local paths
984+
if local:
985+
local_paths = self.local_files()
986+
for path in local_paths:
987+
if path == user_path: # local files always have precedence
988+
continue
989+
self.load(path)
990+
991+
@staticmethod
992+
def _validate_key(key, value=None):
993+
>>>>>>> main
928994
"""
929995
Validate setting names and handle `rc_ultraplot` deprecations.
930996
"""
@@ -971,9 +1037,15 @@ def _get_item_context(self, key, mode=None):
9711037
mode = self._context_mode
9721038
cache = tuple(context.rc_new for context in self._context)
9731039
if mode == 0:
1040+
<<<<<<< HEAD
9741041
rcdicts = (*cache, self.rc_ultraplot, self.rc_matplotlib)
9751042
elif mode == 1:
9761043
rcdicts = (*cache, self.rc_ultraplot) # added settings only!
1044+
=======
1045+
rcdicts = (*cache, rc_ultraplot, rc_matplotlib)
1046+
elif mode == 1:
1047+
rcdicts = (*cache, rc_ultraplot) # added settings only!
1048+
>>>>>>> main
9771049
elif mode == 2:
9781050
rcdicts = (*cache,)
9791051
else:

ultraplot/internals/context.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
"""
33
Utilities for manging context.
44
"""
5-
import threading
65
from . import ic # noqa: F401
76

87

@@ -26,10 +25,6 @@ class _state_context(object):
2625
Temporarily modify attribute(s) for an arbitrary object.
2726
"""
2827

29-
_lock = (
30-
threading.RLock()
31-
) # class-wide reentrant lock (or use instance-wide if needed)
32-
3328
def __init__(self, obj, **kwargs):
3429
self._obj = obj
3530
self._attrs_new = kwargs
@@ -38,14 +33,12 @@ def __init__(self, obj, **kwargs):
3833
}
3934

4035
def __enter__(self):
41-
self._lock.acquire()
4236
for key, value in self._attrs_new.items():
4337
setattr(self._obj, key, value)
4438

45-
def __exit__(self, *args):
39+
def __exit__(self, *args): # noqa: U100
4640
for key in self._attrs_new.keys():
4741
if key in self._attrs_prev:
4842
setattr(self._obj, key, self._attrs_prev[key])
4943
else:
5044
delattr(self._obj, key)
51-
self._lock.release()

ultraplot/internals/rcsetup.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ def __init__(self, source, validate):
541541
def _validate(self):
542542
if not hasattr(self._thread_props, "_validate"):
543543
self._thread_props._validate = _rc_ultraplot_validate
544-
return self._thread_props._validate
544+
return self._thread_props._validate.copy()
545545

546546
@_validate.setter
547547
def _validate(self, value):
@@ -607,9 +607,8 @@ def copy(self):
607607
if validate is None:
608608
# fallback: guess it from another thread (e.g., first one that set it)
609609
validate = dict()
610-
611610
source = dict(self)
612-
return _RcParams(source, validate)
611+
return _RcParams(source.copy(), validate.copy())
613612

614613

615614
# Borrow validators from matplotlib and construct some new ones

0 commit comments

Comments
 (0)