Automatically parse python docstrings and convert them to markdown!
Project description
docs2md
Automatically parse python docstrings and convert them to markdown!
Installing
pip install
and you're good to go!
https://pypi.org/project/docs2md/
Instructions
Simply run the docs2md.py
from the command line to interact with the ol' main function.
Note: Program uses f-strings, as such python 3.6
or above is required.
Assuming you'll have a folder structure like so:
.
├── foo.py
├── blahbla
│ ├── __init__.py
│ └── blahblah.py
├── LICENSE
└── README.md
Running python3 -m docs2md.py .
will produce the following:
.
├── docs
│ ├── foo.md
│ └── blahbla
│ ├── __init__.md
│ └── blahblah.md
├── foo.py
├── blahbla
│ ├── __init__.py
│ └── blahblah.py
├── LICENSE
└── README.md
The command line arguments are as follow:
positional arguments:
f File or directory to parse!
optional arguments:
-h, --help show this help message and exit
-d [DOCS_DIR], --docs-dir [DOCS_DIR]
Documentation directory in which your .md files will
be saved. Defaults to [cwd]/docs
-p, --just-print Prints the results instead of creating a whole file!
-s [SAVE_IMPORT], --save-import [SAVE_IMPORT]
Whether you'll want to save the imports to another
file. Simply place the path of the txt file you'll
want to save your imports to
--test Runs doctest!
How does this work anyway?
If the input is a directory, doc2md.py
will glob all of the files looking for python
files and then look for doctrings.
Note: That the program will also include the __init__
and main files, as these
can include critical declarations.
The yield_docstrings
function will use python's abstract syntax tree module to look
for docstrings near the following nodes:
- FunctionDef:
def foo()...
- AsyncFunctionDef:
def async foo()...
- ClassDef:
class foo:...
- Module:
"""docstrings at the start of a file"""
And automatically generate a simple markdown based on them. Feel free to perouse this repo's docs folder, which was naturally created using this tool.
The program will also look for the following nodes:
- ImportFrom
- Import
And mentions the fact that a python file imports from this or that module.
(This is useful to keep track of dependencies, and you can save these separately using the -s flag)
As of the moment of writting, the program does not yet include global variables or data. Although I'm partial to including them in a future update.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file docs2md-1.0.1.tar.gz
.
File metadata
- Download URL: docs2md-1.0.1.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 42f98cc99a07f5d4101a46c2239e159064fbef59541fa52446f735520908bd7e |
|
MD5 | e953b15b42ac39e9ff2ff17ac0390421 |
|
BLAKE2b-256 | 49a26423b6efaf173003baf00aa9e9dc8a5b557ac4d2d46b56efbde6247b3ed9 |
File details
Details for the file docs2md-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: docs2md-1.0.1-py3-none-any.whl
- Upload date:
- Size: 19.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 16a550e91d573b629064dbd55008d2fe059e984ef61ee6979c46c16e54dfe126 |
|
MD5 | dbcb3ba1502d902794549a983da8e041 |
|
BLAKE2b-256 | dff292e6b34f1b260c8a7e2e906e0ad9209ea707100ddfa8486f6afc863ffc16 |