A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://networkx.org/documentation/latest/developer/contribute.html below:

Contributor Guide — NetworkX 3.5.1rc0.dev0 documentation

Contributor Guide#

Note

This document assumes some familiarity with contributing to open source scientific Python projects using GitHub pull requests. If this does not describe you, you may first want to see the New Contributor FAQ. If you are using a LLM or any other AI model, you will still need to follow the process described here.

Development Workflow#
  1. If you are a first-time contributor:

  2. Develop your contribution:

  3. Test your contribution:

  4. Ensure your contribution is properly formatted.

  5. Submit your contribution:

  6. Review process:

    Note

    If the PR closes an issue, make sure that GitHub knows to automatically close the issue when the PR is merged. For example, if the PR closes issue number 1480, you could use the phrase “Fixes #1480” in the PR description or commit message.

  7. Document deprecations and API changes

    If your change introduces any API modifications including deprecations, please make sure the PR has the type: API label.

    To set up a function for deprecation:

    Note

    To reviewers: make sure the merge message has a brief description of the change(s) and if the PR closes an issue add, for example, “Closes #123” where 123 is the issue number.

Divergence from upstream main#

If GitHub indicates that the branch of your Pull Request can no longer be merged automatically, merge the main branch into yours:

git fetch upstream main
git merge upstream/main

If any conflicts occur, they need to be fixed before continuing. See which files are in conflict using:

Which displays a message like:

Unmerged paths:
  (use "git add <file>..." to mark resolution)

  both modified:   file_with_conflict.txt

Inside the conflicted file, you’ll find sections like these:

<<<<<<< HEAD
The way the text looks in your branch
=======
The way the text looks in the main branch
>>>>>>> main

Choose one version of the text that should be kept, and delete the rest:

The way the text looks in your branch

Now, add the fixed file:

git add file_with_conflict.txt

Once you’ve fixed all merge conflicts, do:

Note

Advanced Git users may want to rebase instead of merge, but we squash and merge PRs either way.

Guidelines# Testing#

networkx has an extensive test suite that ensures correct execution on your system. The test suite has to pass before a pull request can be merged, and tests should be added to cover any modifications to the code base. We make use of the pytest testing framework, with tests located in the various networkx/submodule/tests folders.

To run all tests:

$ PYTHONPATH=. pytest networkx

Or the tests for a specific submodule:

$ PYTHONPATH=. pytest networkx/readwrite

Or tests from a specific file:

$ PYTHONPATH=. pytest networkx/readwrite/tests/test_edgelist.py

Or a single test within that file:

$ PYTHONPATH=. pytest networkx/readwrite/tests/test_edgelist.py::test_parse_edgelist_with_data_list

Use --doctest-modules to run doctests. For example, run all tests and all doctests using:

$ PYTHONPATH=. pytest --doctest-modules networkx

Tests for a module should ideally cover all code in that module, i.e., statement coverage should be at 100%.

To measure the test coverage, run:

$ PYTHONPATH=. pytest --cov=networkx networkx

This will print a report with one line for each file in networkx, detailing the test coverage:

Name                                             Stmts   Miss Branch BrPart  Cover
----------------------------------------------------------------------------------
networkx/__init__.py                                33      2      2      1    91%
networkx/algorithms/__init__.py                    114      0      0      0   100%
networkx/algorithms/approximation/__init__.py       12      0      0      0   100%
networkx/algorithms/approximation/clique.py         42      1     18      1    97%
...

There are additional pytest plugins that provide enhanced features for running the test suite. These can be installed with pip install -r requirements/test-extras.txt. For example, with these plugins installed it is possible to run the tests (including doctests) with multiple cores in randomized order with:

pytest -n auto --doctest-modules --pyargs networkx
Adding tests#

If you’re new to testing, see existing test files for examples of things to do. Don’t let the tests keep you from submitting your contribution! If you’re not sure how to do this or are having trouble, submit your pull request anyway. We will help you create the tests and sort out any kind of problem during code review.

Image comparison#

Note

Image comparison tests require the pytest-mpl extension, which can be installed with:

If pytest-mpl is not installed, the test suite may emit warnings related to pytest.mark.mpl_image_compare - these can be safely ignored.

To run image comparisons:

