|
4 | 4 | Specification of the :file:`setup.cfg` file |
5 | 5 | ******************************************* |
6 | 6 |
|
7 | | -.. :version: 1.0 |
| 7 | +:version: 0.9 |
8 | 8 |
|
9 | 9 | This document describes the :file:`setup.cfg`, an ini-style configuration file |
10 | | -(compatible with :class:`configparser.RawConfigParser`) configuration file used |
11 | | -by Packaging to replace the :file:`setup.py` file. |
| 10 | +(compatible with :class:`configparser.RawConfigParser`) used by Packaging to |
| 11 | +replace the :file:`setup.py` file. |
| 12 | + |
| 13 | + |
| 14 | +Syntax |
| 15 | +====== |
| 16 | + |
| 17 | +The configuration file is an ini-based file. Variables name can be |
| 18 | +assigned values, and grouped into sections. A line that starts with "#" is |
| 19 | +commented out. Empty lines are also removed. |
| 20 | + |
| 21 | +Example:: |
| 22 | + |
| 23 | + [section1] |
| 24 | + # comment |
| 25 | + name = value |
| 26 | + name2 = "other value" |
| 27 | + |
| 28 | + [section2] |
| 29 | + foo = bar |
| 30 | + |
| 31 | + |
| 32 | +Values conversion |
| 33 | +----------------- |
| 34 | + |
| 35 | +Here are a set of rules for converting values: |
| 36 | + |
| 37 | +- If value is quoted with " chars, it's a string. This notation is useful to |
| 38 | + include "=" characters in the value. In case the value contains a " |
| 39 | + character, it must be escaped with a "\" character. |
| 40 | +- If the value is "true" or "false" --no matter what the case is--, it's |
| 41 | + converted to a boolean, or 0 and 1 when the language does not have a |
| 42 | + boolean type. |
| 43 | +- A value can contains multiple lines. When read, lines are converted into a |
| 44 | + sequence of values. Each new line for a multiple lines value must start with |
| 45 | + a least one space or tab character. These indentation characters will be |
| 46 | + stripped. |
| 47 | +- all other values are considered as strings |
| 48 | + |
| 49 | +Examples:: |
| 50 | + |
| 51 | + [section] |
| 52 | + foo = one |
| 53 | + two |
| 54 | + three |
| 55 | + |
| 56 | + bar = false |
| 57 | + baz = 1.3 |
| 58 | + boo = "ok" |
| 59 | + beee = "wqdqw pojpj w\"ddq" |
| 60 | + |
| 61 | + |
| 62 | +Extending files |
| 63 | +--------------- |
| 64 | + |
| 65 | +An INI file can extend another file. For this, a "DEFAULT" section must contain |
| 66 | +an "extends" variable that can point to one or several INI files which will be |
| 67 | +merged to the current file by adding new sections and values. |
| 68 | + |
| 69 | +If the file pointed in "extends" contains section/variable names that already |
| 70 | +exist in the original file, they will not override existing ones. |
| 71 | + |
| 72 | +file_one.ini:: |
| 73 | + |
| 74 | + [section1] |
| 75 | + name2 = "other value" |
| 76 | + |
| 77 | + [section2] |
| 78 | + foo = baz |
| 79 | + bas = bar |
| 80 | + |
| 81 | +file_two.ini:: |
| 82 | + |
| 83 | + [DEFAULT] |
| 84 | + extends = file_one.ini |
| 85 | + |
| 86 | + [section2] |
| 87 | + foo = bar |
| 88 | + |
| 89 | +Result:: |
| 90 | + |
| 91 | + [section1] |
| 92 | + name2 = "other value" |
| 93 | + |
| 94 | + [section2] |
| 95 | + foo = bar |
| 96 | + bas = bar |
| 97 | + |
| 98 | +To point several files, the multi-line notation can be used:: |
| 99 | + |
| 100 | + [DEFAULT] |
| 101 | + extends = file_one.ini |
| 102 | + file_two.ini |
| 103 | + |
| 104 | +When several files are provided, they are processed sequentially. So if the |
| 105 | +first one has a value that is also present in the second, the second one will |
| 106 | +be ignored. This means that the configuration goes from the most specialized to |
| 107 | +the most common. |
| 108 | + |
| 109 | +**Tools will need to provide a way to produce a canonical version of the |
| 110 | +file**. This will be useful to publish a single file. |
| 111 | + |
| 112 | + |
| 113 | +Description of sections and fields |
| 114 | +================================== |
12 | 115 |
|
13 | 116 | Each section contains a description of its options. |
14 | 117 |
|
@@ -646,3 +749,57 @@ section named after the command. Example:: |
646 | 749 |
|
647 | 750 | Option values given in the configuration file can be overriden on the command |
648 | 751 | line. See :ref:`packaging-setup-config` for more information. |
| 752 | + |
| 753 | + |
| 754 | +Extensibility |
| 755 | +============= |
| 756 | + |
| 757 | +Every section can define new variables that are not part of the specification. |
| 758 | +They are called **extensions**. |
| 759 | + |
| 760 | +An extension field starts with *X-*. |
| 761 | + |
| 762 | +Example:: |
| 763 | + |
| 764 | + [metadata] |
| 765 | + ... |
| 766 | + X-Debian-Name = python-distribute |
| 767 | + |
| 768 | + |
| 769 | +Changes in the specification |
| 770 | +============================ |
| 771 | + |
| 772 | +The version scheme for this specification is **MAJOR.MINOR**. |
| 773 | +Changes in the specification will increment the version. |
| 774 | + |
| 775 | +- minor version changes (1.x): backwards compatible |
| 776 | + |
| 777 | + - new fields and sections (both optional and mandatory) can be added |
| 778 | + - optional fields can be removed |
| 779 | + |
| 780 | +- major channges (2.X): backwards-incompatible |
| 781 | + |
| 782 | + - mandatory fields/sections are removed |
| 783 | + - fields change their meaning |
| 784 | + |
| 785 | +As a consequence, a tool written to consume 1.X (say, X=5) has these |
| 786 | +properties: |
| 787 | + |
| 788 | +- reading 1.Y, Y<X (e.g. 1.1) is possible, since the tool knows what |
| 789 | + optional fields weren't there |
| 790 | +- reading 1.Y, Y>X is also possible. The tool will just ignore the new |
| 791 | + fields (even if they are mandatory in that version) |
| 792 | + If optional fields were removed, the tool will just consider them absent. |
| 793 | +- reading 2.X is not possible; the tool should refuse to interpret |
| 794 | + the file. |
| 795 | + |
| 796 | +A tool written to produce 1.X should have these properties: |
| 797 | + |
| 798 | +- it will write all mandatory fields |
| 799 | +- it may write optional fields |
| 800 | + |
| 801 | + |
| 802 | +Acks |
| 803 | +==== |
| 804 | + |
| 805 | +XXX |
0 commit comments