Giter Club home page Giter Club logo

keras-autodoc's Introduction

keras-autodoc

Autodoc for mkdocs.

keras-autodoc will fetch the docstrings from the functions you wish to document and will insert them in the markdown files.

Take a look at the documentation!

Install

pip install keras-autodoc

We recommend pinning the version (eg: pip install keras-autodoc==0.3.2). We may break compatibility without any warning.

Example

Let's suppose that you have a docs directory:

./docs
|-- autogen.py
|-- mkdocs.yml

The API is quite simple:

# content of docs/autogen.py

from keras_autodoc import DocumentationGenerator


pages = {'layers/core.md': ['keras.layers.Dense', 'keras.layers.Flatten'],
         'callbacks.md': ['keras.callbacks.TensorBoard']}

doc_generator = DocumentationGenerator(pages)
doc_generator.generate('./sources')
# content of docs/mkdocs.yml

site_name: My_site
docs_dir: sources
site_description: 'My pretty site.'

nav:
    - Core: layers/core.md
    - Callbacks:
      - Some callbacks: callbacks.md

Then you just have to run:

python autogen.py
mkdocs serve

and you'll be able to see your website at localhost:8000/callbacks.

Docstring format:

The docstrings used should use the The docstrings follow the Google Python Style Guide with markdown, or just plain markdown.

For example, let's take this class:

class ImageDataGenerator:
    """Generate batches of tensor image data with real-time data augmentation.

    The data will be looped over (in batches).

    # Arguments
        featurewise_center: Boolean.
            Set input mean to 0 over the dataset, feature-wise.
        zca_whitening: Boolean. Apply ZCA whitening.
        width_shift_range: Float, 1-D array-like or int
            - float: fraction of total width, if < 1, or pixels if >= 1.
            - 1-D array-like: random elements from the array.
            - int: integer number of pixels from interval
                `(-width_shift_range, +width_shift_range)`
            - With `width_shift_range=2` possible values
                are integers `[-1, 0, +1]`,
                same as with `width_shift_range=[-1, 0, +1]`,
                while with `width_shift_range=1.0` possible values are floats
                in the interval `[-1.0, +1.0)`.

    # Examples

    Example of using `.flow(x, y)`:
    ```python
    datagen = ImageDataGenerator(
        featurewise_center=True,
        zca_whitening=True,
        width_shift_range=0.2)
    # compute quantities required for featurewise normalization
    # (std, mean, and principal components if ZCA whitening is applied)
    datagen.fit(x_train)
    # fits the model on batches with real-time data augmentation:
    model.fit_generator(datagen.flow(x_train, y_train, batch_size=32),
                        steps_per_epoch=len(x_train) / 32, epochs=epochs)
    ```
    """

    def __init__(self,featurewise_center, zca_whitening, width_shift_range):
        pass

will be rendered as:

ImageDataGenerator class:

dummy_module.ImageDataGenerator(featurewise_center, zca_whitening, width_shift_range=0.0)

Generate batches of tensor image data with real-time data augmentation.

The data will be looped over (in batches).

Arguments

  • featurewise_center: Boolean. Set input mean to 0 over the dataset, feature-wise.
  • zca_whitening: Boolean. Apply ZCA whitening.
  • width_shift_range: Float, 1-D array-like or int
    • float: fraction of total width, if < 1, or pixels if >= 1.
    • 1-D array-like: random elements from the array.
    • int: integer number of pixels from interval (-width_shift_range, +width_shift_range)
    • With width_shift_range=2 possible values are integers [-1, 0, +1], same as with width_shift_range=[-1, 0, +1], while with width_shift_range=1.0 possible values are floats in the interval [-1.0, +1.0).

Examples

Example of using .flow(x, y):

datagen = ImageDataGenerator(
    featurewise_center=True,
    zca_whitening=True,
    width_shift_range=0.2)
# compute quantities required for featurewise normalization
# (std, mean, and principal components if ZCA whitening is applied)
datagen.fit(x_train)
# fits the model on batches with real-time data augmentation:
model.fit_generator(datagen.flow(x_train, y_train, batch_size=32),
                    steps_per_epoch=len(x_train) / 32, epochs=epochs)

Take a look at our docs

If you want examples, you can take a look at the docs directory of autokeras as well as the generated docs.

You can also look at the docs directory of keras-tuner.

keras-autodoc's People

Contributors

bstriner avatar bzamecnik avatar edwardraff avatar ericwu09 avatar farizrahman4u avatar fchollet avatar frexvahi avatar fuzzythecat avatar gabrieldemarmiesse avatar gokceneraslan avatar grahamannett avatar haifeng-jin avatar heathhenley avatar julienr avatar junwei-pan avatar kouml avatar leonoverweel avatar lgvaz avatar maxpumperla avatar mezzode avatar mkaze avatar mkirch avatar nzw0301 avatar olegsinavski avatar ozabluda avatar ramananbalakrishnan avatar raphaelmeudec avatar somewacko avatar stefanocappellini avatar valtron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

keras-autodoc's Issues

Can "function" and "class" suffixes in docs headers be removed or become optional?

Currently Keras Autodoc appends the word "class" to the names of classes in their docs headers (example in our Larq docs, larq.layers.QuantDense becomes "QuantDense class") and "function" to the names of functions (example).

We think this adds a bit of unnecessary visual noise/clutter (see larq/docs#118), so I was wondering if this is something we can make optional or remove altogether? I'd be happy to make a PR myself, just wanted to check in before I do. :)

Use class alias

Hi @gabrieldemarmiesse , is there a way to have a class documentation use its alias rather than its actual class name?

I.e. we have keratuner.tuners.randomsearch.RandomSearchOracle but we also have this aliased as kerastuner.oracles.RandomSearch. Is there a way to make the second name be the display name in documentation?

Support for dataclasses

When parsing a @dataclass, DocumentationGenerator.generate fails with AttributeError: module 'mantisshrimp.core.bbox' has no attribute '__create_fn__' (full stack trace at the bottom).

What happens is that the __init__ representation from dataclasses is different than for normal classes.

For normal classes we have:

<function DocumentationGenerator.__init__ at 0x104e56710>

While for dataclasses:

<function __create_fn__.<locals>.__init__ at 0x13b3c1290>

If I understood the problem correctly, get_class_from_method is trying to get the name of the class from the representation, but the name of the class is not present in the dataclass __init__.


Traceback (most recent call last):
  File "autogen.py", line 340, in <module>
    generate(mantisshrimp_dir / "docs" / "sources")
  File "autogen.py", line 256, in generate
    doc_generator.generate(dest_dir)
  File "/Users/lgvaz/anaconda3/envs/mantis/lib/python3.7/site-packages/keras_autodoc/autogen.py", line 82, in generate
    markdown_text += self._render(element)
  File "/Users/lgvaz/anaconda3/envs/mantis/lib/python3.7/site-packages/keras_autodoc/autogen.py", line 109, in _render
    return self._render_from_object(object_, signature_override)
  File "/Users/lgvaz/anaconda3/envs/mantis/lib/python3.7/site-packages/keras_autodoc/autogen.py", line 116, in _render_from_object
    object_, signature_override, self.max_signature_line_length
  File "/Users/lgvaz/anaconda3/envs/mantis/lib/python3.7/site-packages/keras_autodoc/get_signatures.py", line 51, in get_signature
    return get_class_signature(object_, override, max_line_length)
  File "/Users/lgvaz/anaconda3/envs/mantis/lib/python3.7/site-packages/keras_autodoc/get_signatures.py", line 45, in get_class_signature
    signature_end = get_signature_end(cls.__init__)
  File "/Users/lgvaz/anaconda3/envs/mantis/lib/python3.7/site-packages/keras_autodoc/get_signatures.py", line 25, in get_signature_end
    if utils.ismethod(function):
  File "/Users/lgvaz/anaconda3/envs/mantis/lib/python3.7/site-packages/keras_autodoc/utils.py", line 80, in ismethod
    return get_class_from_method(function) is not None
  File "/Users/lgvaz/anaconda3/envs/mantis/lib/python3.7/site-packages/keras_autodoc/utils.py", line 73, in get_class_from_method
    meth.__qualname__.split('.<locals>', 1)[0].rsplit('.', 1)[0])