$ PYTHONPATH=. pytest --mpl --pyargs networkx.drawing

The --mpl tells pytest to use pytest-mpl to compare the generated plots with baseline ones stored in networkx/drawing/tests/baseline.

To add a new test, add a test function to networkx/drawing/tests that returns a Matplotlib figure (or any figure object that has a savefig method) and decorate it as follows:

@pytest.mark.mpl_image_compare
def test_barbell():
    fig = plt.figure()
    barbell = nx.barbell_graph(4, 6)
    # make sure to fix any randomness
    pos = nx.spring_layout(barbell, seed=42)
    nx.draw(barbell, pos=pos)
    return fig

Then create a baseline image to compare against later:

$ pytest -k test_barbell --mpl-generate-path=networkx/drawing/tests/baseline

Note

In order to keep the size of the repository from becoming too large, we prefer to limit the size and number of baseline images we include.

And test:

$ pytest -k test_barbell --mpl
Documentation#

We use Sphinx for generating the API and reference documentation.

Pre-built versions can be found at

https://networkx.org/

for both the stable and the latest (i.e., development) releases.

Instructions#

After installing NetworkX and its dependencies, install the Python packages needed to build the documentation by entering the root directory and executing:

pip install -r requirements/doc.txt

Building the example gallery additionally requires the dependencies listed in requirements/extra.txt and requirements/example.txt:

pip install -r requirements/extra.txt
pip install -r requirements/example.txt

To build the HTML documentation, enter doc/ and execute:

This will generate a build/html subdirectory containing the built documentation. If the dependencies in extra.txt and example.txt are not installed, build the HTML documentation without generating figures by using:

To build the PDF documentation, enter:

You will need to have LaTeX installed for this.

Note

sphinx supports many other output formats. Type make without any arguments to see all the built-in options.

Adding examples#

The gallery examples are managed by sphinx-gallery. The source files for the example gallery are .py scripts in examples/ that generate one or more figures. They are executed automatically by sphinx-gallery when the documentation is built. The output is gathered and assembled into the gallery.

Building the example gallery locally requires that the additional dependencies in requirements/example.txt be installed in your development environment.

You can add a new plot by placing a new .py file in one of the directories inside the examples directory of the repository. See the other examples to get an idea for the format.

Note

Gallery examples should start with plot_, e.g. plot_new_example.py

General guidelines for making a good gallery plot:

Adding References#

If you are contributing a new algorithm (or an improvement to a current algorithm), a reference paper or resource should also be provided in the function docstring. For references to published papers, we try to follow the Chicago Citation Style. The quickest way of generating citation in this style is by searching for the paper on Google Scholar and clicking on the cite button. It will pop up the citation of the paper in multiple formats, and copy the Chicago style.

We prefer adding DOI links for URLs. If the DOI link resolves to a paywalled version of the article, we prefer adding a link to the arXiv version (if available) or any other publicly accessible copy of the paper.

An example of a reference:

.. [1] Cheong, Se-Hang, and Yain-Whar Si. "Force-directed algorithms for schematic drawings and
placement: A survey." Information Visualization 19, no. 1 (2020): 65-91.
https://doi.org/10.1177%2F1473871618821740

If the resource is uploaded as a PDF/DOCX/PPT on the web (lecture notes, presentations) it is better to use the wayback machine to create a snapshot of the resource and link the internet archive link. The URL of the resource can change, and it creates unreachable links from the documentation.

Using Math Formulae and Latex Formatting in Documentation#

When working with docstrings that contain math symbols or formulae use raw strings (r""") to ensure proper rendering. While LaTeX formatting can improve the appearance of the rendered documentation, it’s best to keep it simple and readable.

An example of a math formula:

\[Ax = \lambda x\]

Some inline math:

These are Cheeger's Inequalities for \d-Regular graphs:
$\frac{d- \lambda_2}{2} \leq h(G) \leq \sqrt{2d(d- \lambda_2)}$

These are Cheeger’s Inequalities for d-Regular graphs: \(\frac{d- \lambda_2}{2} \leq h(G) \leq \sqrt{2d(d- \lambda_2)}\)

Bugs#

Please report bugs on GitHub.

Policies#

All interactions with the project are subject to the NetworkX code of conduct.

We also follow these policies:


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4