Giter Club home page Giter Club logo

npdoc_to_md's Introduction

example workflow codecov PyPI version Documentation Made withJupyter

npdoc_to_md

logo

Thanks to freesvg.org for the logo assets

Automatic documentation tool using Markdown and Python docstrings written with the numpydoc style.

This library does not generate a website! It converts template strings/files/folders written in Markdown. The result of that can be used for instance for GitHub or Gitlab Wiki.

The features (see below) are somewhat basic. If you need more advanced features you might want to look into my suggestions for other documentation tools.

Features

  • Easy to use: just place a few placeholders in template files and convert a file or a folder of templates with a single command
  • Supports all sections of a docstring in numpydoc style + custom sections (they'll be read as Markdown)
  • Flexible language highlighting for example outputs (render a markdown table, python code, raw code etc.) on a per-example basis or a per-docstring basis

Requirements

  • Python 3.7+ (besides dataclasses that can be backported with pip install dataclasses there would be too many changes for 3.6 compatibility which is obsolete anyways)
  • dependencies of this library (see requirements.txt and Installation section)

Installation

pip install npdoc_to_md

Install the fire library from Google to use the CLI (recommended)

pip install fire

Quickstart

For more features (e.g. rendering a whole folder in a single command) and explanations on the placeholders (lines surrounded by {{ }}), head over to the documentation.

1. Make a template in Markdown

.npmd is the recommended file extension for template files using this library but that's entirely up to you.

Content of our example template Home.npmd:

# My super cool library

## Some dummy function

{{"obj":"npdoc_to_md.testing.create_random_table", "alias":"create_random_table", "examples_md_lang":"markdown_rendered", "remove_doctest_skip":true, "remove_doctest_blanklines":true, "md_section_level":3}}

2. Render the template

From a terminal:

$ npdoc-to-md render-file -source "Home.npmd" --destination "Home.md"

From Python:

from npdoc_to_md import render_file

render_file(source='Home.npmd', destination='Home.md')

3. Enjoy the result ๐Ÿ

Before

Creates a random table

Parameters
----------
nb_rows
    How many rows to generate

Examples
--------
>>> from npdoc_to_md.testing import TestFunctions
>>>
>>> df = TestFunctions.create_random_table()
>>> print(df.to_markdown(index=False))  # doctest: +SKIP
|   A |   B |   C |   D |
|----:|----:|----:|----:|
|  67 |  14 |  78 |  77 |
|  12 |  96 |  69 |  54 |
|  81 |  13 |  55 |  18 |
|  15 |  15 |  88 |  64 |
|  48 |  68 |  36 |  10 |

After


create_random_table(nb_rows: int = 5) -> 'pandas.DataFrame'

Creates a random table

Parameters

  • nb_rows

    How many rows to generate

Examples

from npdoc_to_md.testing import TestFunctions

df = TestFunctions.create_random_table()
print(df.to_markdown(index=False))
A B C D
67 14 78 77
12 96 69 54
81 13 55 18
15 15 88 64
48 68 36 10

Testing

# 1. Create and activate the build environment
conda env create -f environment.yml
conda activate npdoc_to_md-dev
# 2. Install npdoc_to_md in editable mode (changes are reflected upon reimporting)
pip install -e .
# 3. Run pytest
pytest -sv npdoc_to_md --cov=npdoc_to_md --doctest-modules

Development

I develop the library inside of Jupyter Lab using the jupytext extension.

I recommend using this extension for the best experience. It will split code blocks within modules in notebook cells and will allow interactive development.

If you wish you can also use the provided conda environment (see environment.yml file) inside of Jupyter Lab/Notebook thanks to nb_conda_kernels.

Other documentation tools

Note that all libraries below produce a website and not markdown files like npdoc_to_md does. I also wrote some feedback after trying them for npdoc_to_md (see the research folder). Obviously this is not an exhaustive list of documentation tools.

  • mkdocstrings: this library seems to have a few problems with numpydoc style docstrings
  • pydoc-markdown: does not seem to support numpydoc style docstrings (see this issue). I have not gotten it to work yet because I have an error with the most basic configuration (no next element for the walker to move to)
  • sphinx: sphinx works quite well with the simple example I provided. I didn't manage to get markdown inside docstrings to work though.

Motivation

Sphinx is what motivated me to make such a library several years ago (it was first private for a long time).

I was never 100% satisfied with the results (I had much more complex cases including the presence of subpackages) despite a lot of time spent tweaking sphinx. I also did not like the idea of having to host a website for private libraries and then also having to protect it with a login.

There is probably a library I could use as backend instead of doing a big part of the parsing myself or maybe even a library that could replace this one. Feel free to contact me if you come up with something interesting. This was a great learning project though and I am very happy with the current results.

npdoc_to_md's People

Contributors

thibtrip avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

npdoc_to_md's Issues

Include return type for properties

When documenting class properties it would be nice to have the returned type e.g.

### my_library.Foo.some_property -> str

Lorem ipsum...

Currently we have that instead:

### my_library.Foo.some_property

Lorem ipsum...

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.