This release is a pre-release and may not be stable for production use.
docmat
Python docstring formatter.
- Main Functionalities
- Installation
- Usage
- Supported docstring formats
- Examples
- Integration with VSCode
- Roadmap
Main Functionalities
- Adjusts indentation and spacing.
- Wraps all docstring text.
Installation
pip install docmat
Usage
In order to format the docstring of a file, run in a terminal shell:
docmat <filename>|<folder>|<glob>
Examples:
docmat to_format.py
docmat to_format.py other_file_to_format.py
docmat to_format.py --line-length 79
docmat directory
docmat directory/*
Supported docstring formats
Adding support for other docstring formats is in the Roadmap.
Examples
Before:
def func():
"""
This fits in one line.
"""
After:
def func():
"""This fits in one line."""
Before:
def func():
"""start with lower letter, dot missing"""
After:
def func():
"""Start with lower letter, dot missing."""
Before:
def func():
"""
In this docstring a newline after the summary is missing.
Summary and description should be separated by a newline.
"""
After:
def func():
"""
In this docstring a newline after the summary is missing.
Summary and description should be separated by a newline.
"""
Before:
def func():
"""
Summary.
The length of the function description in this specific function exceeds the maximum line length, that in this case is left to the default value `88`. This block of text should be wrapped.
"""
After:
def func():
"""Summary.
The length of the function description in this specific function exceeds the maximum
line length, that in this case is left to the default value `88`. This block of text
should be wrapped.
"""
Adding the parameter --wrap-summary
Before:
def func():
"""By default, the summary line is not wrapped even if it exceeds the maximum line length.
This behavior can be overriden by adding the `--wrap-summary` command line parameter
"""
After:
def func():
"""By default, the summary line is not wrapped even if it exceeds the maximum line
length.
This behavior can be overriden by adding the `--wrap-summary` command line
parameter.
"""
Before:
def func(arg1, arg2):
"""Summary.
args:
arg1(type): The indentation level of this argument is not correct.
arg2(type): In this case, the description of this argument exceeds the maximum line length and it needs to be wrapped.
"""
After:
def func(arg1, arg2):
"""Summary.
Args:
arg1(type): The indentation level of this argument is not correct.
arg2(type): In this case, the description of this argument exceeds the maximum
line length and it needs to be wrapped.
"""
Integration with VSCode
docmat will be integrated with VSCode using a dedicated extension (see also roadmap).
In the meantime, docmat can be used from VSCode with a keyboard shortcut. Here are the steps to make it work:
-
Install
docmatin the python environment used by VSCode following the installation steps -
Open the Keyboard Shortcuts configuration file in VSCode
Preferences > Keyboard Shortcuts > Open Keyboard Shortcuts (JSON) [icon in the top-right]this will open thekeybindings.jsonfile containing the keyboard shortcuts. -
Associate the docmat command to a key-binding by adding the following entry to the keybindings list:
[ { "key": "shift+alt+d", "command": "workbench.action.terminal.sendSequence", "args": { "text": "docmat '${file}'\u000D" } } ]
The suggested key-binding is
shift+alt+D, but you can change it to whatever you like. -
Save the file.
Now, every time you are working on a python file you can hit shift+alt+D and the docmat command will be executed in the VSCode terminal on the file that you have currently opened. Eventual errors or log messages will be shown there. Please note that the environment where docmat is installed should be active in the VSCode integrated terminal prior to using the shortcut.
Roadmap
- Add support for a no-format comment token.
- Add support for bullet lists.
- Add support for other docstring formats:
- Numpydoc
- reST
- Epytext
- Integrate with pre-commit.
- Create VSCode extension.
- Add support for code examples in docstring.
Metadata
Release files for docmat 0.1.0a1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| docmat-0.1.0a1.tar.gz | 8.6 kB | Without provenance | Details for docmat-0.1.0a1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| docmat-0.1.0a1-py3-none-any.whl | Python 3 | none | any | Details for docmat-0.1.0a1-py3-none-any.whl |
Total release size: 17.5 kB
Release files / docmat-0.1.0a1.tar.gz
| Download URL | docmat-0.1.0a1.tar.gz |
|---|---|
| Size | 8.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
016f848cdca76a17773a320ef8af35c97331ffa1c10bec74a82d9d65cb489e5d
|
|
BLAKE2b-256 checksum How to use checksums |
ec960bcbd7df54d6db377f73ce7d18acf263a6d060e82a8164884d3ee5b39750
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.11 CPython/3.9.5 Darwin/19.6.0
|
Release files / docmat-0.1.0a1-py3-none-any.whl
| Download URL | docmat-0.1.0a1-py3-none-any.whl |
|---|---|
| Size | 8.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0271b825c15041b5ec23e8a189e62eb5c49385935ac7020a99eca49f80b7408d
|
|
BLAKE2b-256 checksum How to use checksums |
6c15355319f1964d5325f687906d31ed20422f20dc9bbf55782cd0de898c022a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.1.11 CPython/3.9.5 Darwin/19.6.0
|
Security for docmat 0.1.0a1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.