Debian Codegraph @

docs/source/develop.rst

raw
1 Development Guidelines
2 ======================
3
4 Dask is a community maintained project. We welcome contributions in the form
5 of bug reports, documentation, code, design proposals, and more.
6 This page provides resources on how best to contribute.
7
8 .. note:: Dask strives to be a welcoming community of individuals with diverse
9 backgrounds. For more information on our values, please see our
10 `code of conduct
11 <https://github.com/dask/governance/blob/main/code-of-conduct.md>`_
12 and
13 `diversity statement <https://github.com/dask/governance/blob/main/diversity.md>`_
14
15 Where to ask for help
16 ---------------------
17
18 Dask conversation happens in the following places:
19
20 #. `Dask Discourse forum`_: for usage questions and general discussion
21 #. `Stack Overflow #dask tag`_: for usage questions
22 #. `GitHub Issue Tracker`_: for discussions around new features or established bugs
23 #. `Dask Community Slack`_: for real-time discussion
24
25 For usage questions and bug reports we prefer the use of Discourse, Stack Overflow
26 and GitHub issues over Slack chat. Discourse, GitHub and Stack Overflow are more easily
27 searchable by future users, so conversations had there can be useful to many more people
28 than just those directly involved.
29
30 .. _`Dask Discourse forum`: https://dask.discourse.group
31 .. _`Stack Overflow #dask tag`: https://stackoverflow.com/questions/tagged/dask
32 .. _`GitHub Issue Tracker`: https://github.com/dask/dask/issues/
33 .. _`Dask Community Slack`: https://join.slack.com/t/dask/shared_invite/zt-mfmh7quc-nIrXL6ocgiUH2haLYA914g
34
35
36 Separate Code Repositories
37 --------------------------
38
39 Dask maintains code and documentation in a few git repositories hosted on the
40 GitHub ``dask`` organization, https://github.com/dask. This includes the primary
41 repository and several other repositories for different components. A
42 non-exhaustive list follows:
43
44 * https://github.com/dask/dask: The main code repository holding parallel
45 algorithms, the single-machine scheduler, and most documentation
46 * https://github.com/dask/distributed: The distributed memory scheduler
47 * https://github.com/dask/dask-ml: Machine learning algorithms
48 * https://github.com/dask/s3fs: S3 Filesystem interface
49 * https://github.com/dask/gcsfs: GCS Filesystem interface
50 * https://github.com/dask/hdfs3: Hadoop Filesystem interface
51 * ...
52
53 Git and GitHub can be challenging at first. Fortunately good materials exist
54 on the internet. Rather than repeat these materials here, we refer you to
55 pandas' documentation and links on this subject at
56 https://pandas.pydata.org/docs/dev/development/contributing.html
57
58
59 Issues
60 ------
61
62 The community discusses and tracks known bugs and potential features in the
63 `GitHub Issue Tracker`_. If you have a new idea or have identified a bug, then
64 you should raise it there to start public discussion.
65
66 If you are looking for an introductory issue to get started with development,
67 then check out the `"good first issue" label`_, which contains issues that are good
68 for starting developers. Generally, familiarity with Python, NumPy, pandas, and
69 some parallel computing are assumed.
70
71 .. _`"good first issue" label`: https://github.com/dask/dask/labels/good%20first%20issue
72
73
74 Development Environment
75 -----------------------
76
77 Download code
78 ~~~~~~~~~~~~~
79
80 Make a fork of the main `Dask repository <https://github.com/dask/dask>`_ and
81 clone the fork::
82
83 git clone https://github.com/<your-github-username>/dask.git
84 cd dask
85
86 You should also pull the latest git tags (this ensures ``pip``'s dependency resolver
87 can successfully install Dask)::
88
89 git remote add upstream https://github.com/dask/dask.git
90 git pull upstream main --tags
91
92 Contributions to Dask can then be made by submitting pull requests on GitHub.
93
94 .. _develop-install:
95
96 Install
97 ~~~~~~~
98
99 From the top level of your cloned Dask repository you can install a
100 local version of Dask, along with all necessary dependencies, using
101 pip or conda_
102
103 .. _conda: https://conda.io/
104
105 ``pip``::
106
107 python -m pip install -e ".[complete,test]"
108
109 ``conda``::
110
111 conda env create -n dask-dev -f continuous_integration/environment-3.12.yaml
112 conda activate dask-dev
113 python -m pip install --no-deps -e .
114
115
116 Run Tests
117 ~~~~~~~~~
118
119 Dask uses py.test_ for testing. You can run tests from the main dask directory
120 as follows::
121
122 py.test dask --verbose --doctest-modules
123
124 .. _py.test: https://docs.pytest.org/en/latest/
125
126
127 Contributing to Code
128 --------------------
129
130 Dask maintains development standards that are similar to most PyData projects. These standards include
131 language support, testing, documentation, and style.
132
133 Python Versions
134 ~~~~~~~~~~~~~~~
135
136 Dask supports Python versions 3.9 to 3.12.
137 Name changes are handled by the :file:`dask/compatibility.py` file.
138
139 .. _develop-test:
140
141 Test
142 ~~~~
143
144 Dask employs extensive unit tests to ensure correctness of code both for today
145 and for the future. Test coverage is expected for all code contributions.
146
147 Tests are written in a py.test style with bare functions:
148
149 .. code-block:: python
150
151 def test_fibonacci():
152 assert fib(0) == 0
153 assert fib(1) == 0
154 assert fib(10) == 55
155 assert fib(8) == fib(7) + fib(6)
156
157 for x in [-3, 'cat', 1.5]:
158 with pytest.raises(ValueError):
159 fib(x)
160
161 These tests should compromise well between covering all branches and fail cases
162 and running quickly (slow test suites get run less often).
163
164 You can run tests locally by running ``py.test`` in the local dask directory::
165
166 py.test dask
167
168 You can also test certain modules or individual tests for faster response::
169
170 py.test dask/dataframe
171
172 py.test dask/dataframe/tests/test_dataframe.py::test_rename_index
173
174 If you want the tests to run faster, you can run them in parallel using
175 ``pytest-xdist``::
176
177 py.test dask -n auto
178
179 Tests run automatically on GitHub Actions on every push to every pull
180 request on GitHub.
181
182 Tests are organized within the various modules' subdirectories::
183
184 dask/array/tests/test_*.py
185 dask/bag/tests/test_*.py
186 dask/bytes/tests/test_*.py
187 dask/dataframe/tests/test_*.py
188 dask/diagnostics/tests/test_*.py
189
190 For the Dask collections like Dask Array and Dask DataFrame, behavior is
191 typically tested directly against the NumPy or pandas libraries using the
192 ``assert_eq`` functions:
193
194 .. code-block:: python
195
196 import numpy as np
197 import dask.array as da
198 from dask.array.utils import assert_eq
199
200 def test_aggregations():
201 rng = np.random.default_rng()
202 nx = rng.random(100)
203 dx = da.from_array(nx, chunks=(10,))
204
205 assert_eq(nx.sum(), dx.sum())
206 assert_eq(nx.min(), dx.min())
207 assert_eq(nx.max(), dx.max())
208 ...
209
210 This technique helps to ensure compatibility with upstream libraries and tends
211 to be simpler than testing correctness directly. Additionally, by passing Dask
212 collections directly to the ``assert_eq`` function rather than call compute
213 manually, the testing suite is able to run a number of checks on the lazy
214 collections themselves.
215
216
217 Docstrings
218 ~~~~~~~~~~
219
220 User facing functions should roughly follow the numpydoc_ standard, including
221 sections for ``Parameters``, ``Examples``, and general explanatory prose.
222
223 By default, examples will be doc-tested. Reproducible examples in documentation
224 is valuable both for testing and, more importantly, for communication of common
225 usage to the user. Documentation trumps testing in this case and clear
226 examples should take precedence over using the docstring as testing space.
227 To skip a test in the examples add the comment ``# doctest: +SKIP`` directly
228 after the line.
229
230 .. code-block:: python
231
232 def fib(i):
233 """ A single line with a brief explanation
234
235 A more thorough description of the function, consisting of multiple
236 lines or paragraphs.
237
238 Parameters
239 ----------
240 i: int
241 A short description of the argument if not immediately clear
242
243 Examples
244 --------
245 >>> fib(4)
246 3
247 >>> fib(5)
248 5
249 >>> fib(6)
250 8
251 >>> fib(-1) # Robust to bad inputs
252 ValueError(...)
253 """
254
255 .. _numpydoc: https://numpydoc.readthedocs.io/en/latest/format.html#docstring-standard
256
257 Docstrings are tested under Python 3.12 on GitHub Actions. You can test
258 docstrings with pytest as follows::
259
260 py.test dask --doctest-modules
261
262 Docstring testing requires ``graphviz`` to be installed. This can be done via::
263
264 conda install -y graphviz
265
266
267 Code Formatting
268 ~~~~~~~~~~~~~~~
269
270 Dask uses several code linters (flake8, black, isort, pyupgrade, mypy), which are
271 enforced by CI. Developers should run them locally before they submit a PR, through the
272 single command ``pre-commit run --all-files``. This makes sure that linter versions and
273 options are aligned for all developers.
274
275 Optionally, you may wish to setup the `pre-commit hooks <https://pre-commit.com/>`_ to
276 run automatically when you make a git commit. This can be done by running::
277
278 pre-commit install
279
280 from the root of the Dask repository. Now the code linters will be run each time you
281 commit changes. You can skip these checks with ``git commit --no-verify`` or with the
282 short version ``git commit -n``.
283
284
285 Contributing to Documentation
286 -----------------------------
287
288 Dask uses Sphinx_ for documentation, hosted on https://readthedocs.org .
289 Documentation is maintained in the RestructuredText markup language (``.rst``
290 files) in ``dask/docs/source``. The documentation consists both of prose
291 and API documentation.
292
293 The documentation is automatically built, and a live preview is available,
294 for each pull request submitted to Dask. Additionally, you may also
295 build the documentation yourself locally by following the instructions outlined
296 below.
297
298 How to build the Dask documentation
299 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
300
301 To build the documentation locally, make a fork of the main
302 `Dask repository <https://github.com/dask/dask>`_, clone the fork::
303
304 git clone https://github.com/<your-github-username>/dask.git
305 cd dask/docs
306
307 Install the packages in ``requirements-docs.txt``.
308
309 Optionally create and activate a ``conda`` environment first::
310
311 conda create -n daskdocs -c conda-forge python=3.8
312 conda activate daskdocs
313
314 Install the dependencies with ``pip``::
315
316 python -m pip install -r requirements-docs.txt
317
318 Then build the documentation with ``make``::
319
320 make html
321
322 The resulting HTML files end up in the ``build/html`` directory.
323
324 You can now make edits to rst files and run ``make html`` again to update
325 the affected pages.
326
327
328 Dask CI Infrastructure
329 ----------------------
330
331 Github Actions
332 ~~~~~~~~~~~~~~
333
334 Dask uses Github Actions for Continuous Integration (CI) testing for each PR.
335 These CI builds will run the test suite across a variety of Python versions, operating
336 systems, and package dependency versions. Additionally, if a commit message
337 includes the phrase ``test-upstream``, then an additional CI build will be
338 triggered which uses the development versions of several dependencies
339 including: NumPy, pandas, fsspec, etc.
340
341 The CI workflows for Github Actions are defined in
342 `.github/workflows <https://github.com/dask/dask/tree/main/.github/workflows>`_
343 with additional scripts and metadata located in `continuous_integration
344 <https://github.com/dask/dask/tree/main/continuous_integration>`_
345
346
347 .. _Sphinx: https://www.sphinx-doc.org/