Skip to content

bug: circular import when loading rc with cycle #335

Open

Description

@syrte

Description

There seems a bug when importing proplot with a "cycle" set in rc file.

Steps to reproduce

I set my .proplotrc as follows

font.size:      10.0
label.size:     med-large
axes.labelsize: med-large
cycle:          tab10

Then I import proplot and get this

import proplot as pplt
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
/tmp/ipykernel_51366/3627428277.py in <module>
----> 1 import proplot as pplt

~/local/conda/envs/nemo/lib/python3.8/site-packages/proplot/__init__.py in <module>
     28 # Import everything to top level
     29 with _benchmark('config'):
---> 30     from .config import *  # noqa: F401 F403
     31 with _benchmark('proj'):
     32     from .proj import *  # noqa: F401 F403

~/local/conda/envs/nemo/lib/python3.8/site-packages/proplot/config.py in <module>
   1765 #: Instance of `Configurator`. This controls both `rc_matplotlib` and `rc_proplot`
   1766 #: settings. See the :ref:`configuration guide <ug_config>` for details.
-> 1767 rc = Configurator(skip_cycle=True)
   1768 
   1769 # Deprecated

~/local/conda/envs/nemo/lib/python3.8/site-packages/proplot/config.py in __init__(self, local, user, default, **kwargs)
    735         """
    736         self._context = []
--> 737         self._init(local=local, user=user, default=default, **kwargs)
    738 
    739     def __getitem__(self, key):

~/local/conda/envs/nemo/lib/python3.8/site-packages/proplot/config.py in _init(self, local, user, default, skip_cycle)
    840             user_path = self.user_file()
    841             if os.path.isfile(user_path):
--> 842                 self.load(user_path)
    843 
    844         # Update from local paths

~/local/conda/envs/nemo/lib/python3.8/site-packages/proplot/config.py in load(self, path)
   1633         rcdict = self._load_file(path)
   1634         for key, value in rcdict.items():
-> 1635             self.__setitem__(key, value)
   1636 
   1637     @staticmethod

~/local/conda/envs/nemo/lib/python3.8/site-packages/proplot/config.py in __setitem__(self, key, value)
    754         (e.g., ``pplt.rc[name] = value``).
    755         """
--> 756         kw_proplot, kw_matplotlib = self._get_item_dicts(key, value)
    757         rc_proplot.update(kw_proplot)
    758         rc_matplotlib.update(kw_matplotlib)

~/local/conda/envs/nemo/lib/python3.8/site-packages/proplot/config.py in _get_item_dicts(self, key, value, skip_cycle)
    956         # NOTE: Have to skip this step during initial proplot import
    957         elif contains('cycle') and not skip_cycle:
--> 958             from .colors import _get_cmap_subtype
    959             cmap = _get_cmap_subtype(value, 'discrete')
    960             kw_matplotlib['axes.prop_cycle'] = cycler.cycler('color', cmap.colors)

~/local/conda/envs/nemo/lib/python3.8/site-packages/proplot/colors.py in <module>
     29 import numpy.ma as ma
     30 
---> 31 from .config import rc
     32 from .internals import ic  # noqa: F401
     33 from .internals import (

ImportError: cannot import name 'rc' from partially initialized module 'proplot.config' (most likely due to a circular import) (/sci/home/lizz/local/conda/envs/nemo/lib/python3.8/site-packages/proplot/config.py)

If I delete cycle from rc file, then everything goes well.

Proplot version

Paste the results of import matplotlib; print(matplotlib.__version__); import proplot; print(proplot.version)here.

3.4.3
0.9.5.post259

Activity

  1. changed the title [-]circular import when loading rc[/-] [+]bug: circular import when loading rc[/+] on Feb 8, 2022
  2. changed the title [-]bug: circular import when loading rc[/-] [+]bug: circular import when loading rc with cycle[/+] on Feb 8, 2022
  3. lukelbd commented on Feb 25, 2022

    @lukelbd
    Collaborator

    Definitely not ideal... maybe relates to #333. A little busy lately but will plug away on these issues in march.

  4. lukelbd commented on Mar 4, 2022

    @lukelbd
    Collaborator

    Don't think this was supposed to be closed.

  5. reopened this on Mar 4, 2022
  6. Yefee commented on May 5, 2024

    @Yefee

    The problem still persists in v.0.9.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions