Debian Codegraph @

docs/development/index.rst

raw
1 ============
2 Contributing
3 ============
4
5
6 .. toctree::
7 :hidden:
8 :maxdepth: 2
9
10 Writing v2 Plugins <plugins>
11
12
13 Becoming a contributor can take as little as 2 minutes (e.g., via a small doc
14 PR) and doesn't require vast coding experience. We are open for contributions in
15 many ways and, if you would like to get involved but aren't sure where to start,
16 create a new issue and we will help you get started. In particular, we are also
17 extremely happy for any help with
18
19 - bugfixes,
20 - improving our documentation,
21 - improving our DevOp pipeline,
22 - improving the design of our website,
23 - new backends/plugins,
24 - and new features.
25
26 Check the relevant section below for a guide on how to get started in any of
27 these areas.
28
29
30 Small Changes to the Documentation
31 ----------------------------------
32
33 .. note::
34 A small documentation pull request includes changes that only affect a single
35 file. Examples include fixing typos or broken links, rewriting a paragraph for
36 clarity, or adding examples.
37
38 A small doc PR is very quick and doesn't require any local setup on your end.
39 All you need is a GitHub account. Here are the steps involved:
40
41 1. Navigate to the page you wish to improve.
42 2. Click on the "Edit this Page" button on the right side panel.
43 3. Make your changes to the file that opens.
44 4. At the bottom of the page under "Commit Changes" choose a descriptive commit
45 message (e.g., "fixed typo in examples").
46 5. Click the button "Propose Changes".
47 6. That's it. The ImageIO team thanks you for your contribution!
48
49
50 Large Changes to the Documentation
51 ----------------------------------
52
53 **Installation**
54
55 For large changes to the documentation, you will have to set up a local development
56 environment with the documentation dependencies installed::
57
58 # 1. Fork the ImageIO repository
59 # 2. If you want to use a virtual environment for your setup, create and activate it now.
60
61 git clone https://github.com/<replace_by_your_username>/imageio.git
62 cd imageio
63 pip install -e .[doc]
64
65 # create and checkout a new branch for your contribution
66 # Note: replace <branch_name> with a descriptive, but short, name
67 git checkout -b <branch_name>
68 git push --set-upstream origin <branch_name>
69
70 # building the docs locally on Linux or MacOS
71 # Note: to rebuild the docs, execute this line again
72 sphinx-build ./docs ./build
73
74 # building the docs locally on Windows
75 # Note: to rebuild the docs, execute this line again
76 sphinx-build .\docs .\build
77
78 **Developing the PR**
79
80 Next, you will have to add your modifications to the docs; remember to commit
81 frequently. You are welcome to reach out during this process if you want
82 feedback or have any doubts. Further, you may wish to create a draft PR with
83 your changes, so that we can discuss more easily.
84
85 We use sphinx to generate the website and the API has narrative docs.
86 Documentation of the actual functions is autogenerated using numpydoc, and is
87 linked to from the narrative API docs. Further, the list of supported formats,
88 too, is autogenerated using a custom sphinx extension (``imageio_ext.py``);
89 essentially, it parses the respective format RST files using jinja and inserts
90 the formats from ``imageio.config.known_extensions``.
91
92 **Submitting the PR**
93
94 Once you are happy with your changes, push your changes to your local fork, head
95 over to the `main repo <https://github.com/imageio/imageio>`_ and create a new
96 PR. In the description, briefly summarize what the changes are about (there is
97 no fixed format). If we discussed them before in an issue, add a reference to
98 that issue, so that we can track it. From there, we will help you by reviewing
99 your changes, discussing any changes and eventually merging your work into
100 ImageIO.
101
102 Thank you for contributing!
103
104
105 Fixing a Bug
106 ------------
107
108 .. note::
109 We currently don't have a dedicated maintainer that uses MacOS as their
110 primary development platform. If you would like to suggest yourself,
111 please get in touch, e.g., via a new issue.
112
113 The first step to fixing a bug is to open a new issue that describes the bug
114 (ideally including a
115 [mwe](https://en.wikipedia.org/wiki/Minimal_working_example)) to discuss where
116 the fix should live. Alternatively, if an issue already exists, leave a comment
117 to let us know you want to work on it.
118
119 In general, a bugfix follows the usual open-source routine. Here is a rough
120 outline::
121
122 # Fork the ImageIO repository
123
124 git clone https://github.com/<replace_by_fork_location>/imageio.git
125 cd imageio
126
127 # Note: replace <plugin_name> with the plugin that has the bug to
128 # install optional dependencies
129 pip install -e .[dev,<plugin_name>]
130
131 # Note: replace <branch_name> with a descriptive, but short, name
132 git checkout -b <branch_name>
133 git push --set-upstream origin <branch_name>
134
135 pytest # run the existing test suite to verify install
136
137 # Add a unit test that reproduces the faulty behavior
138
139 # Apply the changes to fix the bug. Remember to commit frequently.
140
141 # check if your changes are covered by tests
142 coverage run -m pytest
143 coverage report -m
144
145 # If changes are not fully covered, add test(s) to cover the
146 # missing branches.
147
148 # Submit a PR. In the description, reference the abovementioned
149 # issue and give a brief description of the changes.
150
151 Thank you for contributing!
152
153
154 Adding a new Feature
155 --------------------
156
157 .. note::
158 We currently don't have a dedicated maintainer that uses MacOS as their
159 primary development platform. If you would like to suggest yourself,
160 please get in touch, e.g., via a new issue.
161
162 The first step to contributing a new feature is to open a new issue on our issue
163 page so we can discuss how the feature should look like, if it can work with
164 the relevant backends, and fits within the scope of the library.
165
166 Once that is out of the way, the procedure usually follows the following steps::
167
168 # Fork the ImageIO repository
169
170 git clone https://github.com/<replace_by_fork_location>/imageio.git
171 cd imageio
172
173 # Note: replace <plugin_name> with the plugin that has the bug to
174 # install optional dependencies
175 pip install -e .[dev,<plugin_name>]
176
177 # Note: replace <branch_name> with a descriptive, but short, name
178 git checkout -b <branch_name>
179 git push --set-upstream origin <branch_name>
180
181 pytest # run the existing test suite to verify install
182
183 # Add the desired/discussed functionality
184
185 # For each new function you've created add a descriptive docstring
186 # compliant with numpydoc
187
188 # Add an example to ``docs/examples.rst`` showing off the new
189 # feature
190
191 # Add unit tests to verify that the feature does what it is
192 # intended to do
193
194 # check if your changes are covered by tests
195 coverage run -m pytest
196 coverage report -m
197
198 # If changes are not fully covered, add test(s) to cover the
199 # missing branches.
200
201 # Submit a PR. In the description, reference the feature issue and
202 # give a brief description of the changes.
203
204 Thank you for contributing!
205
206
207 Webdesign
208 ---------
209
210 .. warning::
211 We currently don't have a dedicated maintainer for this area. If you would
212 like to suggest yourself, please get in touch, e.g., via a new issue.
213
214 There is currently no established way of suggestion webdesign related changes.
215 If you have any suggestions regarding
216
217 - the structure/layout of the docs
218 - improvements of the template or its config
219 - styling of the website
220 - (other webdesign related items)
221
222 Please open a new issue and we will discuss with you.
223
224
225 DevOps
226 ------
227
228 Before you go and improve our tooling, please start by first opening a new issue
229 and discussing your idea with us. We ask this, because we want to make sure that
230 there is at least one maintainer familiar with the technology you want to use.
231 If anything breaks in the CI/CD pipeline, it will have a direct impact on our
232 release cycle, and we would like to make sure that at least one maintainer is
233 able to step in and fix it in a timely fashion.
234
235 **Installation**
236
237 While you may be able to complete some devops related contributions in GitHub itself,
238 a local setup will perform better in most situations::
239
240 # 1. Fork the ImageIO repository
241
242 git clone https://github.com/<replace_by_your_username>/imageio.git
243 cd imageio
244 pip install -e .
245
246 # create and checkout a new branch for your contribution
247 # Note: replace <branch_name> with a descriptive, but short, name
248 git checkout -b <branch_name>
249 git push --set-upstream origin <branch_name>
250
251 **Developing the PR**
252
253 Do your changes, and remember to commit frequently. If you want to test your
254 changes against our CI/CD provider (GH Actions), you can submit a draft PR,
255 which we will review and run. Alternatively, you configure your local fork to
256 execute actions and develop against it. You can find our workflows in the
257 ``.github`` folder.
258
259 *Continuous Integration (CI)*: The core of our CI is a matrix test across all
260 major OSes and supported python versions running a testsuite based on
261 ``pytest``. Additionally, we track linting errors (black + flake8), coverage
262 (codecov), and have readthedocs build a preview of the documentation.
263
264 *Continuous Deployment (CD)*: Our continuous deployment pipeline checks weekly
265 (Monday night, EU time) for any changes to the repository. If there are any, it
266 uses python-semantic-release to figure out if the version should bump and a new
267 release should be made. If so, all tests are run against the master branch, the
268 version is bumped, and a new release is made and published to GitHub and PyPI.
269 Further, we have a feedstock on conda-forge which manages releases to conda.
270
271 **Submitting the PR**
272
273 Once you are happy with your changes, push your changes to your local fork, head
274 over to the `main repo <https://github.com/imageio/imageio>`_ and create a new
275 PR. In the description, briefly summarize what the changes are about (there is
276 no fixed format) and add a reference to the issue in which we discussed them.
277 From there, we will help you by reviewing your changes, discussing them and
278 eventually merging your work into ImageIO.
279
280 Thank you for contributing!
281
282
283 Implementing a new Plugin
284 -------------------------
285
286 Plugins allow integration of a new backends into ImageIO. They can
287 exist independently of ImageIO; however, we encourage you to contribute any
288 plugins back upstream. This way others, too, can benefit from using the new
289 backend and you will get compatibility guarantees by virtue of the backend
290 becoming part of our test suite.
291
292 .. note::
293
294 These instructions assume that you indeed wish to contribute the plugin.
295
296 If you don't, then you won't need a dev installation of ImageIO and can
297 write the plugin directly. In this case, you will have to pass the plugin
298 class to API calls using the plugin kwarg. For example::
299
300 import imageio as iio
301 from my_plugin import PluginClass
302
303 iio.imread(ImageResource, plugin=PluginClass)
304
305 **Installation**
306
307 To develop a new plugin, you can start off with a simple dev install::
308
309 # 1. Fork the ImageIO repository
310
311 git clone https://github.com/<replace_by_your_username>/imageio.git
312 cd imageio
313 pip install -e .[dev]
314
315 # create and checkout a new branch for your contribution
316 # Note: replace <branch_name> with a descriptive, but short, name
317 git checkout -b <branch_name>
318 git push --set-upstream origin <branch_name>
319
320 # verify installation
321 pytest
322
323 **Develop the Plugin**
324
325 To write a new plugin, you have to create a new class that follows our plugin
326 API, which is documented below:
327
328 **v2 plugin docs**
329
330 .. autosummary::
331
332 imageio.plugins
333
334 **v3 plugin docs**
335
336 .. autosummary::
337 :template: better_class.rst
338 :toctree: ../_autosummary
339
340 imageio.core.v3_plugin_api.PluginV3
341 imageio.core.v3_plugin_api.ImageProperties
342
343 The file itself should be placed into our plugins folder at
344 ``imageio\plugins\your_plugin.py``.
345
346 **Declare Dependencies**
347
348 Plugins typically have at least one external dependency: the backend they use to
349 do the decoding/encoding. This dependency (and any others a plugin may have)
350 have to be declared in our ``setup.py``.
351
352 All plugins start out as optional dependencies (but may be promoted if they turn
353 out stable and useful ;) ). As such, to declare dependencies of a plugin add an
354 item to the extra_requires dict. The key name typically matches the name of the
355 backend, and the value is a list of dependencies::
356
357 extras_require = {
358 # ...
359 "my_backend": ["my_backend", ...],
360 }
361
362 That said, a plugin can assume that its dependencies are installed, i.e., it
363 doesn't have to explicitly assert that imports resolve. We catch any ImportError
364 internally and use it to inform the user that they have to install missing
365 dependencies via::
366
367 pip install imageio[my_backend]
368
369 **Register the Plugin**
370
371 Registering the plugin with ImageIO enables various kinds of auto-magic. Currently
372 this involves two steps:
373
374 1. Register the plugin as a known_plugin
375 2. Associate supported extensions with the plugin
376
377 First, add the plugin to the list of known plugins. This allows ImageIO to try
378 the plugin in case no better suited one can be found and also enables all other
379 optimizations. For this, add a new item to the dict in
380 ``imageio.config.plugins.py``. The key is the name under which the plugin will
381 be known (usually the name of the backend) and the value is an instance of
382 ``PluginConfig``, for example::
383
384 known_plugins["my_plugin"] = PluginConfig(
385 name="my_plugin", # (same as key)
386 class_name="MyPluginClass", # the name of the class
387 module_name="imageio.plugins.my_plugin" # where the class is implemented
388 is_legacy: bool = True, # True if plugin follows V2 API
389 install_name: str = "my_backend", # name of the optional dependency
390 )
391
392 For more details on the PluginConfig class, check the classes docstring.
393
394 Second, if the plugin adds support for any new formats that were not previously
395 supported by ImageIO, declare those formats in ``imageio.config.extensions.py``.
396 For this, add items to the ``extension_list``; items are instances of the
397 ``FileExtension`` class::
398
399 FileExtension(
400 name="Full Name of Format",
401 extension=".file_extension", # e.g. ".png"
402 priority=["my_plugin"], # a list of plugins that supports reading this format
403 ),
404
405 Plugins listed in ``priority`` are assumed to be able to read the declared
406 format. Further, ImageIO will prefer plugins that appear earlier over plugins
407 that appear later in the list, i.e., they are tried first.
408
409 Finally, for each format that is already supported by other plugins, add the new plugin
410 at the end of the ``priority`` list. (This avoids breaking existing downstream code.)
411
412
413 **Document the Plugin**
414
415 .. code-block::
416
417 # build the docs
418 sphinx-build ./docs ./build # MacOS / Linux
419 sphinx-build .\docs .\build # Windows
420
421 Beyond the plugin itself, you will have to write documentation for it that tells
422 others what features are available and how to use it. In ImageIO classes are
423 documented using numpydoc, so they should follow numpy's documentation style.
424 Most importantly, you will have to add a module docstring to the plugin file
425 (check the other plugins for examples), which will be used as the entrypoint for
426 your plugin's documentation.
427
428 Once you have written something, hook the documentation into our docs. For this
429 add it's import path (imageio.plugins.your_module_name) in
430 ``docs\reference\index.rst``. It should be inside the autosummary block that
431 lists all plugins.
432
433
434 **Test the Plugin**
435
436 .. code-block::
437
438 # run tests
439 pytest # run all
440 pytest path/to/test/file.py # run specific module
441 pytest path/to/test/file.py::test_name_of_test # run specific test
442
443 # check coverage
444 coverage run -m pytest # update the coverage logs
445 coverage report -m # report coverage in shell
446
447 To test your plugin, create a new test file at ``tests\test_myplugin.py``. In
448 the file, define functions that have their name begin with ``test_`` (example:
449 ``def test_png_reading():``) and fill them with code that uses your plugin.
450
451 Our main requirement for tests of new plugins is that they cover the full
452 plugin. Ideally, they also test reading and writing of all supported formats,
453 but this is not strictly necessary. Check the commands above for how to run
454 tests and check test coverage of your plugin.
455
456
457 **Submitting the PR**
458
459 Once you are happy with the plugin, push your changes to your local fork, head
460 over to the `main repo <https://github.com/imageio/imageio>`_ and create a new
461 PR. In the description, briefly summarize what the plugin does (there is no
462 fixed format) and, if it exists, add a reference to the issue in which the
463 plugin is discussed. From there, we will help you by reviewing your changes,
464 discussing them and eventually merging your plugin into ImageIO.
465
466 Thank you for contributing!
467
468
469 Adding a missing Format
470 -----------------------
471
472 Adding a new format (or updating an existing one) can be done directly in
473 GitHub. Navigate to [this
474 page](https://github.com/imageio/imageio/blob/master/imageio/config/extensions.py)
475 and click on the "edit this file" button (looks like a pen). From here,
476 either edit the existing format, e.g., by adding a new backend that supports it in ``priority``,
477 or by add a new format. For this add this snippet to the bottom of the ``extension_list``::
478
479 FileExtension(
480 name="<Full Name of File Format>", # e.g., Hasselblad raw
481 extension="<extension>", # e.g., .3fr
482 priority=<list of supporting backend names>, # e.g., ["RAW-FI"]
483 )
484
485 Thank you for contributing!
486
487 Full Developer Setup
488 --------------------
489
490 .. note::
491 This section is intended for library maintainers and people that plan to make
492 multiple contributions of various kinds.
493
494 If you plan to make a series of contributions, we recommend a development
495 installation with all plugins::
496
497 # 1. Fork the ImageIO repository
498 # 2. Optional: Create and activate your virtual environment of choice
499
500 # install
501 git clone https://github.com/<replace_by_fork_location>/imageio.git
502 cd imageio
503 pip install -e .[full]
504
505 # download test images and run all tests
506 pytest
507
508 # build the docs
509 sphinx-build ./docs ./build # MacOS / Linux
510 sphinx-build .\docs .\build # Windows
511
512 # check coverage
513 coverage run -m pytest # update the coverage logs
514 coverage report -m # report coverage in shell