Generate usage documentation from Python scripts using the `argparse` module
Project description
Parse 2 Docs
parse2docs
is a Python library that allows you to automatically generate usage documentation in Markdown format from Python scripts using the argparse
module.
Features
- Scans the Python script for instances of
argparse.ArgumentParser
. - Generates a Markdown file with usage documentation based on the
ArgumentParser
object. - The generated documentation includes a table of contents, descriptions of each command line argument, and examples if provided.
- Works with
ArgumentParser
instances declared at the module level or returned by functions.
Installation
Via pip
parse2docs
is not yet available for installation via pip
. To use the library, clone this repository to your local machine and import the required functions directly into your Python scripts.
Via poetry
parse2docs
can be installed via Poetry. To install the library, clone this repository to your local machine and use Poetry to install:
git clone https://github.com/yourusername/parse2docs.git
cd parse2docs
poetry install
Usage
There are two ways to use parse2docs, either as a Python module in your script or directly from the command line using the provided command.
As a Python module
import parse2docs
# Path to the Python script
script_path = 'path_to_your_python_script.py'
# Generate markdown documentation
markdown = parse2docs.generate_md_from_py_script(script_path)
# Save the markdown to a .md file
with open('output.md', 'w') as f:
f.write(markdown)
This will generate a output.md
file with the usage documentation in Markdown format.
From the command line
You can use parse2docs
directly from the command line with the parse2docs
command. The command takes a Python script as an argument and generates a markdown file with the same name and in the same directory as the Python script.
parse2docs path_to_your_python_script.py
This will print the usage documentation in Markdown format to the console.
Testing
We use pytest
for testing. Run the tests with the following command:
python -m pytest tests/
Contributing
Contributions to parse2docs
are welcome and awesome! Please submit a pull request or open an issue to discuss potential changes or improvements.
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 parse2docs-0.1.0.tar.gz
.
File metadata
- Download URL: parse2docs-0.1.0.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.2 CPython/3.11.4 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | de207a0ded6b141d3743b79267a52607b2c2243de9c5dbda2319f0ac7378db81 |
|
MD5 | 5ec61361b58a827b0ad6f4d1f93b3235 |
|
BLAKE2b-256 | 3f0e4529e7406798bfeae9d93c70aff9b333d832b5f7e185e65525c2f02b7b9f |
File details
Details for the file parse2docs-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: parse2docs-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.2 CPython/3.11.4 Windows/10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a3fd8985752e1ad273762c48658defabc48d0c73fbe694cae3130dd2821ebe4 |
|
MD5 | c32ee6ad97d56fd4b05fd69226fac43d |
|
BLAKE2b-256 | 9652f87501f0a3b7d21fd453b19f629089d8d241cb9aa3f89c838887dc9a346e |