Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 91d0962

Browse filesBrowse files
committed
Update configuration documentation.
1 parent 5bc33f3 commit 91d0962
Copy full SHA for 91d0962

File tree

5 files changed

+170
-26
lines changed
Filter options

5 files changed

+170
-26
lines changed

‎doc-source/conf.py

Copy file name to clipboardExpand all lines: doc-source/conf.py
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,5 @@ def setup(app):
7878

7979

8080
nitpicky = True
81+
toctree_plus_types.add("tconf")
82+
toml_spec_version = "0.5.0"

‎doc-source/configuration.rst

Copy file name to clipboardExpand all lines: doc-source/configuration.rst
+163-26Lines changed: 163 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,56 +4,171 @@ Configuration
44

55
``snippet-fmt`` is configured using the ``pyproject.toml`` file in the root of your project
66
(alongside ``setup.py``, ``tox.ini`` etc.).
7-
The file uses the `TOML <https://github.com/toml-lang/toml>`_ syntax,
7+
The file uses the TOML_ syntax,
88
with the configuration in the ``[tool.snippet-fmt]`` table.
99

10-
The table can contain two keys: :ref:`hooks <snippet_fmt_toml_languages>`
11-
and :ref:`config <snippet_fmt_toml_directives>`
10+
The table can contain two keys: :tconf:`languages` and :tconf:`directives`
1211

1312
Alternatively, the :option:`-c / --config-file <snippet-fmt -c>` option can be used to point to a different TOML file.
1413
The layout is the same except the table ``[snippet-fmt]`` rather than ``[tool.snippet.fmt]``.
1514

1615

17-
.. _snippet_fmt_toml_languages:
16+
.. tconf:: languages
1817

19-
``languages``
20-
--------------
18+
This is a table of tables giving languages to check and reformat.
2119

22-
This is a list of languages to check and reformat.
20+
These correspond to the value after ``.. code-block::``, preserving case.
2321

24-
These correspond to the value after ``.. code-block::``, ignoring case.
22+
For example, the following codeblock has a value of ``'TOML'``:
2523

26-
For example, the following codeblock has a value of ``'toml'``:
24+
.. code-block:: rst
2725
28-
.. code-block:: rst
26+
.. code-block:: TOML
2927
30-
.. code-block:: TOML
28+
key = "value"
3129
32-
key = "value"
30+
Each language has a corresponding check / reformat function,
31+
which is determined from the lowercased form of the language name.
32+
This allows certain code blocks in a language to be excluded from formatting
33+
by using a different case, such as using ``TOML`` for most code blocks
34+
and ``toml`` for ones which shouldn't be reformatted.
3335

3436

35-
The currently supported languages are:
37+
The currently supported languages (matched case insensitively) are:
3638

37-
* JSON -- syntax check only.
38-
* INI -- syntax check only.
39-
* TOML -- syntax check only, v0.5.0.
40-
* Python / Python3 -- syntax check and reformatting using formate_.
39+
* JSON
40+
* INI
41+
* TOML
42+
* Python / Python3
4143

42-
Defaults to ``['python', 'toml', 'ini', 'json']``.
44+
Each sub table contains options specific to that language (and capitalisation).
45+
The exact options vary, but each has a ``reformat`` option which defaults to :py:obj:`False`.
46+
If set to :py:obj:`True` the code snippets in that language will be reformatted,
47+
otherwise they will only be syntax checked.
4348

44-
.. _formate: https://formate.readthedocs.io
49+
By default all languages are enabled for checks only.
50+
51+
52+
.. tconf:: directives
53+
54+
The directive types to reformat, such as ``'code-block'`` for ``.. code-block::``.
55+
56+
The values are case sensitive.
57+
58+
Defaults to ``['code', 'code-block', 'sourcecode']``.
59+
60+
61+
Supported Languages
62+
-------------------------
63+
64+
The following languages are supported by ``snippet-fmt``:
65+
66+
67+
Python / Python3
68+
^^^^^^^^^^^^^^^^^^^^
69+
70+
Reformatting Python_ files with formate_.
71+
72+
73+
:bold-title:`Options`
74+
75+
.. tconf:: python.reformat
76+
:type: :toml:`Boolean`
77+
:default: False
78+
79+
If set to ``true`` the code blocks matching this language and capitalisation will be reformatted, otherwise they will only be syntax checked.
80+
81+
82+
.. tconf:: python.config-file
83+
:type: :toml:`String`
84+
:default: formate.toml
85+
86+
The TOML_ file containing the configuration for formate_.
87+
88+
.. TODO:: link for formate's docs
89+
90+
91+
JSON
92+
^^^^^^^^
93+
94+
Syntax checking and reformatting of JSON files, using Python's :mod:`json` module.
95+
96+
97+
:bold-title:`Options`
98+
99+
.. tconf:: json.reformat
100+
:type: :toml:`Boolean`
101+
:default: False
102+
103+
If set to ``true`` the code blocks matching this language and capitalisation will be reformatted, otherwise they will only be syntax checked.
104+
105+
106+
.. tconf:: json.ensure_ascii
107+
:type: :toml:`Boolean`
108+
:default: false
109+
110+
If ``true``, the output is guaranteed to have all incoming non-ASCII characters escaped. If ``false`` (the default), these characters will be output as-is.
45111

112+
.. tconf:: json.allow_nan
113+
:type: :toml:`Boolean`
114+
:default: true
46115

47-
.. _snippet_fmt_toml_directives:
116+
If ``true`` (the default), then ``NaN``, ``Infinity``, and ``-Infinity`` will be encoded as such. This behavior is not JSON specification compliant, but is consistent with most JavaScript based encoders and decoders. Otherwise an error will be raised when attepting to reformat files containing such floats.
48117

