Skip to content

Refactor: Moving backend docs from backends.py to backends.rst - #7776

Merged
dschult merged 1 commit into
networkx:mainfrom
Schefflera-Arboricola:mv_backend_doc
Feb 7, 2025
Merged

dschult merged 1 commit into
networkx:mainfrom
Schefflera-Arboricola:mv_backend_doc

Conversation

@Schefflera-Arboricola

Copy link
Copy Markdown
Member

I've moved the documentation from backends.py to backends.rst, as having ~400-450 lines of docs at the start of the code file felt excessive. I think giving the detailed backend docs their own space improves readability and the overall structure. LMK your thoughts on this change.

Additionally, I would like to propose converting backends.py into a sub-package, considering its growing size and complexity. I think this would help us refactor the code more to make it more readable and more organized and hence easier to contribute to and review. Also, if we do go down this route, I'd also suggest moving that backends folder(sub-package) out of utils, as I think the whole backends machinery has evolved from an utility to a big component of the project. LMKWYT.

Thank you :)

@Schefflera-Arboricola Schefflera-Arboricola added type: Documentation Discussion Issues for discussion and decision making Dispatching Related to dispatching and backend support labels Dec 22, 2024
@dschult

dschult commented Dec 22, 2024

Copy link
Copy Markdown
Member

This sounds promising to me! Thanks @Schefflera-Arboricola --

I think you are right that this module is so large we might find it easier to read and review if it was refactored. A new directory alongside utils makes sense to me. We could move the tests (which I think are still in classes) into that directory too.

Looking forward to input from @eriknw on this too.

What would be a good way to separate it into modules?

@Schefflera-Arboricola

Schefflera-Arboricola commented Dec 31, 2024 •

Copy link
Copy Markdown
Member Author

We could move the tests (which I think are still in classes) into that directory too.

yes, and also the configs.py and its tests.

What would be a good way to separate it into modules?

I think separating out all the helper functions/functionalities from the _dispatchable class might be a good start. Also, I'm not sure if separating methods(like how they are currently) of the _dispatchable class into different modules would make it less or more readable. For example, the refactor in PR #7761 could be said to increase the readability because there is one less indentation, but it can also be seen as adding an additional depth to the logic. Also I think for new-contributors having an extra indentation might be easier to read than to go down a level deeper into the rabbit hole. So, I think this is quite debatable, therefore we should concentrate more on separating the repeatitive functionalities and adding more smaller util functions, so that the main functionality(or the flow of functionality) of a method in the _dispatchable class is more clear just by reading through it; also better variable and function names :)

@eriknw

eriknw commented Jan 2, 2025

Copy link
Copy Markdown
Contributor

Thanks for this! I'm sorry for being slow to the party--I've been afk.

I think separating out docs as is currently done in this PR makes a lot of sense. It has gotten quite long.

Regarding moving to nx.backends, we avoided using this previously because it's unclear what nx.backends is expected to be and whether it should be a top-level, user-facing namespace. I want to support exploring packages via tab-completion, and backends is alphabetically low, so it would always appear in nx.<TAB> even though it may not be useful or what is expected. So, do we expect users to interact or get anything from nx.backends? If not, or if not yet, then perhaps nx.utils.backends or nx._backends may make more sense for now, but I'm open to nx.backends if we believe this is the direction we want to go (after all, this would give more signal to users that backends are a thing).

I think we can break up backends.py into a backends/ subpackage even if some of the files are short. There is handling of the entry points, handling of the environment variables for configs, helper functions for using caches, a couple other utilities, and #7765 adds plugin hooks, and these could all be separate files. It's not clear to me whether _dispatchable class can or should be split up, but I do support efforts of trying to make it more clear. IMHO, the value of #7761 isn't that it separates out the __call__ method and uses one less indent; it's that it defines a simple __call__ method when there are no networkx backends. I do think perhaps #7761 should define _call_backends_installed and _call_no_backends_installed in the class body.

@Schefflera-Arboricola

Copy link
Copy Markdown
Member Author

Thank you @dschult and @eriknw for your inputs.

I'm +1 on nx._backends.

And I'm removing the "discussion" label because I think we can merge this since I think the response to the change made in this PR has been positive, but feel free to continue the discussion at #7787 :)

@@ -13,6 +13,473 @@ variables.
<https://scientific-python.org/calendars/networkx.ics>`_ is an excellent way

@Schefflera-Arboricola Schefflera-Arboricola Jan 8, 2025 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for reviewers

  1. copy this backends.rst file in the root directory of your local networkx fork(main branch)

  2. then run the following command(in the networkx root directory) to confirm that the documentation has not be changed but just shifted:

    diff <(sed -n '16,481p' backends.rst) <(sed -n '2,467p' networkx/utils/backends.py)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty slick, thanks for providing these instructions! I just confirmed that documentation has not changed, so this PR is up to date and ready to go in.

And, yes, let's continue the refactor discussion in #7787 👍

@dschult dschult left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Schefflera-Arboricola for this!

@dschult
dschult merged commit 9156e92 into networkx:main Feb 7, 2025
@jarrodmillman jarrodmillman added this to the 3.5 milestone May 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Dispatching Related to dispatching and backend support type: Documentation

Development

Successfully merging this pull request may close these issues.

4 participants