Skip to content

Modernizing the docs - #648

Merged
almarklein merged 88 commits into
imageio:masterfrom
FirefoxMetzger:new_api_docs
Sep 6, 2021
Merged

almarklein merged 88 commits into
imageio:masterfrom
FirefoxMetzger:new_api_docs

Conversation

@FirefoxMetzger

@FirefoxMetzger FirefoxMetzger commented Jun 16, 2021 •

Copy link
Copy Markdown
Contributor

Closes #621

I am going to write the docs for the new API and some use-case examples.

I wanted to write the docs, but now I am thinking it is easier to clean up and modernize the docs a bit in this PR and then make a dedicated one that adds new content.

We didn't discuss it beforehand @almarklein , but what do you think about switching to the pydata theme for our docs? I like its clean and modern appearance.

This PR adds the following to the docs:

  • new theme (RTD -> pydata)
  • reorganize top menu following a more standard layout: install/examples/API reference. This is based on comparison with scipy, pydata, skimage, numpy and seaborn.
  • reorganized the file structure in the docs to reflect top level menus (there were too many files in the same folder to stay organized)
  • split dev install and normal install (mainly: move all dev stuff into "development")
  • add an overview page to Getting Started (this is the terminology comment we had in new public API #574 )
  • explicitly reference drop27 in the toctree of Getting Started (address the warning we had before)
  • split the API docs into core (imread/mimread/volread) and backends (one page per backend for backend specific docs; mainly applicable kwargs)
  • add three examples to the example list for iterating files in a folder, iterating files in a .zip and reading single files from a zip.
  • add a Requests page to the docs (describe which kind of URIs are supported
  • link the backend reference pages via autosummary
  • specify the ffmpeg version needed
  • depreciate parts of our custom plugin in flavor of using autosummary for generation

Once all the boxes above are ticked, this PR is ready for review.

@FirefoxMetzger

Copy link
Copy Markdown
Contributor Author

Not entirely sure how I feel about the edit button ...

@FirefoxMetzger

Copy link
Copy Markdown
Contributor Author

@almarklein Was there any reason for disabling autosummary in favor of a homebrew version of it?

@FirefoxMetzger FirefoxMetzger changed the title Documentation for the new API Modernizing the docs Jun 17, 2021
@FirefoxMetzger FirefoxMetzger linked an issue Jun 19, 2021 that may be closed by this pull request
@FirefoxMetzger FirefoxMetzger linked an issue Jun 19, 2021 that may be closed by this pull request
@almarklein

Copy link
Copy Markdown
Member

what do you think about switching to the pydata theme for our docs? I

Sounds good!

Was there any reason for disabling autosummary in favor of a homebrew version of it?

Can't remember. Let's run with autosummary. Worst case we find out why :)

@FirefoxMetzger
FirefoxMetzger marked this pull request as ready for review June 21, 2021 10:06
@FirefoxMetzger
FirefoxMetzger marked this pull request as draft June 21, 2021 10:06
@FirefoxMetzger
FirefoxMetzger marked this pull request as ready for review July 15, 2021 07:21
@FirefoxMetzger

Copy link
Copy Markdown
Contributor Author

A little bit larger than originally anticipated, but I think it is worth cleaning stuff up a little ... and most parts are just copy/pasting docstrings around to align the doc layout a bit more with other familiar python libraries (scipy, numpy, pandas, ...)

Comment thread docs/supported_formats.rst Outdated
Comment on lines +16 to +18
Format List
-----------
Each backend listed here is listed using the format string you would use to call

@almarklein almarklein Jul 15, 2021 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this file still auto-generated? I see code-gen code being removed, but no new code to replace it. I hope it's not a manual document, because I suspect that will be painful to maintain. (*edited to add "not")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You hope it's a manual document or you hope its not a manual document? But to answer your question either way: At the moment it is a manual document.

Moving forward, I think it will become a little easier, since a lot of the formats are XXX-FI or XXX-PIL, and in the new API all of these will become plugin="freeimage" or plugin="pillow", at which point we could think of removing the Format List (by extension) and just keep a format list by backend and ask people to Ctrl+F the extension they are looking for. Then again it might be nice to have a long list of extensions/formats, because it looks impressive.

@FirefoxMetzger FirefoxMetzger Jul 15, 2021 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, and some of the codegen is now covered by autosummary/autodoc. I also removed all the template strings from the extension and placed them into dedicated template files.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I meant not a manual document, sorry.

[...] in the new API all of these will become plugin="freeimage" or plugin="pillow".

mmm what would that look like? I imagine that many formats still have their own specific keyword argument (e.g. compression for png, exif rotation for jpg, etc, etc.).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In either case, this list seems like it's easy to generate from the information that is already available. It being manual will mean having to keep things in sync, and discrepancies will creep in at some point.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you were/are wondering how it will look like on the documentation side then that will depend on the individual plugin/backend.

Yes, I was wondering mostly about the docs. Ok, I think I see what you mean. So the Pillow plugin will be a relatively large page describing the parameters for generic formats, and a few sections for png, jpg, etc.? I hadn't thought about that, but it sounds good. Would be nice, though, if the links in the list of supported formats would bring the user to the relevant section (Eg for png, it lists at least pillow, freeimage, and if you click on pillow you get to the section on the pillow page describing the png format params). I guesst this could be as simple as adding the format at the end of the link ("/plugins/pillow.html#png"), and making sure that the doc page has <a name='png' />.


What we can't easily automate is the association of an extension with its full format name (and link to additional documentation).

So perhaps we should add some information to the plugin classes so that we can? ;) Maintaining some meta-data at the plugins is easier than maintaining a large manual list.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice, though, if the links in the list of supported formats would bring the user to the relevant section