Cannot properly configure autogen.py

I am completely new to python and mkdocs, so I started a pet project for testing purposes and I wanted to use keras-autodoc for documenting my own functions (looks really promising, and I can use markdown instead of rst).

If I am not wrong, after configuring autogen.py and running mkdocs serve a new .md file will be created with the documentation of all functions listed within the pages variable.

After reading readme.md file, I tried to adapt it to my project, but without success.
My project uses the following structure:

├── docs/   <- where mkdocs and autogen.py are located.
├── src                <- Source code for use in this project.
│   ├── __init__.py    <- Makes src a Python module
│   ├── features       <- Scripts to turn raw data into features for modeling
│           ├── __init__.py   
│           └── bcn_trees.py

You can see the complete repo here

With that structure, I created a docs/autogen.py file with the following content:

# content of docs/autogen.py

from keras_autodoc import DocumentationGenerator

pages = {
    'api_bcn_trees.md': [
        'bcn_trees.data_download',
        'bcn_trees.data_munging']
    }

doc_generator = DocumentationGenerator(pages)
doc_generator.generate('./sources')

but when running mkdocs serve the api_bcn_trees.md file is not generated. What am I doing wrong?

[Question] Pinned Black version

Hi!

In setup.py black is pinned to the version 19.10b0, is that a hard requirement for the documentation to build properly?

I'm using your package as a dependency of mine, and this also requires me to lock the version of black, I tested building the docs with the newest version of black and it seemed to work just fine.

Turn example code into pytest tests

@gabrieldemarmiesse Thanks for fixing the previous issues so quickly!

It would be a great feature if we had a way to mark code snippets that exist in the documentation in a way that indicates that they should be run as tests. During python autogen.py, we could extract those snippets into tests that can be run with pytest. This way we could ensure our examples stay up-to-date

See discussion on keras-team/keras-tuner#136 (comment), we would probably have to roll our own solution for this

Support for Enums

When having an enum as a default parameter in any function, the following error occurs:

black.InvalidInput: Cannot parse: 1:72: def xxxx(metric_type=<COCOMetricType.bbox: 'bbox'>, print_summary=False):

The error tells everything, inside format_signature black is used and it cannot understand <Classname...> because that's not valid python code.

I've found two workarounds but they are both suboptimal. The first is to use None in the default value instead, and the second, to change the enum __repr__/__str__.

Is there another way to get around this error? I can try drafting a PR if you think this is easily solvable.

ImportError: cannot import name 'Signature' from 'sphinx.util.inspect'

Hi,

I'm using this package for documenting all my Python packages, especially this one.

It worked very well on my last commit but now, when I run python3 docs/autogen.py, I get the following error messages:

Traceback (most recent call last):
  File "docs/autogen.py", line 4, in <module>
    import keras_autodoc
  File "/Users/t/Documents/Python_Packages/teller/venv/lib/python3.8/site-packages/keras_autodoc/__init__.py", line 1, in <module>
    from .autogen import DocumentationGenerator
  File "/Users/t/Documents/Python_Packages/teller/venv/lib/python3.8/site-packages/keras_autodoc/autogen.py", line 8, in <module>
    from .get_signatures import get_signature
  File "/Users/t/Documents/Python_Packages/teller/venv/lib/python3.8/site-packages/keras_autodoc/get_signatures.py", line 5, in <module>
    from sphinx.util.inspect import Signature
ImportError: cannot import name 'Signature' from 'sphinx.util.inspect' (/Users/t/Documents/Python_Packages/teller/venv/lib/python3.8/site-packages/sphinx/util/inspect.py)

It seems like the problem comes from this file, and a change in Sphinx's API. Could you please help me in solving this issue?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.