summaryrefslogtreecommitdiff
path: root/developer/contribute.html
blob: a55159d69cfc6e2518655322ef1e6659a482ee4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136

<!DOCTYPE html>

<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.19: https://docutils.sourceforge.io/" />

    <title>Contributor Guide &#8212; NetworkX 3.1rc1.dev0 documentation</title>
  
  
  
  <script data-cfasync="false">
    document.documentElement.dataset.mode = localStorage.getItem("mode") || "light";
    document.documentElement.dataset.theme = localStorage.getItem("theme") || "light";
  </script>
  
  <!-- Loaded before other Sphinx assets -->
  <link href="../_static/styles/theme.css?digest=796348d33e8b1d947c94" rel="stylesheet">
<link href="../_static/styles/bootstrap.css?digest=796348d33e8b1d947c94" rel="stylesheet">
<link href="../_static/styles/pydata-sphinx-theme.css?digest=796348d33e8b1d947c94" rel="stylesheet">

  
  <link href="../_static/vendor/fontawesome/6.1.2/css/all.min.css?digest=796348d33e8b1d947c94" rel="stylesheet">
  <link rel="preload" as="font" type="font/woff2" crossorigin href="../_static/vendor/fontawesome/6.1.2/webfonts/fa-solid-900.woff2">
<link rel="preload" as="font" type="font/woff2" crossorigin href="../_static/vendor/fontawesome/6.1.2/webfonts/fa-brands-400.woff2">
<link rel="preload" as="font" type="font/woff2" crossorigin href="../_static/vendor/fontawesome/6.1.2/webfonts/fa-regular-400.woff2">

    <link rel="stylesheet" type="text/css" href="../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../_static/custom.css" />
    <link rel="stylesheet" type="text/css" href="../_static/sg_gallery.css" />
    <link rel="stylesheet" type="text/css" href="../_static/sg_gallery-binder.css" />
    <link rel="stylesheet" type="text/css" href="../_static/sg_gallery-dataframe.css" />
    <link rel="stylesheet" type="text/css" href="../_static/sg_gallery-rendered-html.css" />
  
  <!-- Pre-loaded scripts that we'll load fully later -->
  <link rel="preload" as="script" href="../_static/scripts/bootstrap.js?digest=796348d33e8b1d947c94">
<link rel="preload" as="script" href="../_static/scripts/pydata-sphinx-theme.js?digest=796348d33e8b1d947c94">

    <script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
    <script src="../_static/jquery.js"></script>
    <script src="../_static/underscore.js"></script>
    <script src="../_static/_sphinx_javascript_frameworks_compat.js"></script>
    <script src="../_static/doctools.js"></script>
    <script src="../_static/sphinx_highlight.js"></script>
    <script src="../_static/copybutton.js"></script>
    <script>DOCUMENTATION_OPTIONS.pagename = 'developer/contribute';</script>
    <link rel="canonical" href="https://networkx.org/documentation/stable/developer/contribute.html" />
    <link rel="search" type="application/opensearchdescription+xml"
          title="Search within NetworkX 3.1rc1.dev0 documentation"
          href="../_static/opensearch.xml"/>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="Mentored Projects" href="projects.html" />
    <link rel="prev" title="Mission and Values" href="values.html" />
<script
  defer
  data-domain="networkx.org"
  src="https://views.scientific-python.org/js/script.js"
></script>

  <meta name="viewport" content="width=device-width, initial-scale=1" />
  <meta name="docsearch:language" content="en"> 
  </head>
  
  
  <body data-spy="scroll" data-target="#bd-toc-nav" data-offset="180" data-default-mode="light">

  
  
  <a class="skip-link" href="#main-content">Skip to main content</a> 
<div class="container-fluid version-alert devbar">
  <div class="row no-gutters">
    <div class="col-12 text-center">
      This page is documentation for a DEVELOPMENT / PRE-RELEASE version.
      <a
        class="btn version-stable font-weight-bold ml-3 my-3 align-baseline"
        href="https://networkx.org/documentation/stable/"
        >Switch to stable version</a
      >
    </div>
  </div>
</div>


  
  <input type="checkbox" class="sidebar-toggle" name="__primary" id="__primary">
  <label class="overlay overlay-primary" for="__primary"></label>

  
  <input type="checkbox" class="sidebar-toggle" name="__secondary" id="__secondary">
  <label class="overlay overlay-secondary" for="__secondary"></label>

  
  <div class="search-button__wrapper">
    <div class="search-button__overlay"></div>
    <div class="search-button__search-container">
      
<form class="bd-search d-flex align-items-center" action="../search.html" method="get">
  <i class="fa-solid fa-magnifying-glass"></i>
  <input type="search" class="form-control" name="q" id="search-input" placeholder="Search the docs ..." aria-label="Search the docs ..." autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false">
  <span class="search-button__kbd-shortcut"><kbd class="kbd-shortcut__modifier">Ctrl</kbd>+<kbd>K</kbd></span>
</form>
    </div>
  </div><div class="bd-header-announcement container-fluid" id="header-announcement">
    


<div class="bd-header-announcement__content"><p><a href='https://forms.gle/NUGcBxyjx5onbAgc8'> NetworkX User Survey 2023</a> 🎉 Fill out the survey to tell us about your ideas, complaints, praises of NetworkX!</p></div>

  </div>

  
  <nav class="bd-header navbar navbar-expand-lg bd-navbar" id="navbar-main"><div class="bd-header__inner bd-page-width">
  <label class="sidebar-toggle primary-toggle" for="__primary">
      <span class="fa-solid fa-bars"></span>
  </label>
  <div id="navbar-start">
    
    
  


<a class="navbar-brand logo" href="../index.html">

  
  
  
  
  
  
  

  
    <img src="../_static/networkx_banner.svg" class="logo__image only-light" alt="Logo image">
    <img src="../_static/networkx_banner.svg" class="logo__image only-dark" alt="Logo image">
  
  
