Skip to content

Commit

Permalink
nx-cugraph: check networkx version (#4571)
Browse files Browse the repository at this point in the history
This is to address the feedback from @bdice in #4531 (comment), which I was unable to do in that PR.

I know checking version strings is playing it fast-and-loose, but I believe we are abundantly safe to do so here, as networkx releases have been, and are expected to be, slow and predictable. Also, we do not have `packaging` as a runtime dependency (it _is_ a test dependency for finer control).

So, even better than using `packaging.version.parse`, this PR performs a sanity check on the networkx version. I put it in both `nx_cugraph.__init__` and `_nx_cugraph.__init__` to give us obvious breadcrumbs to discover and follow.

Authors:
  - Erik Welch (https://github.com/eriknw)

Approvers:
  - Rick Ratzel (https://github.com/rlratzel)

URL: #4571
  • Loading branch information
eriknw authored Jul 31, 2024
1 parent 7b81173 commit d77a2d6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
21 changes: 21 additions & 0 deletions python/nx-cugraph/_nx_cugraph/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,27 @@ def get_info():
return d


def _check_networkx_version():
import warnings

import networkx as nx

version_major, version_minor = nx.__version__.split(".")[:2]
if version_major != "3":
warnings.warn(
f"nx-cugraph version {__version__} is only known to work with networkx "
f"versions 3.x, but networkx {nx.__version__} is installed. "
"Perhaps try upgrading your Python environment.",
UserWarning,
stacklevel=2,
)
if len(version_minor) > 1:
raise RuntimeWarning(
f"nx-cugraph version {__version__} does not work with networkx version "
f"{nx.__version__}. Please upgrade (or fix) your Python environment."
)


if __name__ == "__main__":
from pathlib import Path

Expand Down
3 changes: 3 additions & 0 deletions python/nx-cugraph/nx_cugraph/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@
from .algorithms import *

from _nx_cugraph._version import __git_commit__, __version__
from _nx_cugraph import _check_networkx_version

_check_networkx_version()

0 comments on commit d77a2d6

Please sign in to comment.