diff --git a/icebug/__init__.py b/icebug/__init__.py new file mode 100644 index 000000000..5e7ca4135 --- /dev/null +++ b/icebug/__init__.py @@ -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 diff --git a/networkit/test/test_icebug_alias.py b/networkit/test/test_icebug_alias.py new file mode 100644 index 000000000..47a56d464 --- /dev/null +++ b/networkit/test/test_icebug_alias.py @@ -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)