Skip to content

circular import when loading rc with cycle #364

@Yefee

Description

@Yefee

An error is thrown when setting up the circle in the ultraplotrc. The persists from #proplot-dev/proplot#335 (comment).

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[1], line 10
      8 import numpy as np
      9 import xcesm
---> 10 import ultraplot as pplt
     11 import matplotlib.pyplot as plt
     12 import nc_time_axis 

File /glade/work/che43/conda-envs/neu/lib/python3.11/site-packages/ultraplot/__init__.py:34
     32 # Import everything to top level
     33 with _benchmark("config"):
---> 34     from .config import *  # noqa: F401 F403
     35 with _benchmark("proj"):
     36     from .proj import *  # noqa: F401 F403

File /glade/work/che43/conda-envs/neu/lib/python3.11/site-packages/ultraplot/config.py:1825
   1821 rc_ultraplot = rcsetup._rc_ultraplot_default.copy()  # a validated rcParams-style dict
   1823 #: Instance of `Configurator`. This controls both `rc_matplotlib` and `rc_ultraplot`
   1824 #: settings. See the :ref:`configuration guide <ug_config>` for details.
-> 1825 rc = Configurator(skip_cycle=True)
   1827 # Deprecated
   1828 RcConfigurator = warnings._rename_objs(
   1829     "0.8.0",
   1830     RcConfigurator=Configurator,
   1831 )

File /glade/work/che43/conda-envs/neu/lib/python3.11/site-packages/ultraplot/config.py:769, in Configurator.__init__(self, local, user, default, **kwargs)
    763 """
    764 Parameters
    765 ----------
    766 %(rc.params)s
    767 """
    768 self._context = []
--> 769 self._init(local=local, user=user, default=default, **kwargs)

File /glade/work/che43/conda-envs/neu/lib/python3.11/site-packages/ultraplot/config.py:879, in Configurator._init(self, local, user, default, skip_cycle)
    877     user_path = self.user_file()
    878     if os.path.isfile(user_path):
--> 879         self.load(user_path)
    881 # Update from local paths
    882 if local:

File /glade/work/che43/conda-envs/neu/lib/python3.11/site-packages/ultraplot/config.py:1683, in Configurator.load(self, path)
   1681 rcdict = self._load_file(path)
   1682 for key, value in rcdict.items():
-> 1683     self.__setitem__(key, value)

File /glade/work/che43/conda-envs/neu/lib/python3.11/site-packages/ultraplot/config.py:788, in Configurator.__setitem__(self, key, value)
    783 def __setitem__(self, key, value):
    784     """
    785     Modify an `rc_matplotlib` or `rc_ultraplot` setting using dictionary notation
    786     (e.g., ``uplt.rc[name] = value``).
    787     """
--> 788     kw_ultraplot, kw_matplotlib = self._get_item_dicts(key, value)
    789     rc_ultraplot.update(kw_ultraplot)
    790     rc_matplotlib.update(kw_matplotlib)

File /glade/work/che43/conda-envs/neu/lib/python3.11/site-packages/ultraplot/config.py:997, in Configurator._get_item_dicts(self, key, value, skip_cycle)
    994 # Cycler
    995 # NOTE: Have to skip this step during initial ultraplot import
    996 elif contains("cycle") and not skip_cycle:
--> 997     from .colors import _get_cmap_subtype
    999     cmap = _get_cmap_subtype(value, "discrete")
   1000     kw_matplotlib["axes.prop_cycle"] = cycler.cycler("color", cmap.colors)

File /glade/work/che43/conda-envs/neu/lib/python3.11/site-packages/ultraplot/colors.py:32
     29 import numpy as np
     30 import numpy.ma as ma
---> 32 from .config import rc
     33 from .internals import ic  # noqa: F401
     34 from .internals import (
     35     _kwargs_to_args,
     36     _not_none,
   (...)
     40     warnings,
     41 )

ImportError: cannot import name 'rc' from partially initialized module 'ultraplot.config' (most likely due to a circular import) (/glade/work/che43/conda-envs/neu/lib/python3.11/site-packages/ultraplot/config.py)

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions