@@ -19,14 +19,14 @@ enhancements, and ideas are welcome.
19
19
If you are brand new to *xarray * or open-source development, we recommend going
20
20
through the `GitHub "issues" tab <https://github.com/pydata/xarray/issues >`_
21
21
to find issues that interest you. There are a number of issues listed under
22
- `Documentation <https://github.com/pydata/xarray/issues?q=is%3Aissue+is%3Aopen+label%3Adocumentation >`_
22
+ `Documentation <https://github.com/pydata/xarray/labels/topic-documentation >`_
23
23
and `good first issue
24
- <https://github.com/pydata/xarray/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+ first+ issue%22 > `_
24
+ <https://github.com/pydata/xarray/labels/contrib-good- first- issue> `_
25
25
where you could start out. Once you've found an interesting issue, you can
26
26
return here to get your development environment setup.
27
27
28
28
Feel free to ask questions on the `mailing list
29
- <https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!forum /xarray> `_.
29
+ <https://groups.google.com/g /xarray> `_.
30
30
31
31
.. _contributing.bug_reports :
32
32
@@ -106,6 +106,12 @@ Getting started with Git
106
106
setting up your SSH key, and configuring git. All these steps need to be completed before
107
107
you can work seamlessly between your local repository and GitHub.
108
108
109
+ .. note ::
110
+
111
+ The following instructions assume you want to learn how to interact with github via the git command-line utility,
112
+ but contributors who are new to git may find it easier to use other tools instead such as
113
+ `Github Desktop <https://desktop.github.com/ >`_.
114
+
109
115
.. _contributing.forking :
110
116
111
117
Forking
@@ -122,17 +128,58 @@ want to clone your fork to your machine::
122
128
This creates the directory `xarray ` and connects your repository to
123
129
the upstream (main project) *xarray * repository.
124
130
131
+ Creating a branch
132
+ -----------------
133
+
134
+ You want your ``main `` branch to reflect only production-ready code, so create a
135
+ feature branch before making your changes. For example::
136
+
137
+ git branch shiny-new-feature
138
+ git checkout shiny-new-feature
139
+
140
+ The above can be simplified to::
141
+
142
+ git checkout -b shiny-new-feature
143
+
144
+ This changes your working directory to the shiny-new-feature branch. Keep any
145
+ changes in this branch specific to one bug or feature so it is clear
146
+ what the branch brings to *xarray *. You can have many "shiny-new-features"
147
+ and switch in between them using the ``git checkout `` command.
148
+
149
+ To update this branch, you need to retrieve the changes from the ``main `` branch::
150
+
151
+ git fetch upstream
152
+ git merge upstream/main
153
+
154
+ This will combine your commits with the latest *xarray * git ``main ``. If this
155
+ leads to merge conflicts, you must resolve these before submitting your pull
156
+ request. If you have uncommitted changes, you will need to ``git stash `` them
157
+ prior to updating. This will effectively store your changes, which can be
158
+ reapplied after updating.
159
+
125
160
.. _contributing.dev_env :
126
161
127
162
Creating a development environment
128
163
----------------------------------
129
164
130
- To test out code changes, you'll need to build *xarray * from source, which
165
+ To test out code changes locally , you'll need to build *xarray * from source, which
131
166
requires a Python environment. If you're making documentation changes, you can
132
167
skip to :ref: `contributing.documentation ` but you won't be able to build the
133
168
documentation locally before pushing your changes.
134
169
135
- .. _contributiong.dev_python :
170
+ .. note ::
171
+
172
+ For small changes, such as fixing a typo, you don't necessarily need to build and test xarray locally.
173
+ If you make your changes then :ref: `commit and push them to a new branch <contributing.changes >`,
174
+ xarray's automated :ref: `continuous integration tests <contributing.ci >` will run and check your code in various ways.
175
+ You can then try to fix these problems by committing and pushing more commits to the same branch.
176
+
177
+ You can also avoid building the documentation locally by instead :ref: `viewing the updated documentation via the CI <contributing.pr >`.
178
+
179
+ To speed up this feedback loop or for more complex development tasks you should build and test xarray locally.
180
+
181
+
182
+ .. _contributing.dev_python :
136
183
137
184
Creating a Python Environment
138
185
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -193,35 +240,6 @@ To return to your root environment::
193
240
194
241
See the full conda docs `here <http://conda.pydata.org/docs >`__.
195
242
196
- Creating a branch
197
- -----------------
198
-
199
- You want your ``main `` branch to reflect only production-ready code, so create a
200
- feature branch before making your changes. For example::
201
-
202
- git branch shiny-new-feature
203
- git checkout shiny-new-feature
204
-
205
- The above can be simplified to::
206
-
207
- git checkout -b shiny-new-feature
208
-
209
- This changes your working directory to the shiny-new-feature branch. Keep any
210
- changes in this branch specific to one bug or feature so it is clear
211
- what the branch brings to *xarray *. You can have many "shiny-new-features"
212
- and switch in between them using the ``git checkout `` command.
213
-
214
- To update this branch, you need to retrieve the changes from the ``main `` branch::
215
-
216
- git fetch upstream
217
- git merge upstream/main
218
-
219
- This will combine your commits with the latest *xarray * git ``main ``. If this
220
- leads to merge conflicts, you must resolve these before submitting your pull
221
- request. If you have uncommitted changes, you will need to ``git stash `` them
222
- prior to updating. This will effectively store your changes, which can be
223
- reapplied after updating.
224
-
225
243
.. _contributing.documentation :
226
244
227
245
Contributing to the documentation
@@ -302,6 +320,7 @@ Requirements
302
320
~~~~~~~~~~~~
303
321
Make sure to follow the instructions on :ref: `creating a development environment above <contributing.dev_env >`, but
304
322
to build the docs you need to use the environment file ``ci/requirements/doc.yml ``.
323
+ You should also use this environment and these steps if you want to view changes you've made to the docstrings.
305
324
306
325
.. code-block :: sh
307
326
@@ -312,7 +331,7 @@ to build the docs you need to use the environment file ``ci/requirements/doc.yml
312
331
# or with older versions of Anaconda:
313
332
source activate xarray-docs
314
333
315
- # Build and install xarray
334
+ # Build and install a local, editable version of xarray
316
335
pip install -e .
317
336
318
337
Building the documentation
@@ -323,7 +342,17 @@ To build the documentation run::
323
342
cd doc/
324
343
make html
325
344
326
- Then you can find the HTML output in the folder ``xarray/doc/_build/html/ ``.
345
+ Then you can find the HTML output files in the folder ``xarray/doc/_build/html/ ``.
346
+
347
+ To see what the documentation now looks like with your changes, you can view the HTML build locally by opening the files in your local browser.
348
+ For example, if you normally use Google Chrome as your browser, you could enter::
349
+
350
+ google-chrome _build/html/quick-overview.html
351
+
352
+ in the terminal, running from within the ``doc/ `` folder.
353
+ You should now see a new tab pop open in your local browser showing the ``quick-overview `` page of the documentation.
354
+ The different pages of this local build of the documentation are linked together,
355
+ so you can browse the whole documentation by following links the same way you would on the officially-hosted xarray docs site.
327
356
328
357
The first time you build the docs, it will take quite a while because it has to run
329
358
all the code examples and build all the generated docstring pages. In subsequent
@@ -362,14 +391,13 @@ Code Formatting
362
391
xarray uses several tools to ensure a consistent code format throughout the project:
363
392
364
393
- `Black <https://black.readthedocs.io/en/stable/ >`_ for standardized
365
- code formatting
394
+ code formatting,
366
395
- `blackdoc <https://blackdoc.readthedocs.io/en/stable/ >`_ for
367
- standardized code formatting in documentation
368
- - `Flake8 <http://flake8.pycqa.org/en/latest/ >`_ for general code quality
369
- - `isort <https://github.com/timothycrosley/isort >`_ for standardized order in imports.
370
- See also `flake8-isort <https://github.com/gforcada/flake8-isort >`_.
396
+ standardized code formatting in documentation,
397
+ - `ruff <https://github.com/charliermarsh/ruff/ >`_ for code quality checks and standardized order in imports
398
+ - `absolufy-imports <https://github.com/MarcoGorelli/absolufy-imports >`_ for absolute instead of relative imports from different files,
371
399
- `mypy <http://mypy-lang.org/ >`_ for static type checking on `type hints
372
- <https://docs.python.org/3/library/typing.html> `_
400
+ <https://docs.python.org/3/library/typing.html> `_.
373
401
374
402
We highly recommend that you setup `pre-commit hooks <https://pre-commit.com/ >`_
375
403
to automatically run all the above tools every time you make a git commit. This
@@ -418,7 +446,7 @@ of xarray, and for developers of other libraries that depend on xarray.
418
446
Testing With Continuous Integration
419
447
-----------------------------------
420
448
421
- The *xarray * test suite runs automatically the
449
+ The *xarray * test suite runs automatically via the
422
450
`GitHub Actions <https://docs.github.com/en/free-pro-team@latest/actions >`__,
423
451
continuous integration service, once your pull request is submitted.
424
452
@@ -480,7 +508,7 @@ the expected correct result::
480
508
Transitioning to ``pytest ``
481
509
~~~~~~~~~~~~~~~~~~~~~~~~~~~
482
510
483
- *xarray * existing test structure is *mostly * classed based, meaning that you will
511
+ *xarray * existing test structure is *mostly * class- based, meaning that you will
484
512
typically find tests wrapped in a class.
485
513
486
514
.. code-block :: python
@@ -517,8 +545,6 @@ features that we like to use.
517
545
We would name this file ``test_cool_feature.py `` and put in an appropriate place in the
518
546
``xarray/tests/ `` structure.
519
547
520
- .. TODO: confirm that this actually works
521
-
522
548
.. code-block :: python
523
549
524
550
import pytest
@@ -569,26 +595,27 @@ A test run of this yields
569
595
570
596
.. code-block :: shell
571
597
572
- (( xarray) $ pytest test_cool_feature.py - v
573
- =============================== test session starts ================================
598
+ (( xarray) $ pytest test_cool_feature.py - v
599
+ ================================= test session starts == ================================
574
600
platform darwin -- Python 3 .10 .6 , pytest-7 .2 .0 , pluggy-1 .0 .0 --
575
601
cachedir: .pytest_cache
576
602
plugins: hypothesis-6 .56 .3 , cov-4 .0 .0
577
603
collected 11 items
578
604
579
- test_cool_feature.py::test_dtypes[int8 ] PASSED
580
- test_cool_feature.py::test_dtypes[int16 ] PASSED
581
- test_cool_feature.py::test_dtypes[int32 ] PASSED
582
- test_cool_feature.py::test_dtypes[int64 ] PASSED
583
- test_cool_feature.py::test_mark[float32 ] PASSED
584
- test_cool_feature.py::test_mark[int16 ] SKIPPED
585
- test_cool_feature.py::test_mark[int32 ] xfail
586
- test_cool_feature.py::test_series[int8 ] PASSED
587
- test_cool_feature.py::test_series[int16 ] PASSED
588
- test_cool_feature.py::test_series[int32 ] PASSED
589
- test_cool_feature.py::test_series[int64 ] PASSED
605
+ xarray/tests/test_cool_feature.py::test_dtypes[int8 ] PASSED [ 9 %]
606
+ xarray/tests/test_cool_feature.py::test_dtypes[int16 ] PASSED [ 18 %]
607
+ xarray/tests/test_cool_feature.py::test_dtypes[int32 ] PASSED [ 27 %]
608
+ xarray/tests/test_cool_feature.py::test_dtypes[int64 ] PASSED [ 36 %]
609
+ xarray/tests/test_cool_feature.py::test_mark[float32 ] PASSED [ 45 %]
610
+ xarray/tests/test_cool_feature.py::test_mark[int16 ] SKIPPED (unconditional skip) [ 54 %]
611
+ xarray/tests/test_cool_feature.py::test_mark[int32 ] XFAIL (to show how it works) [ 63 %]
612
+ xarray/tests/test_cool_feature.py::test_series[int8 ] PASSED [ 72 %]
613
+ xarray/tests/test_cool_feature.py::test_series[int16 ] PASSED [ 81 %]
614
+ xarray/tests/test_cool_feature.py::test_series[int32 ] PASSED [ 90 %]
615
+ xarray/tests/test_cool_feature.py::test_series[int64 ] PASSED [100 %]
616
+
590
617
591
- ================== 9 passed, 1 skipped, 1 xfailed in 1 .83 seconds ==================
618
+ ==================== 9 passed, 1 skipped, 1 xfailed in 1 .83 seconds == ==================
592
619
593
620
Tests that we have ``parametrized`` are now accessible via the test name, for
594
621
example we could run these with ``-k int8 `` to sub-select *only* those tests
@@ -598,10 +625,10 @@ which match ``int8``.
598
625
.. code-block:: shell
599
626
600
627
((xarray) bash-3 .2 $ pytest test_cool_feature.py -v -k int8
601
- =========================== test session starts ===========================
602
- platform darwin -- Python 3 .10 .6 , pytest-7 .2 .0 , pluggy-1 .0 .0 --
603
- cachedir: .pytest_cache
604
- plugins: hypothesis-6 .56 .3 , cov-4 .0 .0
628
+ ================================== test session starts ======= ===========================
629
+ platform darwin -- Python 3 .10 .6 , pytest-7 .2 .0 , pluggy-1 .0 .0 --
630
+ cachedir: .pytest_cache
631
+ plugins: hypothesis-6 .56 .3 , cov-4 .0 .0
605
632
collected 11 items
606
633
607
634
test_cool_feature.py::test_dtypes[int8 ] PASSED
@@ -728,9 +755,13 @@ If your code is an enhancement, it is most likely necessary to add usage
728
755
examples to the existing documentation. This can be done following the section
729
756
regarding documentation :ref:`above <contributing.documentation>`.
730
757
758
+ .. _contributing.changes:
759
+
731
760
Contributing your changes to *xarray*
732
761
=====================================
733
762
763
+ .. _contributing.committing:
764
+
734
765
Committing your code
735
766
--------------------
736
767
@@ -751,11 +782,11 @@ Doing 'git status' again should give something like::
751
782
# modified: /relative/path/to/file-you-added.py
752
783
#
753
784
754
- The following defines how a commit message should be structured:
785
+ The following defines how a commit message should ideally be structured:
755
786
756
- * A subject line with `< 72 ` chars.
757
- * One blank line.
758
- * Optionally, a commit message body.
787
+ * A subject line with `< 72 ` chars.
788
+ * One blank line.
789
+ * Optionally, a commit message body.
759
790
760
791
Please reference the relevant GitHub issues in your commit message using ``GH1234 `` or
761
792
``#1234 ``. Either style is fine, but the former is generally preferred.
@@ -764,6 +795,9 @@ Now you can commit your changes in your local repository::
764
795
765
796
git commit -m
766
797
798
+
799
+ .. _contributing.pushing:
800
+
767
801
Pushing your changes
768
802
--------------------
769
803
@@ -788,6 +822,8 @@ like::
788
822
Now your code is on GitHub, but it is not yet a part of the *xarray* project. For that to
789
823
happen, a pull request needs to be submitted on GitHub.
790
824
825
+ .. _contributing.review:
826
+
791
827
Review your code
792
828
----------------
793
829
@@ -802,6 +838,8 @@ double check your branch changes against the branch it was based on:
802
838
#. Select the ``base`` and ``compare`` branches, if necessary. This will be ``main`` and
803
839
``shiny-new-feature``, respectively.
804
840
841
+ .. _contributing.pr:
842
+
805
843
Finally, make the pull request
806
844
------------------------------
807
845
@@ -819,7 +857,16 @@ release. To submit a pull request:
819
857
#. Click ``Send Pull Request``.
820
858
821
859
This request then goes to the repository maintainers, and they will review
822
- the code. If you need to make more changes, you can make them in
860
+ the code.
861
+
862
+ If you have made updates to the documentation, you can now see a preview of the updated docs by clicking on "Details" under
863
+ the ``docs/readthedocs.org`` check near the bottom of the list of checks that run automatically when submitting a PR,
864
+ then clicking on the "View Docs" button on the right (not the big green button, the small black one further down).
865
+
866
+ .. image:: _static/view-docs.png
867
+
868
+
869
+ If you need to make more changes, you can make them in
823
870
your branch, add them to a new commit, push them to GitHub, and the pull request
824
871
will automatically be updated. Pushing them to GitHub again is done by::
825
872
@@ -829,6 +876,8 @@ This will automatically update your pull request with the latest code and restar
829
876
:ref:`Continuous Integration <contributing.ci>` tests.
830
877
831
878
879
+ .. _contributing.delete:
880
+
832
881
Delete your merged branch (optional)
833
882
------------------------------------
834
883
@@ -853,20 +902,22 @@ GitHub. To delete it there do::
853
902
git push origin --delete shiny-new-feature
854
903
855
904
905
+ .. _contributing.checklist:
906
+
856
907
PR checklist
857
908
------------
858
909
859
910
- ** Properly comment and document your code.** See `"Documenting your code" < https:// docs.xarray.dev/ en/ stable/ contributing.html#documenting- your- code> `_.
860
911
- ** Test that the documentation builds correctly** by typing ``make html`` in the ``doc`` directory. This is not strictly necessary, but this may be easier than waiting for CI to catch a mistake. See `"Contributing to the documentation" < https:// docs.xarray.dev/ en/ stable/ contributing.html#contributing- to- the- documentation> `_.
861
912
- ** Test your code** .
862
913
863
- - Write new tests if needed. See `"Test-driven development/code writing" <https://docs.xarray.dev/en/stable/contributing.html#test-driven-development-code-writing>`_.
864
- - Test the code using `Pytest <http://doc.pytest.org/en/latest/>`_. Running all tests (type ``pytest`` in the root directory) takes a while, so feel free to only run the tests you think are needed based on your PR (example: ``pytest xarray/tests/test_dataarray.py``). CI will catch any failing tests.
865
- - By default, the upstream dev CI is disabled on pull request and push events. You can override this behavior per commit by adding a <tt>[test-upstream]</tt> tag to the first line of the commit message. For documentation-only commits, you can skip the CI per commit by adding a "[skip-ci]" tag to the first line of the commit message.
914
+ - Write new tests if needed. See `"Test-driven development/code writing" <https://docs.xarray.dev/en/stable/contributing.html#test-driven-development-code-writing>`_.
915
+ - Test the code using `Pytest <http://doc.pytest.org/en/latest/>`_. Running all tests (type ``pytest`` in the root directory) takes a while, so feel free to only run the tests you think are needed based on your PR (example: ``pytest xarray/tests/test_dataarray.py``). CI will catch any failing tests.
916
+ - By default, the upstream dev CI is disabled on pull request and push events. You can override this behavior per commit by adding a <tt>[test-upstream]</tt> tag to the first line of the commit message. For documentation-only commits, you can skip the CI per commit by adding a "[skip-ci]" tag to the first line of the commit message.
866
917
867
918
- ** Properly format your code** and verify that it passes the formatting guidelines set by `Black < https:// black.readthedocs.io/ en/ stable/> `_ and `Flake8 < http:// flake8 .pycqa.org/ en/ latest/> `_. See `"Code formatting" < https:// docs.xarray.dev/ en/ stablcontributing.html#code- formatting> `_. You can use `pre- commit < https:// pre- commit.com/> `_ to run these automatically on each commit.
868
919
869
- - Run ``pre-commit run --all-files`` in the root directory. This may modify some files. Confirm and commit any formatting changes.
920
+ - Run ``pre-commit run --all-files`` in the root directory. This may modify some files. Confirm and commit any formatting changes.
870
921
871
- - ** Push your code and ** `create a PR on GitHub < https:// help.github.com/ en/ articles/ creating- a- pull- request> `_.
922
+ - ** Push your code** and `create a PR on GitHub < https:// help.github.com/ en/ articles/ creating- a- pull- request> `_.
872
923
- ** Use a helpful title for your pull request** by summarizing the main contributions rather than using the latest commit message. If the PR addresses an `issue < https:// github.com/ pydata/ xarray/ issues> `_, please `reference it < https:// help.github.com/ en/ articles/ autolinked- references- and- urls> `_.
0 commit comments