[BUG] Wonky bug with layouts module
Expected Behavior
import graspologic
works successfully in a jupyter notebook, after setting up from either github or the setup.py file manually (e.g., cloning package).
Actual Behavior
import graspologic
produces the following error from a jupyter notebook:
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
File ~/.virtualenvs/graspy-fix/lib/python3.8/site-packages/pkg_resources/__init__.py:355, in get_provider(moduleOrReq)
354 try:
--> 355 module = sys.modules[moduleOrReq]
356 except KeyError:
KeyError: None
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
Input In [1], in <cell line: 1>()
----> 1 import graspologic
2 print(graspologic.__file__)
File <frozen importlib._bootstrap>:991, in _find_and_load(name, import_)
File <frozen importlib._bootstrap>:975, in _find_and_load_unlocked(name, import_)
File <frozen importlib._bootstrap>:655, in _load_unlocked(spec)
File <frozen importlib._bootstrap>:618, in _load_backward_compatible(spec)
File <frozen zipimport>:259, in load_module(self, fullname)
File ~/.virtualenvs/graspy-fix/lib/python3.8/site-packages/graspologic-1.0.1-py3.8.egg/graspologic/__init__.py:9, in <module>
7 import graspologic.embed
8 import graspologic.inference
----> 9 import graspologic.layouts
10 import graspologic.models
11 import graspologic.nominate
File <frozen importlib._bootstrap>:991, in _find_and_load(name, import_)
File <frozen importlib._bootstrap>:975, in _find_and_load_unlocked(name, import_)
File <frozen importlib._bootstrap>:655, in _load_unlocked(spec)
File <frozen importlib._bootstrap>:618, in _load_backward_compatible(spec)
File <frozen zipimport>:259, in load_module(self, fullname)
File ~/.virtualenvs/graspy-fix/lib/python3.8/site-packages/graspologic-1.0.1-py3.8.egg/graspologic/layouts/__init__.py:6, in <module>
1 # Copyright (c) Microsoft Corporation.
2 # Licensed under the MIT license.
5 from .classes import NodePosition
----> 6 from .colors import categorical_colors, sequential_colors
7 from .render import save_graph, show_graph
9 from .auto import layout_tsne, layout_umap # isort:skip
File <frozen importlib._bootstrap>:991, in _find_and_load(name, import_)
File <frozen importlib._bootstrap>:975, in _find_and_load_unlocked(name, import_)
File <frozen importlib._bootstrap>:655, in _load_unlocked(spec)
File <frozen importlib._bootstrap>:618, in _load_backward_compatible(spec)
File <frozen zipimport>:259, in load_module(self, fullname)
File ~/.virtualenvs/graspy-fix/lib/python3.8/site-packages/graspologic-1.0.1-py3.8.egg/graspologic/layouts/colors.py:36, in <module>
32 dark: Dict[Any, Any] = thematic_json["dark"]
33 return light, dark
---> 36 _CACHED_LIGHT, _CACHED_DARK = _load_thematic_json(None)
39 def _get_colors(light_background: bool, theme_path: Optional[str]) -> Dict[Any, Any]:
40 light = _CACHED_LIGHT
File ~/.virtualenvs/graspy-fix/lib/python3.8/site-packages/graspologic-1.0.1-py3.8.egg/graspologic/layouts/colors.py:26, in _load_thematic_json(path)
24 else:
25 atexit.register(pkg_resources.cleanup_resources)
---> 26 include_path = pkg_resources.resource_filename(__package__, "include")
27 colors_path = os.path.join(include_path, "colors-100.json")
29 with open(colors_path) as thematic_json_io:
File ~/.virtualenvs/graspy-fix/lib/python3.8/site-packages/pkg_resources/__init__.py:1141, in ResourceManager.resource_filename(self, package_or_requirement, resource_name)
1139 def resource_filename(self, package_or_requirement, resource_name):
1140 """Return a true filesystem path for specified resource"""
-> 1141 return get_provider(package_or_requirement).get_resource_filename(
1142 self, resource_name
1143 )
File ~/.virtualenvs/graspy-fix/lib/python3.8/site-packages/pkg_resources/__init__.py:357, in get_provider(moduleOrReq)
355 module = sys.modules[moduleOrReq]
356 except KeyError:
--> 357 __import__(moduleOrReq)
358 module = sys.modules[moduleOrReq]
359 loader = getattr(module, '__loader__', None)
TypeError: __import__() argument 1 must be str, not None
Your Environment
- Python version: 3.8.2
- graspologic version: 1.0.1 (
devbranch)
Additional Details
The package builds/works successfully from a terminal session, so obviously my first thought was that I had mis-configured/not appropriately configured my jupyter kernel for the notebook. However, I verified manually that graspologic.__file__ pointed to the same thing in both places, which it did. Further verified that my jupyter kernel was the right version of python, which it was. Not really sure what to do from there. Not sure whether this is a jupyter issue, OS issue (mac), or a python issue relating to something else.
Oh this is going to be so much fun to track down. Basically we try to look inside the module for the json file that contains the thematic color palette and use it. The current process was supposed to work everywhere - relative paths, or while packaged, etc - but it seems like Jupyter is putting you in an odd state that we didn't expect. What's most vexxing is that this absolutely works for other people in Jupyter, so there's something else adding a new wrinkle that we didn't expect at all.
@daxpryce for reference, there was no 😢 react, so let the 👍 stand in its place :(
@daxpryce https://via.hypothes.is/http://docs.neurodata.io/graph-stats-book/representations/ch4/properties-of-networks.html here it is for you again, this time in our graph stats book...
@daxpryce perhaps a "healthy medium" as a last resort fail-safe would be a try-catch that downloads it if it's not there if the computer is connected to interwebz..?
yah; this doesn't work for me locally, nor on a remote jupyter instance for the github workflow we use for the book... so something is amuck. no clue how to rectify.
Ok so I just brute forced it temporarily by literally wgetting and chmodding with problematically bad permissions to fix the issue for the specific deployment workflow I needed to work as seen https://github.com/neurodata/graph-stats-book/blob/accde1f0dcad134b2d7843fa637923db77d4068a/.github/workflows/deploy.yml#L29, so no longer critical to me, but definitely still seems to be a problem. The workflow we were building off was using ubuntu-latest on a github workflow, and we were building using pip install git+<appropriate path to graspologic>@dev directly from the dev branch.