Nice idea! I'm sold :D This might be a tad iffy to maintain if we automatically generate the list - only a few plugins will have the need for this -, but we can see.

So perhaps we should add some information to the plugin classes so that we can? ;)

What kind of info did you have in mind and where should it live? In my mind that would be a description of each format supported by a plugin/backend. This would mean a lot of replication if multiple formats can read the same format (tiff, jpg, png, ...) that needs to be kept in sync. I guess I am misunderstanding what you have in mind.

@almarklein almarklein Jul 21, 2021 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, ok, I think I see what you mean. You have a format, say PNG, and with it a short description and a link to the wiki page about that format, and then a link to each plugin that supports that format. So maybe we should create a definition of formats, if only for the sake of documentation. Something like:

format_meta_data = {
     "png": {
        "description": """ PNG is a lossless image format, blabla
            ....
        """,
       "plugins": ["pillow", "freeimage"], 
}

or

class PngFormat:
   """ PNG is a lossless bla bla
   ..
   """
   plugins = "pillow", "freeimage" 

And plugins that specify what formats they support based on the key ("png" in this case).

Maybe we could also specify common extension here, instead of on the plugins. mmmm

@FirefoxMetzger FirefoxMetzger Jul 21, 2021 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So maybe we should create a definition of formats, if only for the sake of documentation. [...] And plugins that specify what formats they support based on the key ("png" in this case).

@almarklein Just to poke the bear: If we only do it for the docs, why not use a _templates/format.rst file instead of a meta dict and have it populated by our extension or autodoc? This would give us much easier control over the formatting and allow IDEs with rst support to perform syntax and cross-ref checks. We can also place the description into it directly since it won't be used by any other part of our codebase.

Maybe we could also specify common extension here, instead of on the plugins.

How do you mean? I thought the (dict keys)/(class names) would be based on extensions? Or are you thinking of basing them on a format's full name and then add extensions as a metadata key?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use a _templates/format.rst file

I have never worked with rst templates, so yeah, if that works, great!

How do you mean? I thought the (dict keys)/(class names) would be based on extensions? Or are you thinking of basing them on a format's full name and then add extensions as a metadata key?

So right now (in the old system) a plugin class has an extensions attribute that is used to pre-filter possible plugins. We mean to bring something like this back. But instead of specifying extensions, we could specify format names, and declare what extensions are common to this format in a different (central) place. If we'd go with the rst solution, thus would make much less sense though, I guess :)

@FirefoxMetzger

Copy link
Copy Markdown
Contributor Author

@almarklein Okay, I didn't get a chance to work on ImageIO for a while now, but I made some time today to add the auto-generation we discussed last month.

I changed the imageio_ext to use sphinx's internal templating engine (jinja2) and rewrote the generation routines we had taking advantage of it.

I also added a new module to imageio called config, which stores a list of all extensions (as python classes as discussed), and a dict of all formats/plugins. Both are used to generate the list of known formats in the docs. Moving forward, I want to use the list of extensions to implement #641

I'm thinking if we should/could use the list of plugins to configure the plugins that imageio is aware of. We could extend this to on-demand/lazy loading of plugins the first time it would be used (instead of loading all installed ones on import imageio). I've done something similar recently for some XML bindings here.

@almarklein

Copy link
Copy Markdown
Member

Looking good! Is this ready for merge?

@FirefoxMetzger

Copy link
Copy Markdown
Contributor Author

@almarklein Yep. all green from my side. If you don't have anything else to add I'm happy to merge the PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

2 participants