Name | doccmd JSON |
Version |
2024.11.14
JSON |
| download |
home_page | None |
Summary | Run commands against code blocks in reStructuredText and Markdown files. |
upload_time | 2024-11-14 07:14:16 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.10 |
license | The MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
markdown
rst
sphinx
testing
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
|Build Status| |codecov| |PyPI| |Documentation Status|
doccmd
======
A command line tool for running commands against code blocks in documentation files.
This allows you to run linters, formatters, and other tools against the code blocks in your documentation files.
.. contents::
:local:
Installation
------------
With ``pip``
^^^^^^^^^^^^
Requires Python |minimum-python-version|\+.
.. code-block:: shell
pip install doccmd
With Homebrew (macOS, Linux, WSL)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Requires `Homebrew`_.
.. code-block:: shell
brew tap adamtheturtle/doccmd
brew install doccmd
.. _Homebrew: https://docs.brew.sh/Installation
Pre-built Linux binaries
~~~~~~~~~~~~~~~~~~~~~~~~
.. code-block:: console
$ curl --fail -L https://github.com/adamtheturtle/doccmd/releases/download/2024.11.07/doccmd -o /usr/local/bin/doccmd &&
chmod +x /usr/local/bin/doccmd
Using ``doccmd`` as a pre-commit hook
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
To run ``doccmd`` with `pre-commit`_, add hooks like the following to your ``.pre-commit-config.yaml``:
.. code-block:: yaml
- repo: https://github.com/adamtheturtle/doccmd-pre-commit
rev: v2024.11.07
hooks:
- id: doccmd
args: ["--language", "shell", "--command", "shellcheck --shell=bash"]
additional_dependencies: ["shellcheck-py"]
.. _pre-commit: https://pre-commit.com
Usage example
-------------
.. code-block:: shell
# Run mypy against the Python code blocks in README.md and CHANGELOG.rst
$ doccmd --language=python --command="mypy" README.md CHANGELOG.rst
# Run gofmt against the Go code blocks in README.md
# This will modify the README.md file in place
$ doccmd --language=go --command="gofmt -w" README.md
# or type less... and search for files in the docs directory
$ doccmd -l python -c mypy README.md docs/
What does it work on?
---------------------
* reStructuredText (`.rst`)
.. code-block:: rst
.. code-block:: shell
echo "Hello, world!"
.. code:: shell
echo "Or this Hello, world!"
* Markdown (`.md`)
.. code-block:: markdown
```shell
echo "Hello, world!"
```
* MyST (`.md` with MyST syntax)
.. code-block:: markdown
```{code-block} shell
echo "Hello, world!"
```
```{code} shell
echo "Or this Hello, world!"
```
* Want more? Open an issue!
Formatters and padding
----------------------
Running linters with ``doccmd`` gives you errors and warnings with line numbers that match the documentation file.
It does this by adding padding to the code blocks before running the command.
Some tools do not work well with this padding, and you can choose to obscure the line numbers in order to give the tool the original code block's content without padding, by using the ``--no-pad-file`` flag.
File names and linter ignores
-----------------------------
``doccmd`` creates temporary files for each code block in the documentation file.
These files are created in the same directory as the documentation file, and are named with the documentation file name and the line number of the code block.
Files are created with a prefix set to the given ``--file-name-prefix`` argument (default ``doccmd``).
You can use this information to ignore files in your linter configuration.
For example, to ignore a rule in all files created by ``doccmd`` in a ``ruff`` configuration in ``pyproject.toml``:
.. code-block:: toml
[tool.ruff]
lint.per-file-ignores."doccmd_*.py" = [
# Allow hardcoded secrets in documentation.
"S105",
]
Skipping code blocks
--------------------
Code blocks which come just after a comment matching
``skip doccmd[all]: next`` are skipped.
For example:
* reStructuredText (`.rst`)
.. code-block:: rst
.. skip doccmd[all]: next
.. code-block:: shell
echo "This will be skipped!"
.. code-block:: shell
echo "This will run"
* Markdown (`.md`)
.. code-block:: markdown
<-- skip doccmd[all]: next -->
```shell
echo "This will be skipped!"
```
```shell
echo "This will run"
```
* MyST (`.md` with MyST syntax)
.. code-block:: markdown
% skip doccmd[all]: next
```{code-block} shell
echo "This will be skipped!"
```
```{code-block} shell
echo "This will run"
```
To skip multiple code blocks in a row, use ``skip doccmd[all]: start`` and ``skip doccmd[all]: end`` surrounding the code blocks to skip.
Use the ``--skip-marker`` option to set a marker for this particular command which will work as well as ``"all"``.
For example, use ``--skip-marker="type-check"`` to skip code blocks which come just after a comment matching ``skip doccmd[type-check]: next``.
This marker is matched using a regular expression.
Full documentation
------------------
See the `full documentation <https://doccmd.readthedocs.io/en/latest>`__.
.. |Build Status| image:: https://github.com/adamtheturtle/doccmd/actions/workflows/ci.yml/badge.svg?branch=main
:target: https://github.com/adamtheturtle/doccmd/actions
.. |codecov| image:: https://codecov.io/gh/adamtheturtle/doccmd/branch/main/graph/badge.svg
:target: https://codecov.io/gh/adamtheturtle/doccmd
.. |PyPI| image:: https://badge.fury.io/py/doccmd.svg
:target: https://badge.fury.io/py/doccmd
.. |Documentation Status| image:: https://readthedocs.org/projects/doccmd/badge/?version=latest
:target: https://doccmd.readthedocs.io/en/latest/?badge=latest
:alt: Documentation Status
.. |minimum-python-version| replace:: 3.10
Raw data
{
"_id": null,
"home_page": null,
"name": "doccmd",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.10",
"maintainer_email": null,
"keywords": "markdown, rst, sphinx, testing",
"author": null,
"author_email": "Adam Dangoor <adamdangoor@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/28/9f/c9d97a4bb8d3193d6fd87a527c31d2155f70a6dbb579c84227d75524680f/doccmd-2024.11.14.tar.gz",
"platform": null,
"description": "|Build Status| |codecov| |PyPI| |Documentation Status|\n\ndoccmd\n======\n\nA command line tool for running commands against code blocks in documentation files.\nThis allows you to run linters, formatters, and other tools against the code blocks in your documentation files.\n\n.. contents::\n :local:\n\nInstallation\n------------\n\nWith ``pip``\n^^^^^^^^^^^^\n\nRequires Python |minimum-python-version|\\+.\n\n.. code-block:: shell\n\n pip install doccmd\n\nWith Homebrew (macOS, Linux, WSL)\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nRequires `Homebrew`_.\n\n.. code-block:: shell\n\n brew tap adamtheturtle/doccmd\n brew install doccmd\n\n.. _Homebrew: https://docs.brew.sh/Installation\n\nPre-built Linux binaries\n~~~~~~~~~~~~~~~~~~~~~~~~\n\n.. code-block:: console\n\n $ curl --fail -L https://github.com/adamtheturtle/doccmd/releases/download/2024.11.07/doccmd -o /usr/local/bin/doccmd &&\n chmod +x /usr/local/bin/doccmd\n\nUsing ``doccmd`` as a pre-commit hook\n^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n\nTo run ``doccmd`` with `pre-commit`_, add hooks like the following to your ``.pre-commit-config.yaml``:\n\n.. code-block:: yaml\n\n - repo: https://github.com/adamtheturtle/doccmd-pre-commit\n rev: v2024.11.07\n hooks:\n - id: doccmd\n args: [\"--language\", \"shell\", \"--command\", \"shellcheck --shell=bash\"]\n additional_dependencies: [\"shellcheck-py\"]\n\n.. _pre-commit: https://pre-commit.com\n\nUsage example\n-------------\n\n.. code-block:: shell\n\n # Run mypy against the Python code blocks in README.md and CHANGELOG.rst\n $ doccmd --language=python --command=\"mypy\" README.md CHANGELOG.rst\n\n # Run gofmt against the Go code blocks in README.md\n # This will modify the README.md file in place\n $ doccmd --language=go --command=\"gofmt -w\" README.md\n\n # or type less... and search for files in the docs directory\n $ doccmd -l python -c mypy README.md docs/\n\nWhat does it work on?\n---------------------\n\n* reStructuredText (`.rst`)\n\n.. code-block:: rst\n\n .. code-block:: shell\n\n echo \"Hello, world!\"\n\n .. code:: shell\n\n echo \"Or this Hello, world!\"\n\n* Markdown (`.md`)\n\n.. code-block:: markdown\n\n ```shell\n echo \"Hello, world!\"\n ```\n\n* MyST (`.md` with MyST syntax)\n\n.. code-block:: markdown\n\n ```{code-block} shell\n echo \"Hello, world!\"\n ```\n\n ```{code} shell\n echo \"Or this Hello, world!\"\n ```\n\n* Want more? Open an issue!\n\nFormatters and padding\n----------------------\n\nRunning linters with ``doccmd`` gives you errors and warnings with line numbers that match the documentation file.\nIt does this by adding padding to the code blocks before running the command.\n\nSome tools do not work well with this padding, and you can choose to obscure the line numbers in order to give the tool the original code block's content without padding, by using the ``--no-pad-file`` flag.\n\nFile names and linter ignores\n-----------------------------\n\n``doccmd`` creates temporary files for each code block in the documentation file.\nThese files are created in the same directory as the documentation file, and are named with the documentation file name and the line number of the code block.\nFiles are created with a prefix set to the given ``--file-name-prefix`` argument (default ``doccmd``).\n\nYou can use this information to ignore files in your linter configuration.\n\nFor example, to ignore a rule in all files created by ``doccmd`` in a ``ruff`` configuration in ``pyproject.toml``:\n\n.. code-block:: toml\n\n [tool.ruff]\n\n lint.per-file-ignores.\"doccmd_*.py\" = [\n # Allow hardcoded secrets in documentation.\n \"S105\",\n ]\n\nSkipping code blocks\n--------------------\n\nCode blocks which come just after a comment matching\n``skip doccmd[all]: next`` are skipped.\n\nFor example:\n\n* reStructuredText (`.rst`)\n\n.. code-block:: rst\n\n .. skip doccmd[all]: next\n\n .. code-block:: shell\n\n echo \"This will be skipped!\"\n\n .. code-block:: shell\n\n echo \"This will run\"\n\n* Markdown (`.md`)\n\n.. code-block:: markdown\n\n <-- skip doccmd[all]: next -->\n\n ```shell\n echo \"This will be skipped!\"\n ```\n\n ```shell\n echo \"This will run\"\n ```\n\n* MyST (`.md` with MyST syntax)\n\n.. code-block:: markdown\n\n % skip doccmd[all]: next\n\n ```{code-block} shell\n echo \"This will be skipped!\"\n ```\n\n ```{code-block} shell\n echo \"This will run\"\n ```\n\nTo skip multiple code blocks in a row, use ``skip doccmd[all]: start`` and ``skip doccmd[all]: end`` surrounding the code blocks to skip.\n\nUse the ``--skip-marker`` option to set a marker for this particular command which will work as well as ``\"all\"``.\nFor example, use ``--skip-marker=\"type-check\"`` to skip code blocks which come just after a comment matching ``skip doccmd[type-check]: next``.\nThis marker is matched using a regular expression.\n\nFull documentation\n------------------\n\nSee the `full documentation <https://doccmd.readthedocs.io/en/latest>`__.\n\n.. |Build Status| image:: https://github.com/adamtheturtle/doccmd/actions/workflows/ci.yml/badge.svg?branch=main\n :target: https://github.com/adamtheturtle/doccmd/actions\n.. |codecov| image:: https://codecov.io/gh/adamtheturtle/doccmd/branch/main/graph/badge.svg\n :target: https://codecov.io/gh/adamtheturtle/doccmd\n.. |PyPI| image:: https://badge.fury.io/py/doccmd.svg\n :target: https://badge.fury.io/py/doccmd\n.. |Documentation Status| image:: https://readthedocs.org/projects/doccmd/badge/?version=latest\n :target: https://doccmd.readthedocs.io/en/latest/?badge=latest\n :alt: Documentation Status\n.. |minimum-python-version| replace:: 3.10\n",
"bugtrack_url": null,
"license": "The MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
"summary": "Run commands against code blocks in reStructuredText and Markdown files.",
"version": "2024.11.14",
"project_urls": {
"Documentation": "https://doccmd.readthedocs.io/en/latest/",
"Source": "https://github.com/adamtheturtle/doccmd"
},
"split_keywords": [
"markdown",
" rst",
" sphinx",
" testing"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "93bd416721dc67ef0feb4604375d4d33d64792ab333d6c239a2e1d02d6d199d3",
"md5": "628962772ea228ea8ad7bf468f22f135",
"sha256": "78c1bf0d243c436156fc860b34cbd71298dce1fed914745faf18cc621edc9313"
},
"downloads": -1,
"filename": "doccmd-2024.11.14-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "628962772ea228ea8ad7bf468f22f135",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": ">=3.10",
"size": 12270,
"upload_time": "2024-11-14T07:14:14",
"upload_time_iso_8601": "2024-11-14T07:14:14.227530Z",
"url": "https://files.pythonhosted.org/packages/93/bd/416721dc67ef0feb4604375d4d33d64792ab333d6c239a2e1d02d6d199d3/doccmd-2024.11.14-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "289fc9d97a4bb8d3193d6fd87a527c31d2155f70a6dbb579c84227d75524680f",
"md5": "762c8e8283ccf17a0e6f49cdb42cfd34",
"sha256": "4a2262c2f6f9834b3e05de2498c48b060eae0fa9b7ae89d9a9ed28cd005e031e"
},
"downloads": -1,
"filename": "doccmd-2024.11.14.tar.gz",
"has_sig": false,
"md5_digest": "762c8e8283ccf17a0e6f49cdb42cfd34",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.10",
"size": 38965,
"upload_time": "2024-11-14T07:14:16",
"upload_time_iso_8601": "2024-11-14T07:14:16.217024Z",
"url": "https://files.pythonhosted.org/packages/28/9f/c9d97a4bb8d3193d6fd87a527c31d2155f70a6dbb579c84227d75524680f/doccmd-2024.11.14.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-14 07:14:16",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "adamtheturtle",
"github_project": "doccmd",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "doccmd"
}