Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions icebug/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
"""Compatibility alias for the :mod:`networkit` package.

This allows users to write ``import icebug as ib`` and use the same API that is
available via ``import networkit as nk``.
"""

import importlib
import sys

import networkit as _networkit

# Expose the exact same top-level module object under the "icebug" name.
sys.modules[__name__] = _networkit

# Keep submodule aliasing explicit and static.
_ALIASED_SUBMODULES = [
"graph",
"graphio",
"community",
"centrality",
"generators",
"structures",
"engineering",
"embedding",
"distance",
"components",
"gephi",
"coloring",
"flow",
"sparsification",
"scd",
"clique",
"globals",
"linkprediction",
"correlation",
"matching",
"coarsening",
"reachability",
"simulation",
"stats",
"viz",
"randomization",
"independentset",
"graphtools",
"support",
"plot",
"profiling",
"nxadapter",
]

for _submodule in _ALIASED_SUBMODULES:
try:
_module = importlib.import_module(f"networkit.{_submodule}")
except ImportError:
# Optional dependencies may make some modules unavailable.
continue
sys.modules[f"icebug.{_submodule}"] = _module
21 changes: 21 additions & 0 deletions networkit/test/test_icebug_alias.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env python3
import unittest

import icebug as ib
import networkit as nk


class TestIcebugAlias(unittest.TestCase):

def test_top_level_alias(self):
self.assertIs(ib, nk)

def test_core_api_available(self):
graph = ib.Graph(5)
self.assertEqual(graph.numberOfNodes(), 5)

def test_submodule_alias(self):
import icebug.centrality as ib_cent
import networkit.centrality as nk_cent

self.assertIs(ib_cent, nk_cent)
Loading