npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

myopts

v1.1.0

Published

convert python docstrings with options into markdown

Downloads

10

Readme

myopts

NPM version js-standard-style

convert python docstrings with options into markdown

This module provides a command line tool for parsing a Python file and generating nice looking markdown with your function definitions. It's extremely opinionated and rigid! But also extremely easy to use.

I wrote it because Sphinx, the main documentation framework for Python, is complicated, involves a lot of configuration, and exports to re-structured text. Especially for small projects, I want to write documentation in markdown and just combine it with automatically generated function and option signatures. This module helps you do that!

Why myopts? There's a bug called Paonias myops that's also known as the small-eyed Sphinx.

install

Install the command line tool as

npm install myopts -g

example

Put this into a file function.py

def coolfunction(parameter, option=1000):
    """
    This is a docstring.

    Parameters
    ----------
    option : int, optional, default = 10
        Description of the option.
    """

And then call myopts function.py to get the following markdown

#### `coolfunction(parameter, option=1000)`

This is a docstring.

- **`option`** `int` `optional` `default = 10`

   Description of the option.

Which renders as

coolfunction(parameter, option=1000)

This is a docstring.

  • option int optional default = 10

    Description of the option.

usage

Just specify a python file, and any associated options. Markdown will be sent to stdout, or written to a file.

myopts <source> -o <output> -c <classname> -t <title> -s <sort>

The options are:

  • output whether to write to an output file
  • classname if specified, will document all methods for this class
  • title if specified, will add a heading to the top with the given title
  • sort if true, will sort functions by name

format

The parsing in myopts only works on a rigid set of docstring formats, more or less the "numpydocs" style.

You can provide a Python module with one or more functions in the form

def coolfunction(parameter, option=1000):
    """
    This is a docstring.

    Parameters
    ----------
    option : int, optional, default = 10
        Description of the option.

    another : int, optional, default = 200
        Description of another option.
    """

Or you can provide a class with one or more class methods

class CoolClass:
    def coolfunction(self, parameter, option=1000):
        """
        This is a docstring.

        Parameters
        ----------
        option : int, optional, default = 10
            Description of the option.

        another : int, optional, default = 200
            Description of another option.
        """

In either case, the following conventions are assumed:

  • all docstrings are demarcated above and below with """
  • all parameters are listed under the Parameters heading
  • there is a : between a parameter name and its annotation
  • parameter annotations are comma-separated
  • each parameter has a one or many line description followed by a line break

If you write your docstrings any differently, myopts probably won't work!

contributing

A couple simple features that'd be good to add

  • Support for other headings like Returns and Example
  • Throw errors if formatting deviates from expectation, rather than produce garbage

If you want to add one of these, or if you find the intended behavior doesn't work, issues and PRs welcome!

license

MIT