Skip to main content

A formatter for reStructuredText

Project description

Not to be confused with rustfmt.

Highly experimental and unstable. Do not depend on this yet.

Description

rstfmt is a tool for automatically formatting reStructuredText files in a consistent way.

Like Black and gofmt, the motivation is to provide a format that is reasonable and minimally configurable to prevent teams from wasting time on style discussions (or individuals on manually doing formatting, for that matter).

Currently, rstfmt is in a very early stage of development. Not all reST constructs are covered and the interface or formatting may change at any time without warning.

To get a feel for the output of rstfmt, see the sample file.

Usage

# Install directly from the repository.
pip install git+https://github.com/dzhu/rstfmt

# Install from PyPI.
pip install rstfmt

# Read a file from stdin and write the formatted version to stdout.
rstfmt

# Exit with a nonzero status code if any files are not formatted.
rstfmt --check <file>...

# Format the given files in place.
rstfmt <file>...

# Format all files with the `rst` or `txt` extension inside a directory.
rstfmt <directory>...
rstfmt --ext txt <directory>...

# Wrap paragraphs to the given line length (default 72).
rstfmt -w <width>

Like Black’s blackd, there is also a daemon that provides formatting via HTTP requests to avoid the cost of starting and importing everything on every run.

# Install.
pip install 'git+https://github.com/dzhu/rstfmt#egg=rstfmt[d]'
pip install 'rstfmt[d]'

# Start the daemon (binds to localhost:5219 by default).
rstfmtd --bind-host=<host> --bind-port=<port>

# Print the formatted version of a file.
curl http://locahost:5219 --data-binary @<file>

# Specify the line length (default 72).
curl -H 'X-Line-Length: 72' http://locahost:5219 --data-binary @<file>

# Mimic the standalone tool: read from stdin, write to stdout, exit with
# a nonzero status code if there are errors.
curl -fsS http://locahost:5219 --data-binary @/dev/stdin

With editors

The default behavior of reading from stdin and writing to stdout should integrate well with other systems, such as on-save hooks in editors. For example, here’s a configuration for reformatter.el, including both standalone and daemon modes:

;; Run the standalone tool.
(reformatter-define rstfmt
  :program "rstfmt")
(add-hook 'rst-mode-hook #'rstfmt-on-save-mode)

;; Query the daemon.
(reformatter-define client-rstfmt
  :program "curl"
  :args '("-fsS" "http://localhost:5219" "--data-binary" "@/dev/stdin"))
(add-hook 'rst-mode-hook #'client-rstfmt-on-save-mode)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rstfmt-0.0.10-py3-none-any.whl (17.1 kB view details)

Uploaded Python 3

File details

Details for the file rstfmt-0.0.10-py3-none-any.whl.

File metadata

  • Download URL: rstfmt-0.0.10-py3-none-any.whl
  • Upload date:
  • Size: 17.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.7

File hashes

Hashes for rstfmt-0.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 00630511b4f190d08518c3ba2a3698fb2dd125dc63834165441385e64f598cb1
MD5 8fb4c221f8eb6da05d0e0ec8bdb3a8d7
BLAKE2b-256 12dbcba00482cd28a8d5e72632214286a539216108cb20ebbe1c9faf08b2c8db

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page