49-
``directives``
50-
----------------
118+
.. note:: JSON snippets containing ``NaN`` etc. when this option is ``false`` and ``reformat`` is also ``false`` will pass, as this check only takes place durinh reformatting.
51119

52-
The directive types to reformat, such as ``'code-block'`` for ``.. code-block::``.
53120

54-
The values are case sensitive.
121+
.. tconf:: json.sort_keys
122+
:type: :toml:`Boolean`
123+
:default: false
55124

56-
Defaults to ``['code', 'code-block', 'sourcecode']``.
125+
If ``true`` then the keys will be sorted alphabetically.
126+
127+
128+
.. tconf:: json.indent
129+
:type: :toml:`Integer` or :toml:`string`
130+
131+
If ``indent`` is a non-negative integer or string, then JSON array elements and object members will be pretty-printed with that indent level. An indent level of 0, negative, or "" will only insert newlines. If not specified a compact representation will be used. Using a positive integer indent indents that many spaces per level. If indent is a string (such as "\t"), that string is used to indent each level.
132+
133+
134+
.. tconf:: json.separators
135+
:type: :toml:`Array` of :toml:`string`
136+
137+
A 2-element array of ``[item_separator, key_separator]``.
138+
The default is ``(', ', ': ')`` if ``indent`` is unspecified and ``(',', ': ')`` otherwise.
139+
To get the most compact JSON representation, you should specify ``(',', ':')`` to eliminate whitespace.
140+
141+
142+
TOML
143+
^^^^^^^^
144+
145+
Syntax checking and reformatting of TOML_ files using the `toml <https://pypi.org/project/toml>`__ library.
146+
147+
.. note:: This only supports TOML_ version `0.5.0 <https://toml.io/en/v0.5.0>`_.
148+
149+
150+
:bold-title:`Options`
151+
152+
.. tconf:: toml.reformat
153+
:type: :toml:`Boolean`
154+
:default: False
155+
156+
If set to ``true`` the code blocks matching this language and capitalisation will be reformatted, otherwise they will only be syntax checked.
157+
158+
159+
INI
160+
^^^^^^^^
161+
162+
Syntax checking and reformatting of INI files, using Python's :mod:`configparser` module.
163+
164+
165+
:bold-title:`Options`
166+
167+
.. tconf:: ini.reformat
168+
:type: :toml:`Boolean`
169+
:default: False
170+
171+
If set to ``true`` the code blocks matching this language and capitalisation will be reformatted, otherwise they will only be syntax checked.
57172

58173

59174
Example
@@ -62,5 +177,27 @@ Example
62177
.. code-block:: toml
63178
64179
[tool.snippet-fmt]
65-
languages = ['python', 'toml', 'ini']
66180
directives = ['code', 'code-block', 'sourcecode']
181+
182+
[tool.snippet-fmt.languages.python]
183+
reformat = true
184+
config-file = "pyproject.toml"
185+
186+
[tool.snippet-fmt.languages.TOML]
187+
reformat = true
188+
189+
[tool.snippet-fmt.languages.toml]
190+
[tool.snippet-fmt.languages.ini]
191+
192+
This will:
193+
194+
* look at ``.. code::``, ``.. code-block::`` and ``.. sourcecode::`` directives
195+
for ``python``, ``TOML``, ``toml``, and ``ini``.
196+
* Code blocks marked ``python`` and ``TOML`` will be reformatted.
197+
* Code blocks marked ``toml`` and ``ini`` will only be checked for valid syntax.
198+
* formate_ is configured to take its configuration from ``pyproject.toml``.
199+
200+
201+
.. _TOML: https://toml.io/en/
202+
.. _formate: https://formate.readthedocs.io
203+
.. _Python: https://python.org

‎doc-source/requirements.txt

Copy file name to clipboardExpand all lines: doc-source/requirements.txt
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ sphinx-copybutton>=0.2.12
99
sphinx-debuginfo>=0.1.0
1010
sphinx-licenseinfo>=0.1.1
1111
sphinx-notfound-page>=0.7.1
12+
sphinx-packaging>=0.1.0
1213
sphinx-prompt>=1.1.0
1314
sphinx-pyproject>=0.1.0
1415
sphinx-tabs>=1.1.13

‎pyproject.toml

Copy file name to clipboardExpand all lines: pyproject.toml
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ extensions = [
7474
"sphinx_toolbox_experimental.html_section",
7575
"sphinx_toolbox_experimental.autosummary_widths",
7676
"sphinx_toolbox_experimental.missing_xref",
77+
"sphinx_packaging",
7778
]
7879
sphinxemoji_style = "twemoji"
7980
gitstamp_fmt = "%d %b %Y"

‎repo_helper.yml

Copy file name to clipboardExpand all lines: repo_helper.yml
+3Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,14 @@ extra_sphinx_extensions:
4646
- sphinx_toolbox_experimental.autosummary_widths
4747
# - sphinx_toolbox_experimental.changelog
4848
- sphinx_toolbox_experimental.missing_xref
49+
- sphinx_packaging
4950

5051
sphinx_conf_epilogue:
5152
# - "\tfrom sphinx_toolbox.latex import replace_unknown_unicode"
5253
# - "\tapp.connect('build-finished', replace_unknown_unicode)"
5354
- nitpicky = True
55+
- toctree_plus_types.add("tconf")
56+
- toml_spec_version = "0.5.0"
5457

5558
exclude_files:
5659
- contributing

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.