</a>
    
  </div>

  
  <div class="col-lg-9 navbar-header-items">
    <div id="navbar-center" class="mr-auto">
      
      <div class="navbar-center-item">
        <nav class="navbar-nav">
    <p class="sidebar-header-items__title" role="heading" aria-level="1" aria-label="Site Navigation">
        Site Navigation
    </p>
    <ul id="navbar-main-elements" class="navbar-nav">
        
                    <li class="nav-item">
                      <a class="nav-link nav-internal" href="../install.html">
                        Install
                      </a>
                    </li>
                

                    <li class="nav-item">
                      <a class="nav-link nav-internal" href="../tutorial.html">
                        Tutorial
                      </a>
                    </li>
                

                    <li class="nav-item">
                      <a class="nav-link nav-internal" href="../reference/index.html">
                        Reference
                      </a>
                    </li>
                

                    <li class="nav-item">
                      <a class="nav-link nav-internal" href="../auto_examples/index.html">
                        Gallery
                      </a>
                    </li>
                

                    <li class="nav-item current active">
                      <a class="nav-link nav-internal" href="index.html">
                        Developer
                      </a>
                    </li>
                

                    <li class="nav-item">
                      <a class="nav-link nav-internal" href="../release/index.html">
                        Releases
                      </a>
                    </li>
                

                <li class="nav-item">
                  <a class="nav-link nav-external" href="https://networkx.org/nx-guides/">
                    Guides
                  </a>
                </li>
                
    </ul>
</nav>
      </div>
      
    </div>

    <div id="navbar-end">
      
        <div class="navbar-end-item navbar-persistent--container">
          
<button class="btn btn-sm navbar-btn search-button search-button__button" title="Search" aria-label="Search" data-toggle="tooltip">
  <i class="fa-solid fa-magnifying-glass"></i>
</button>
        </div>
      
      
      <div class="navbar-end-item">
        <button class="theme-switch-button btn btn-sm btn-outline-primary navbar-btn rounded-circle" title="light/dark" aria-label="light/dark" data-toggle="tooltip">
    <span class="theme-switch" data-mode="light"><i class="fa-solid fa-sun"></i></span>
    <span class="theme-switch" data-mode="dark"><i class="fa-solid fa-moon"></i></span>
    <span class="theme-switch" data-mode="auto"><i class="fa-solid fa-circle-half-stroke"></i></span>
</button>
      </div>
      
      <div class="navbar-end-item">
        <ul id="navbar-icon-links" class="navbar-nav" aria-label="Icon Links">
        <li class="nav-item">
          
          
          
          
          
          
          
          <a href="https://networkx.org" title="Home Page" class="nav-link" rel="noopener" target="_blank" data-toggle="tooltip"><span><i class="fas fa-home"></i></span>
            <label class="sr-only">Home Page</label></a>
        </li>
        <li class="nav-item">
          
          
          
          
          
          
          
          <a href="https://github.com/networkx/networkx" title="GitHub" class="nav-link" rel="noopener" target="_blank" data-toggle="tooltip"><span><i class="fab fa-github-square"></i></span>
            <label class="sr-only">GitHub</label></a>
        </li>
      </ul>
      </div>
      
      <div class="navbar-end-item">
        <ul class="navbar-nav">
  <li class="mr-2 dropdown">
    <button
      type="button"
      class="btn btn-version btn-sm navbar-btn dropdown-toggle"
      id="dLabelMore"
      data-toggle="dropdown"
    >
      v3.1rc1.dev0
      <span class="caret"></span>
    </button>
    <ul class="dropdown-menu" aria-labelledby="dLabelMore">
      <li>
        <a href="https://networkx.org/documentation/latest/index.html"
          >devel (latest)</a
        >
      </li>
      <li>
        <a href="https://networkx.org/documentation/stable/index.html"
          >current (stable)</a
        >
      </li>
    </ul>
  </li>
</ul>
      </div>
      
    </div>
  </div>


  
  
    <div class="navbar-persistent--mobile">
<button class="btn btn-sm navbar-btn search-button search-button__button" title="Search" aria-label="Search" data-toggle="tooltip">
  <i class="fa-solid fa-magnifying-glass"></i>
</button>
    </div>
  

  
  <label class="sidebar-toggle secondary-toggle" for="__secondary">
      <span class="fa-solid fa-outdent"></span>
  </label>
  

</div>
  </nav>
  

  <div class="bd-container">
    <div class="bd-container__inner bd-page-width">
      
      <div class="bd-sidebar-primary bd-sidebar">
        
  
  <div class="sidebar-header-items sidebar-primary__section">
    
    
      <div class="sidebar-header-items__center">
      
      <div class="navbar-center-item">
        <nav class="navbar-nav">
    <p class="sidebar-header-items__title" role="heading" aria-level="1" aria-label="Site Navigation">
        Site Navigation
    </p>
    <ul id="navbar-main-elements" class="navbar-nav">
        
                    <li class="nav-item">
                      <a class="nav-link nav-internal" href="../install.html">
                        Install
                      </a>
                    </li>
                

                    <li class="nav-item">
                      <a class="nav-link nav-internal" href="../tutorial.html">
                        Tutorial
                      </a>
                    </li>
                

                    <li class="nav-item">
                      <a class="nav-link nav-internal" href="../reference/index.html">
                        Reference
                      </a>
                    </li>
                

                    <li class="nav-item">
                      <a class="nav-link nav-internal" href="../auto_examples/index.html">
                        Gallery
                      </a>
                    </li>
                

                    <li class="nav-item current active">
                      <a class="nav-link nav-internal" href="index.html">
                        Developer
                      </a>
                    </li>
                

                    <li class="nav-item">
                      <a class="nav-link nav-internal" href="../release/index.html">
                        Releases
                      </a>
                    </li>
                

                <li class="nav-item">
                  <a class="nav-link nav-external" href="https://networkx.org/nx-guides/">
                    Guides
                  </a>
                </li>
                
    </ul>
</nav>
      </div>
      
      </div>
    

    
    
    <div class="sidebar-header-items__end">
      
      <div class="navbar-end-item">
        <button class="theme-switch-button btn btn-sm btn-outline-primary navbar-btn rounded-circle" title="light/dark" aria-label="light/dark" data-toggle="tooltip">
    <span class="theme-switch" data-mode="light"><i class="fa-solid fa-sun"></i></span>
    <span class="theme-switch" data-mode="dark"><i class="fa-solid fa-moon"></i></span>
    <span class="theme-switch" data-mode="auto"><i class="fa-solid fa-circle-half-stroke"></i></span>
</button>
      </div>
      
      <div class="navbar-end-item">
        <ul id="navbar-icon-links" class="navbar-nav" aria-label="Icon Links">
        <li class="nav-item">
          
          
          
          
          
          
          
          <a href="https://networkx.org" title="Home Page" class="nav-link" rel="noopener" target="_blank" data-toggle="tooltip"><span><i class="fas fa-home"></i></span>
            <label class="sr-only">Home Page</label></a>
        </li>
        <li class="nav-item">
          
          
          
          
          
          
          
          <a href="https://github.com/networkx/networkx" title="GitHub" class="nav-link" rel="noopener" target="_blank" data-toggle="tooltip"><span><i class="fab fa-github-square"></i></span>
            <label class="sr-only">GitHub</label></a>
        </li>
      </ul>
      </div>
      
      <div class="navbar-end-item">
        <ul class="navbar-nav">
  <li class="mr-2 dropdown">
    <button
      type="button"
      class="btn btn-version btn-sm navbar-btn dropdown-toggle"
      id="dLabelMore"
      data-toggle="dropdown"
    >
      v3.1rc1.dev0
      <span class="caret"></span>
    </button>
    <ul class="dropdown-menu" aria-labelledby="dLabelMore">
      <li>
        <a href="https://networkx.org/documentation/latest/index.html"
          >devel (latest)</a
        >
      </li>
      <li>
        <a href="https://networkx.org/documentation/stable/index.html"
          >current (stable)</a
        >
      </li>
    </ul>
  </li>
</ul>
      </div>
      
    </div>
    
  </div>

  
  <div class="sidebar-start-items sidebar-primary__section">
    <div class="sidebar-start-items__item"><nav class="bd-links" id="bd-docs-nav" aria-label="Section navigation">
  <p class="bd-links__title" role="heading" aria-level="1">
    Section Navigation
  </p>
  <div class="bd-toc-item navbar-nav">
    <ul class="current nav bd-sidenav">
<li class="toctree-l1"><a class="reference internal" href="about_us.html">About Us</a></li>
<li class="toctree-l1"><a class="reference internal" href="code_of_conduct.html">Code of Conduct</a></li>
<li class="toctree-l1"><a class="reference internal" href="values.html">Mission and Values</a></li>
<li class="toctree-l1 current active"><a class="current reference internal" href="#">Contributor Guide</a></li>
<li class="toctree-l1"><a class="reference internal" href="projects.html">Mentored Projects</a></li>

<li class="toctree-l1"><a class="reference internal" href="new_contributor_faq.html">New Contributor FAQ</a></li>
<li class="toctree-l1"><a class="reference internal" href="core_developer.html">Core Developer Guide</a></li>
<li class="toctree-l1"><a class="reference internal" href="release.html">Release Process</a></li>
<li class="toctree-l1"><a class="reference internal" href="deprecations.html">Deprecations</a></li>
<li class="toctree-l1"><a class="reference internal" href="roadmap.html">Roadmap</a></li>
<li class="toctree-l1"><a class="reference internal" href="nxeps/index.html">NXEPs</a></li>
</ul>

  </div>
</nav>
    </div>
    <div class="sidebar-start-items__item">
    </div>
  </div>
  

  
  <div class="sidebar-end-items sidebar-primary__section">
    <div class="sidebar-end-items__item">
    </div>
  </div>

  
  <div id="rtd-footer-container"></div>

      </div>
      <main id="main-content" class="bd-main">
        
        
        <div class="bd-content">
          <div class="bd-article-container">
            
            <div class="bd-header-article">
                
            </div>
            
            
            <article class="bd-article" role="main">
              
  <section id="contributor-guide">
<span id="id1"></span><h1>Contributor Guide<a class="headerlink" href="#contributor-guide" title="Permalink to this heading">#</a></h1>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>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 <a class="reference internal" href="new_contributor_faq.html#contributing-faq"><span class="std std-ref">New Contributor FAQ</span></a>.</p>
</div>
<section id="development-workflow">
<span id="dev-workflow"></span><h2>Development Workflow<a class="headerlink" href="#development-workflow" title="Permalink to this heading">#</a></h2>
<ol class="arabic">
<li><p>If you are a first-time contributor:</p>
<ul>
<li><p>Go to <a class="github reference external" href="https://github.com/networkx/networkx">networkx/networkx</a> and click the
“fork” button to create your own copy of the project.</p></li>
<li><p>Clone the project to your local computer:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">git</span> <span class="n">clone</span> <span class="n">git</span><span class="nd">@github</span><span class="o">.</span><span class="n">com</span><span class="p">:</span><span class="n">your</span><span class="o">-</span><span class="n">username</span><span class="o">/</span><span class="n">networkx</span><span class="o">.</span><span class="n">git</span>
</pre></div>
</div>
</li>
<li><p>Navigate to the folder networkx and add the upstream repository:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">git</span> <span class="n">remote</span> <span class="n">add</span> <span class="n">upstream</span> <span class="n">git</span><span class="nd">@github</span><span class="o">.</span><span class="n">com</span><span class="p">:</span><span class="n">networkx</span><span class="o">/</span><span class="n">networkx</span><span class="o">.</span><span class="n">git</span>
</pre></div>
</div>
</li>
<li><p>Now, you have remote repositories named:</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">upstream</span></code>, which refers to the <code class="docutils literal notranslate"><span class="pre">networkx</span></code> repository</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">origin</span></code>, which refers to your personal fork</p></li>
</ul>
</li>
<li><p>Next, you need to set up your build environment.
Here are instructions for two popular environment managers:</p>
<ul>
<li><p><code class="docutils literal notranslate"><span class="pre">venv</span></code> (pip based)</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># Create a virtualenv named ``networkx-dev`` that lives in the directory of</span>
<span class="c1"># the same name</span>
<span class="n">python</span> <span class="o">-</span><span class="n">m</span> <span class="n">venv</span> <span class="n">networkx</span><span class="o">-</span><span class="n">dev</span>
<span class="c1"># Activate it</span>
<span class="n">source</span> <span class="n">networkx</span><span class="o">-</span><span class="n">dev</span><span class="o">/</span><span class="nb">bin</span><span class="o">/</span><span class="n">activate</span>
<span class="c1"># Install main development and runtime dependencies of networkx</span>
<span class="n">pip</span> <span class="n">install</span> <span class="o">-</span><span class="n">r</span> <span class="n">requirements</span><span class="o">/</span><span class="n">default</span><span class="o">.</span><span class="n">txt</span> <span class="o">-</span><span class="n">r</span> <span class="n">requirements</span><span class="o">/</span><span class="n">test</span><span class="o">.</span><span class="n">txt</span> <span class="o">-</span><span class="n">r</span> <span class="n">requirements</span><span class="o">/</span><span class="n">developer</span><span class="o">.</span><span class="n">txt</span>
<span class="c1">#</span>
<span class="c1"># (Optional) Install pygraphviz and pydot packages</span>
<span class="c1"># These packages require that you have your system properly configured</span>
<span class="c1"># and what that involves differs on various systems.</span>
<span class="c1"># pip install -r requirements/extra.txt</span>
<span class="c1">#</span>
<span class="c1"># Build and install networkx from source</span>
<span class="n">pip</span> <span class="n">install</span> <span class="o">-</span><span class="n">e</span> <span class="o">.</span>
<span class="c1"># Test your installation</span>
<span class="n">pytest</span> <span class="o">--</span><span class="n">pyargs</span> <span class="n">networkx</span>
</pre></div>
</div>
</li>
<li><p><code class="docutils literal notranslate"><span class="pre">conda</span></code> (Anaconda or Miniconda)</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="c1"># Create a conda environment named ``networkx-dev``</span>
<span class="n">conda</span> <span class="n">create</span> <span class="o">--</span><span class="n">name</span> <span class="n">networkx</span><span class="o">-</span><span class="n">dev</span>
<span class="c1"># Activate it</span>
<span class="n">conda</span> <span class="n">activate</span> <span class="n">networkx</span><span class="o">-</span><span class="n">dev</span>
<span class="c1"># Install main development and runtime dependencies of networkx</span>
<span class="n">conda</span> <span class="n">install</span> <span class="o">-</span><span class="n">c</span> <span class="n">conda</span><span class="o">-</span><span class="n">forge</span> <span class="o">--</span><span class="n">file</span> <span class="n">requirements</span><span class="o">/</span><span class="n">default</span><span class="o">.</span><span class="n">txt</span> <span class="o">--</span><span class="n">file</span> <span class="n">requirements</span><span class="o">/</span><span class="n">test</span><span class="o">.</span><span class="n">txt</span> <span class="o">--</span><span class="n">file</span> <span class="n">requirements</span><span class="o">/</span><span class="n">developer</span><span class="o">.</span><span class="n">txt</span>
<span class="c1">#</span>
<span class="c1"># (Optional) Install pygraphviz and pydot packages</span>
<span class="c1"># These packages require that you have your system properly configured</span>
<span class="c1"># and what that involves differs on various systems.</span>
<span class="c1"># conda install -c conda-forge --file requirements/extra.txt</span>
<span class="c1">#</span>
<span class="c1"># Install networkx from source</span>
<span class="n">pip</span> <span class="n">install</span> <span class="o">-</span><span class="n">e</span> <span class="o">.</span>
<span class="c1"># Test your installation</span>
<span class="n">pytest</span> <span class="o">--</span><span class="n">pyargs</span> <span class="n">networkx</span>
</pre></div>
</div>
</li>
</ul>
</li>
<li><p>Finally, we recommend you use a pre-commit hook, which runs black when
you type <code class="docutils literal notranslate"><span class="pre">git</span> <span class="pre">commit</span></code>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">pre</span><span class="o">-</span><span class="n">commit</span> <span class="n">install</span>
</pre></div>
</div>
</li>
</ul>
</li>
<li><p>Develop your contribution:</p>
<ul>
<li><p>Pull the latest changes from upstream:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">git</span> <span class="n">checkout</span> <span class="n">main</span>
<span class="n">git</span> <span class="n">pull</span> <span class="n">upstream</span> <span class="n">main</span>
</pre></div>
</div>
</li>
<li><p>Create a branch for the feature you want to work on. Since the
branch name will appear in the merge message, use a sensible name
such as ‘bugfix-for-issue-1480’:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">git</span> <span class="n">checkout</span> <span class="o">-</span><span class="n">b</span> <span class="n">bugfix</span><span class="o">-</span><span class="k">for</span><span class="o">-</span><span class="n">issue</span><span class="o">-</span><span class="mi">1480</span> <span class="n">main</span>
</pre></div>
</div>
</li>
<li><p>Commit locally as you progress (<code class="docutils literal notranslate"><span class="pre">git</span> <span class="pre">add</span></code> and <code class="docutils literal notranslate"><span class="pre">git</span> <span class="pre">commit</span></code>)</p></li>
</ul>
</li>
<li><p>Test your contribution:</p>
<ul>
<li><p>Run the test suite locally (see <a class="reference internal" href="#testing">Testing</a> for details):</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">PYTHONPATH</span><span class="o">=.</span> <span class="n">pytest</span> <span class="n">networkx</span>
</pre></div>
</div>
</li>
<li><p>Running the tests locally <em>before</em> submitting a pull request helps catch
problems early and reduces the load on the continuous integration
system.</p></li>
</ul>
</li>
<li><p>Submit your contribution:</p>
<ul>
<li><p>Push your changes back to your fork on GitHub:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">git</span> <span class="n">push</span> <span class="n">origin</span> <span class="n">bugfix</span><span class="o">-</span><span class="k">for</span><span class="o">-</span><span class="n">issue</span><span class="o">-</span><span class="mi">1480</span>
</pre></div>
</div>
</li>
<li><p>Go to GitHub. The new branch will show up with a green Pull Request
button—click it.</p></li>
<li><p>If you want, post on the <a class="reference external" href="http://groups.google.com/group/networkx-discuss">mailing list</a> to explain your changes or
to ask for review.</p></li>
</ul>
</li>
<li><p>Review process:</p>
<ul class="simple">
<li><p>Every Pull Request (PR) update triggers a set of <a class="reference external" href="https://en.wikipedia.org/wiki/Continuous_integration">continuous integration</a> services
that check that the code is up to standards and passes all our tests.
These checks must pass before your PR can be merged.  If one of the
checks fails, you can find out why by clicking on the “failed” icon (red
cross) and inspecting the build and test log.</p></li>
<li><p>Reviewers (the other developers and interested community members) will
write inline and/or general comments on your PR to help
you improve its implementation, documentation, and style.  Every single
developer working on the project has their code reviewed, and we’ve come
to see it as friendly conversation from which we all learn and the
overall code quality benefits.  Therefore, please don’t let the review
discourage you from contributing: its only aim is to improve the quality
of project, not to criticize (we are, after all, very grateful for the
time you’re donating!).</p></li>
<li><p>To update your PR, make your changes on your local repository
and commit. As soon as those changes are pushed up (to the same branch as
before) the PR will update automatically.</p></li>
</ul>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>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.</p>
</div>
</li>
<li><p>Document changes</p>
<p>If your change introduces any API modifications, please update
<code class="docutils literal notranslate"><span class="pre">doc/release/release_dev.rst</span></code>.</p>
<p>To set up a function for deprecation:</p>
<ul>
<li><p>Use a deprecation warning to warn users. For example:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">msg</span> <span class="o">=</span> <span class="s2">&quot;curly_hair is deprecated and will be removed in v3.0. Use sum() instead.&quot;</span>
<span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="n">msg</span><span class="p">,</span> <span class="ne">DeprecationWarning</span><span class="p">)</span>
</pre></div>
</div>
</li>
<li><p>Add a warning to <code class="docutils literal notranslate"><span class="pre">networkx/conftest.py</span></code>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">warnings</span><span class="o">.</span><span class="n">filterwarnings</span><span class="p">(</span>
    <span class="s2">&quot;ignore&quot;</span><span class="p">,</span> <span class="n">category</span><span class="o">=</span><span class="ne">DeprecationWarning</span><span class="p">,</span> <span class="n">message</span><span class="o">=&lt;</span><span class="n">start</span> <span class="n">of</span> <span class="n">message</span><span class="o">&gt;</span>
<span class="p">)</span>
</pre></div>
</div>
</li>
<li><p>Add a reminder to <code class="docutils literal notranslate"><span class="pre">doc/developer/deprecations.rst</span></code> for the team
to remove the deprecated functionality in the future. For example:</p>
<div class="highlight-rst notranslate"><div class="highlight"><pre><span></span><span class="m">*</span> In <span class="s">``utils/misc.py``</span> remove <span class="s">``generate_unique_node``</span> and related tests.
</pre></div>
</div>
</li>
<li><p>Add a note (and a link to the PR) to <code class="docutils literal notranslate"><span class="pre">doc/release/release_dev.rst</span></code>:</p>
<div class="highlight-rst notranslate"><div class="highlight"><pre><span></span>[<span class="s">`#4281 </span><span class="si">&lt;https://github.com/networkx/networkx/pull/4281&gt;</span><span class="s">`_</span>]
Deprecate <span class="s">``read_yaml``</span> and <span class="s">``write_yaml``</span>.
</pre></div>
</div>
</li>
</ul>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>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.</p>
</div>
</li>
</ol>
</section>
<section id="divergence-from-upstream-main">
<h2>Divergence from <code class="docutils literal notranslate"><span class="pre">upstream</span> <span class="pre">main</span></code><a class="headerlink" href="#divergence-from-upstream-main" title="Permalink to this heading">#</a></h2>
<p>If GitHub indicates that the branch of your Pull Request can no longer
be merged automatically, merge the main branch into yours:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">git</span> <span class="n">fetch</span> <span class="n">upstream</span> <span class="n">main</span>
<span class="n">git</span> <span class="n">merge</span> <span class="n">upstream</span><span class="o">/</span><span class="n">main</span>
</pre></div>
</div>
<p>If any conflicts occur, they need to be fixed before continuing.  See
which files are in conflict using:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">git</span> <span class="n">status</span>
</pre></div>
</div>
<p>Which displays a message like:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">Unmerged</span> <span class="n">paths</span><span class="p">:</span>
  <span class="p">(</span><span class="n">use</span> <span class="s2">&quot;git add &lt;file&gt;...&quot;</span> <span class="n">to</span> <span class="n">mark</span> <span class="n">resolution</span><span class="p">)</span>

  <span class="n">both</span> <span class="n">modified</span><span class="p">:</span>   <span class="n">file_with_conflict</span><span class="o">.</span><span class="n">txt</span>
</pre></div>
</div>
<p>Inside the conflicted file, you’ll find sections like these:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">&lt;&lt;&lt;&lt;&lt;&lt;&lt;</span> <span class="n">HEAD</span>
<span class="n">The</span> <span class="n">way</span> <span class="n">the</span> <span class="n">text</span> <span class="n">looks</span> <span class="ow">in</span> <span class="n">your</span> <span class="n">branch</span>
<span class="o">=======</span>
<span class="n">The</span> <span class="n">way</span> <span class="n">the</span> <span class="n">text</span> <span class="n">looks</span> <span class="ow">in</span> <span class="n">the</span> <span class="n">main</span> <span class="n">branch</span>
<span class="o">&gt;&gt;&gt;&gt;&gt;&gt;&gt;</span> <span class="n">main</span>
</pre></div>
</div>
<p>Choose one version of the text that should be kept, and delete the
rest:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">The</span> <span class="n">way</span> <span class="n">the</span> <span class="n">text</span> <span class="n">looks</span> <span class="ow">in</span> <span class="n">your</span> <span class="n">branch</span>
</pre></div>
</div>
<p>Now, add the fixed file:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">git</span> <span class="n">add</span> <span class="n">file_with_conflict</span><span class="o">.</span><span class="n">txt</span>
</pre></div>
</div>
<p>Once you’ve fixed all merge conflicts, do:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">git</span> <span class="n">commit</span>
</pre></div>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Advanced Git users may want to rebase instead of merge,
but we squash and merge PRs either way.</p>
</div>
</section>
<section id="guidelines">
<h2>Guidelines<a class="headerlink" href="#guidelines" title="Permalink to this heading">#</a></h2>
<ul>
<li><p>All code should have tests.</p></li>
<li><p>All code should be documented, to the same
<a class="reference external" href="https://numpydoc.readthedocs.io/en/latest/format.html#docstring-standard">standard</a>
as NumPy and SciPy.</p></li>
<li><p>All changes are reviewed.  Ask on the
<a class="reference external" href="http://groups.google.com/group/networkx-discuss">mailing list</a> if
you get no response to your pull request.</p></li>
<li><p>Default dependencies are listed in <code class="docutils literal notranslate"><span class="pre">requirements/default.txt</span></code> and extra
(i.e., optional) dependencies are listed in <code class="docutils literal notranslate"><span class="pre">requirements/extra.txt</span></code>.
We don’t often add new default and extra dependencies.  If you are considering
adding code that has a dependency, you should first consider adding a gallery
example.  Typically, new proposed dependencies would first be added as extra
dependencies.  Extra dependencies should be easy to install on all platforms
and widely-used.  New default dependencies should be easy to install on all
platforms, widely-used in the community, and have demonstrated potential for
wide-spread use in NetworkX.</p></li>
<li><p>Use the following import conventions:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">numpy</span> <span class="k">as</span> <span class="nn">np</span>
<span class="kn">import</span> <span class="nn">scipy</span> <span class="k">as</span> <span class="nn">sp</span>
<span class="kn">import</span> <span class="nn">matplotlib</span> <span class="k">as</span> <span class="nn">mpl</span>
<span class="kn">import</span> <span class="nn">matplotlib.pyplot</span> <span class="k">as</span> <span class="nn">plt</span>
<span class="kn">import</span> <span class="nn">pandas</span> <span class="k">as</span> <span class="nn">pd</span>
<span class="kn">import</span> <span class="nn">networkx</span> <span class="k">as</span> <span class="nn">nx</span>
</pre></div>
</div>
<p>After importing <code class="xref py py-obj docutils literal notranslate"><span class="pre">sp`</span></code> for <code class="docutils literal notranslate"><span class="pre">scipy</span></code>:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">scipy</span> <span class="k">as</span> <span class="nn">sp</span>
</pre></div>
</div>
<p>use the following imports:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">scipy.linalg</span>  <span class="c1"># call as sp.linalg</span>
<span class="kn">import</span> <span class="nn">scipy.sparse</span>  <span class="c1"># call as sp.sparse</span>
<span class="kn">import</span> <span class="nn">scipy.sparse.linalg</span>  <span class="c1"># call as sp.sparse.linalg</span>
<span class="kn">import</span> <span class="nn">scipy.stats</span>  <span class="c1"># call as sp.stats</span>
<span class="kn">import</span> <span class="nn">scipy.optimize</span>  <span class="c1"># call as sp.optimize</span>
</pre></div>
</div>
<p>For example, many libraries have a <code class="docutils literal notranslate"><span class="pre">linalg</span></code> subpackage: <code class="docutils literal notranslate"><span class="pre">nx.linalg</span></code>,
<code class="docutils literal notranslate"><span class="pre">np.linalg</span></code>, <code class="docutils literal notranslate"><span class="pre">sp.linalg</span></code>, <code class="docutils literal notranslate"><span class="pre">sp.sparse.linalg</span></code>. The above import
pattern makes the origin of any particular instance of <code class="docutils literal notranslate"><span class="pre">linalg</span></code> explicit.</p>
</li>
<li><p>Use the decorator <code class="docutils literal notranslate"><span class="pre">not_implemented_for</span></code> in <code class="docutils literal notranslate"><span class="pre">networkx/utils/decorators.py</span></code>
to designate that a function doesn’t accept ‘directed’, ‘undirected’,
‘multigraph’ or ‘graph’.  The first argument of the decorated function should
be the graph object to be checked.</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="nd">@nx</span><span class="o">.</span><span class="n">not_implemented_for</span><span class="p">(</span><span class="s2">&quot;directed&quot;</span><span class="p">,</span> <span class="s2">&quot;multigraph&quot;</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">function_not_for_MultiDiGraph</span><span class="p">(</span><span class="n">G</span><span class="p">,</span> <span class="n">others</span><span class="p">):</span>
    <span class="c1"># function not for graphs that are directed *and* multigraph</span>
    <span class="k">pass</span>


<span class="nd">@nx</span><span class="o">.</span><span class="n">not_implemented_for</span><span class="p">(</span><span class="s2">&quot;directed&quot;</span><span class="p">)</span>
<span class="nd">@nx</span><span class="o">.</span><span class="n">not_implemented_for</span><span class="p">(</span><span class="s2">&quot;multigraph&quot;</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">function_only_for_Graph</span><span class="p">(</span><span class="n">G</span><span class="p">,</span> <span class="n">others</span><span class="p">):</span>
    <span class="c1"># function not for directed graphs *or* for multigraphs</span>
    <span class="k">pass</span>
</pre></div>
</div>
</li>
</ul>
</section>
<section id="testing">
<h2>Testing<a class="headerlink" href="#testing" title="Permalink to this heading">#</a></h2>
<p><code class="docutils literal notranslate"><span class="pre">networkx</span></code> 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 <a class="reference external" href="https://docs.pytest.org/en/latest/">pytest</a>
testing framework, with tests located in the various
<code class="docutils literal notranslate"><span class="pre">networkx/submodule/tests</span></code> folders.</p>
<p>To run all tests:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ PYTHONPATH=. pytest networkx
</pre></div>
</div>
<p>Or the tests for a specific submodule:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ PYTHONPATH=. pytest networkx/readwrite
</pre></div>
</div>
<p>Or tests from a specific file:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ PYTHONPATH=. pytest networkx/readwrite/tests/test_edgelist.py
</pre></div>
</div>
<p>Or a single test within that file:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ PYTHONPATH=. pytest networkx/readwrite/tests/test_edgelist.py::test_parse_edgelist_with_data_list
</pre></div>
</div>
<p>Use <code class="docutils literal notranslate"><span class="pre">--doctest-modules</span></code> to run doctests.
For example, run all tests and all doctests using:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ PYTHONPATH=. pytest --doctest-modules networkx
</pre></div>
</div>
<p>Tests for a module should ideally cover all code in that module,
i.e., statement coverage should be at 100%.</p>
<p>To measure the test coverage, run:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ PYTHONPATH=. pytest --cov=networkx networkx
</pre></div>
</div>
<p>This will print a report with one line for each file in <code class="xref py py-obj docutils literal notranslate"><span class="pre">networkx</span></code>,
detailing the test coverage:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">Name</span>                                             <span class="n">Stmts</span>   <span class="n">Miss</span> <span class="n">Branch</span> <span class="n">BrPart</span>  <span class="n">Cover</span>
<span class="o">----------------------------------------------------------------------------------</span>
<span class="n">networkx</span><span class="o">/</span><span class="fm">__init__</span><span class="o">.</span><span class="n">py</span>                                <span class="mi">33</span>      <span class="mi">2</span>      <span class="mi">2</span>      <span class="mi">1</span>    <span class="mi">91</span><span class="o">%</span>
<span class="n">networkx</span><span class="o">/</span><span class="n">algorithms</span><span class="o">/</span><span class="fm">__init__</span><span class="o">.</span><span class="n">py</span>                    <span class="mi">114</span>      <span class="mi">0</span>      <span class="mi">0</span>      <span class="mi">0</span>   <span class="mi">100</span><span class="o">%</span>
<span class="n">networkx</span><span class="o">/</span><span class="n">algorithms</span><span class="o">/</span><span class="n">approximation</span><span class="o">/</span><span class="fm">__init__</span><span class="o">.</span><span class="n">py</span>       <span class="mi">12</span>      <span class="mi">0</span>      <span class="mi">0</span>      <span class="mi">0</span>   <span class="mi">100</span><span class="o">%</span>
<span class="n">networkx</span><span class="o">/</span><span class="n">algorithms</span><span class="o">/</span><span class="n">approximation</span><span class="o">/</span><span class="n">clique</span><span class="o">.</span><span class="n">py</span>         <span class="mi">42</span>      <span class="mi">1</span>     <span class="mi">18</span>      <span class="mi">1</span>    <span class="mi">97</span><span class="o">%</span>
<span class="o">...</span>
</pre></div>
</div>
<section id="adding-tests">
<h3>Adding tests<a class="headerlink" href="#adding-tests" title="Permalink to this heading">#</a></h3>
<p>If you’re <strong>new to testing</strong>, see existing test files for examples of things to do.
<strong>Don’t let the tests keep you from submitting your contribution!</strong>
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.</p>
</section>
<section id="image-comparison">
<h3>Image comparison<a class="headerlink" href="#image-comparison" title="Permalink to this heading">#</a></h3>
<p>To run image comparisons:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ PYTHONPATH=. pytest --mpl --pyargs networkx.drawing
</pre></div>
</div>
<p>The <code class="docutils literal notranslate"><span class="pre">--mpl</span></code> tells <code class="docutils literal notranslate"><span class="pre">pytest</span></code> to use <code class="docutils literal notranslate"><span class="pre">pytest-mpl</span></code> to compare the generated plots
with baseline ones stored in <code class="docutils literal notranslate"><span class="pre">networkx/drawing/tests/baseline</span></code>.</p>
<p>To add a new test, add a test function to <code class="docutils literal notranslate"><span class="pre">networkx/drawing/tests</span></code> that
returns a Matplotlib figure (or any figure object that has a savefig method)
and decorate it as follows:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="nd">@pytest</span><span class="o">.</span><span class="n">mark</span><span class="o">.</span><span class="n">mpl_image_compare</span>
<span class="k">def</span> <span class="nf">test_barbell</span><span class="p">():</span>
    <span class="n">fig</span> <span class="o">=</span> <span class="n">plt</span><span class="o">.</span><span class="n">figure</span><span class="p">()</span>
    <span class="n">barbell</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">barbell_graph</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="mi">6</span><span class="p">)</span>
    <span class="c1"># make sure to fix any randomness</span>
    <span class="n">pos</span> <span class="o">=</span> <span class="n">nx</span><span class="o">.</span><span class="n">spring_layout</span><span class="p">(</span><span class="n">barbell</span><span class="p">,</span> <span class="n">seed</span><span class="o">=</span><span class="mi">42</span><span class="p">)</span>
    <span class="n">nx</span><span class="o">.</span><span class="n">draw</span><span class="p">(</span><span class="n">barbell</span><span class="p">,</span> <span class="n">pos</span><span class="o">=</span><span class="n">pos</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">fig</span>
</pre></div>
</div>
<p>Then create a baseline image to compare against later:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ pytest -k test_barbell --mpl-generate-path=networkx/drawing/tests/baseline
</pre></div>
</div>
<p>And test:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>$ pytest -k test_barbell --mpl
</pre></div>
</div>
</section>
</section>
<section id="documentation">
<h2>Documentation<a class="headerlink" href="#documentation" title="Permalink to this heading">#</a></h2>
<p>Building the documentation locally requires that the additional dependencies
specified in <code class="docutils literal notranslate"><span class="pre">requirements/doc.txt</span></code> be installed in your development
environment.</p>
<p>The documentation is built with <code class="docutils literal notranslate"><span class="pre">sphinx</span></code>. To build the documentation locally,
navigate to the <code class="docutils literal notranslate"><span class="pre">doc/</span></code> directory and:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">make</span> <span class="n">html</span>
</pre></div>
</div>
<p>This will generate both the reference documentation as well as the example
gallery. If you want to build the documentation <em>without</em> building the
gallery examples use:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="n">make</span> <span class="n">html</span><span class="o">-</span><span class="n">noplot</span>
</pre></div>
</div>
<p>The build products are stored in <code class="docutils literal notranslate"><span class="pre">doc/build/</span></code> and can be viewed directly.
For example, to view the built html, open <code class="docutils literal notranslate"><span class="pre">build/html/index.html</span></code>
in your preferred web browser.</p>
<section id="adding-examples">
<h3>Adding examples<a class="headerlink" href="#adding-examples" title="Permalink to this heading">#</a></h3>
<p>The gallery examples are managed by
<a class="reference external" href="https://sphinx-gallery.readthedocs.io/">sphinx-gallery</a>.
The source files for the example gallery are <code class="docutils literal notranslate"><span class="pre">.py</span></code> scripts in <code class="docutils literal notranslate"><span class="pre">examples/</span></code> 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.</p>
<p>Building the example gallery locally requires that the additional dependencies
in <code class="docutils literal notranslate"><span class="pre">requirements/example.txt</span></code> be installed in your development environment.</p>
<p>You can <strong>add a new</strong> plot by placing a new <code class="docutils literal notranslate"><span class="pre">.py</span></code> file in one of the directories inside the
<code class="docutils literal notranslate"><span class="pre">examples</span></code> directory of the repository. See the other examples to get an idea for the
format.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Gallery examples should start with <code class="docutils literal notranslate"><span class="pre">plot_</span></code>, e.g. <code class="docutils literal notranslate"><span class="pre">plot_new_example.py</span></code></p>
</div>
<p>General guidelines for making a good gallery plot:</p>
<ul class="simple">
<li><p>Examples should highlight a single feature/command.</p></li>
<li><p>Try to make the example as simple as possible.</p></li>
<li><p>Data needed by examples should be included in the same directory and the example script.</p></li>
<li><p>Add comments to explain things are aren’t obvious from reading the code.</p></li>
<li><p>Describe the feature that you’re showcasing and link to other relevant parts of the
documentation.</p></li>
</ul>
</section>
<section id="adding-references">
<h3>Adding References<a class="headerlink" href="#adding-references" title="Permalink to this heading">#</a></h3>
<p>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
<a class="reference external" href="https://en.wikipedia.org/wiki/The_Chicago_Manual_of_Style">Chicago Citation Style</a>.
The quickest way of generating citation in this style is
by searching for the paper on <a class="reference external" href="https://scholar.google.com/">Google Scholar</a> and clicking on
the <code class="docutils literal notranslate"><span class="pre">cite</span></code> button. It will pop up the citation of the paper in multiple formats, and copy the
<code class="docutils literal notranslate"><span class="pre">Chicago</span></code> style.</p>
<p>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.</p>
<p>An example of a reference:</p>
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="o">..</span> <span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="n">Cheong</span><span class="p">,</span> <span class="n">Se</span><span class="o">-</span><span class="n">Hang</span><span class="p">,</span> <span class="ow">and</span> <span class="n">Yain</span><span class="o">-</span><span class="n">Whar</span> <span class="n">Si</span><span class="o">.</span> <span class="s2">&quot;Force-directed algorithms for schematic drawings and</span>
<span class="n">placement</span><span class="p">:</span> <span class="n">A</span> <span class="n">survey</span><span class="o">.</span><span class="s2">&quot; Information Visualization 19, no. 1 (2020): 65-91.</span>
<span class="n">https</span><span class="p">:</span><span class="o">//</span><span class="n">doi</span><span class="o">.</span><span class="n">org</span><span class="o">/</span><span class="mf">10.1177</span><span class="o">%</span><span class="mi">2</span><span class="n">F1473871618821740</span>
</pre></div>
</div>
<p>If the resource is uploaded as a PDF/DOCX/PPT on the web (lecture notes, presentations) it is better
to use the <a class="reference external" href="https://web.archive.org/">wayback machine</a> 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.</p>
</section>
</section>
<section id="bugs">
<h2>Bugs<a class="headerlink" href="#bugs" title="Permalink to this heading">#</a></h2>
<p>Please <a class="reference external" href="https://github.com/networkx/networkx/issues">report bugs on GitHub</a>.</p>
</section>
<section id="policies">
<h2>Policies<a class="headerlink" href="#policies" title="Permalink to this heading">#</a></h2>
<p>All interactions with the project are subject to the
<a class="reference internal" href="code_of_conduct.html"><span class="doc">NetworkX code of conduct</span></a>.</p>
<p>We also follow these policies:</p>
<ul class="simple">
<li><p><a class="reference internal" href="deprecations.html"><span class="doc">NetworkX deprecation policy</span></a></p></li>
<li><p><a class="reference external" href="https://numpy.org/neps/nep-0029-deprecation_policy.html" title="(in NumPy Enhancement Proposals)"><span class="xref std std-doc">Python version support</span></a></p></li>
</ul>
</section>
</section>


            </article>
            
            
            
          </div>
          
          
          
            <div class="bd-sidebar-secondary bd-toc">
              
<div class="toc-item">
  
<form class="bd-search d-flex align-items-center" action="../search.html" method="get">
  <i class="fa-solid fa-magnifying-glass"></i>
  <input type="search" class="form-control" name="q" id="search-input" placeholder="Search the docs ..." aria-label="Search the docs ..." autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false">
  <span class="search-button__kbd-shortcut"><kbd class="kbd-shortcut__modifier">Ctrl</kbd>+<kbd>K</kbd></span>
</form>
</div>

<div class="toc-item">
  
<div class="tocsection onthispage">
    <i class="fa-solid fa-list"></i> On this page
</div>
<nav id="bd-toc-nav" class="page-toc">
    <ul class="visible nav section-nav flex-column">
 <li class="toc-h2 nav-item toc-entry">
  <a class="reference internal nav-link" href="#development-workflow">
   Development Workflow
  </a>
 </li>
 <li class="toc-h2 nav-item toc-entry">
  <a class="reference internal nav-link" href="#divergence-from-upstream-main">
   Divergence from
   <code class="docutils literal notranslate">
    <span class="pre">
     upstream
    </span>
    <span class="pre">
     main
    </span>
   </code>
  </a>
 </li>
 <li class="toc-h2 nav-item toc-entry">
  <a class="reference internal nav-link" href="#guidelines">
   Guidelines
  </a>
 </li>
 <li class="toc-h2 nav-item toc-entry">
  <a class="reference internal nav-link" href="#testing">
   Testing
  </a>
  <ul class="nav section-nav flex-column">
   <li class="toc-h3 nav-item toc-entry">
    <a class="reference internal nav-link" href="#adding-tests">
     Adding tests
    </a>
   </li>
   <li class="toc-h3 nav-item toc-entry">
    <a class="reference internal nav-link" href="#image-comparison">
     Image comparison
    </a>
   </li>
  </ul>
 </li>
 <li class="toc-h2 nav-item toc-entry">
  <a class="reference internal nav-link" href="#documentation">
   Documentation
  </a>
  <ul class="nav section-nav flex-column">
   <li class="toc-h3 nav-item toc-entry">
    <a class="reference internal nav-link" href="#adding-examples">
     Adding examples
    </a>
   </li>
   <li class="toc-h3 nav-item toc-entry">
    <a class="reference internal nav-link" href="#adding-references">
     Adding References
    </a>
   </li>
  </ul>
 </li>
 <li class="toc-h2 nav-item toc-entry">
  <a class="reference internal nav-link" href="#bugs">
   Bugs
  </a>
 </li>
 <li class="toc-h2 nav-item toc-entry">
  <a class="reference internal nav-link" href="#policies">
   Policies
  </a>
 </li>
</ul>

</nav>
</div>

<div class="toc-item">
  
</div>

            </div>
          
          
        </div>
        <footer class="bd-footer-content">
          <div class="bd-footer-content__inner">
            
          </div>
        </footer>
        
      </main>
    </div>
  </div>

  
    
  <!-- Scripts loaded after <body> so the DOM is not blocked -->
  <script src="../_static/scripts/bootstrap.js?digest=796348d33e8b1d947c94"></script>
<script src="../_static/scripts/pydata-sphinx-theme.js?digest=796348d33e8b1d947c94"></script>
 
  <footer class="bd-footer"><div class="bd-footer__inner container">
  
  <div class="footer-item">
    
<p class="copyright">

    &copy; Copyright 2004-2023, NetworkX Developers.<br>

</p>

  </div>
  
  <div class="footer-item">
    <p class="theme-version">
    Built with the
    <a href="https://pydata-sphinx-theme.readthedocs.io/en/stable/index.html">
        PyData Sphinx Theme
    </a>
    0.12.0.
</p>
  </div>
  
  <div class="footer-item">
    
<p class="sphinx-version">
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 5.2.3.<br>
</p>

  </div>
  
</div>
  </footer>
  </body>
</html>