-
-
Notifications
You must be signed in to change notification settings - Fork 173
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add TOML config loading, autodetect pyproject.toml #374
Changes from 11 commits
af76101
596c7fd
42ad151
09aba9e
dcf9f6e
caac79f
e678632
2fb5f80
fca5cc3
0f2b021
615edd1
87cd2b3
cff267c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,3 +5,4 @@ pyflakes | |
pytest>=5.4.1 | ||
coverage>=4.0,<5 | ||
doit-py>=0.4.0 | ||
toml>=0.10.1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,12 +18,94 @@ The name can be seem from ``doit help`` output:: | |
-f ARG, --file=ARG load task from dodo FILE [default: dodo.py] (config: dodoFile) | ||
|
||
|
||
pyproject.toml | ||
-------------- | ||
|
||
`doit` configuration can be read from `pyproject.toml <https://www.python.org/dev/peps/pep-0518/>`_ | ||
under the `tool.doit` namespace. In the future, especially if a TOML parser becomes | ||
part of the python standard library, this will become the preferred configuration source, | ||
and may gain features not available in the legacy `doit.cfg`. | ||
|
||
.. note:: | ||
|
||
As a TOML parser is _not_ yet part of the standard library, a third-party package is | ||
required, one of: | ||
|
||
- `toml <https://pypi.org/project/toml/>`_ | ||
- `tomlkit <https://pypi.org/project/tomlkit/>`_ | ||
|
||
|
||
TOML vs INI | ||
^^^^^^^^^^^ | ||
|
||
While mostly similar, `TOML <https://toml.io>`_ differs from the INI format | ||
in a few ways: | ||
|
||
- all strings must be quoted with `'` or `"` | ||
- triple-quoted strings may contain new line characters (`\n`) and quotes | ||
- must be saved as UTF-8 | ||
- integers and floating point numbers can be written without quotes | ||
- boolean values can be written unquoted and lower-cased, as `true` and `false` | ||
|
||
Unlike "plain" TOML, `doit` will parse pythonic strings into their correct types, | ||
e.g. `"True"`, `"False"`, `"3"`, but using "native" TOML types may be preferable. | ||
|
||
|
||
tool.doit | ||
^^^^^^^^^ | ||
|
||
The `tool.doit` section may contain command line options that will be used | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess mentioned this before... Why not just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is specified by PEP 518. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see it is their recommendation... although I dont really understand/agree why limit to only 2 top tables. So another question. Why put There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Indeed, that has a solid question, and mypy has fought back viciously, for some reason. But my feeling is that the more tools I can cram into a single, consensus-driven file, the better I'll be able to automate the creation (through schema, etc), updating, etc. vs code.
A fine idea as well, and could be added to the list. I'd imagine this one wouldn't have the |
||
(if applicable) by any commands. | ||
|
||
Example setting the DB backend type: | ||
|
||
.. code-block:: toml | ||
|
||
[tool.doit] | ||
backend = "json" | ||
|
||
All commands that have a `backend` option (*run*, *clean*, *forget*, etc), | ||
will use this option without the need for this option in the command line. | ||
|
||
|
||
tools.doit.commands | ||
^^^^^^^^^^^^^^^^^^^ | ||
|
||
To configure options for a specific command, use a section with | ||
the command name under `tools.doit.commands`: | ||
|
||
.. code-block:: toml | ||
|
||
[tools.doit.commands.list] | ||
status = true | ||
subtasks = true | ||
|
||
|
||
tools.doit.plugins | ||
^^^^^^^^^^^^^^^^^^ | ||
|
||
Check the :ref:`plugins <plugins>` section for an introduction | ||
on available plugin categories. | ||
|
||
|
||
tools.doit.tasks | ||
^^^^^^^^^^^^^^^^ | ||
|
||
To configure options for a specific task, use a section with | ||
the task name under `tool.doit.tasks`: | ||
|
||
.. code-block:: toml | ||
|
||
[tool.doit.tasks.make_cookies] | ||
cookie_type = "chocolate" | ||
temp = "375F" | ||
duration = 12 | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You mentioned about being able to define tasks in TOML, right? Have you thought about what the name would be? I would thing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Again, the naming is just trying to keep the new format as parallel as possible while both config formats are supported. I don't recall ever actually having used the task params, but I'm sure someone would want to! If anything, I'd imagine putting everything this PR has done thus far under
I had imagined this as a separate loader, e.g. For the actual task definitions, I'm imagining the high road would, whether such a loader was part of this repo or standalone:
|
||
|
||
doit.cfg | ||
-------- | ||
|
||
`doit` uses an INI style configuration file | ||
`doit` also supports an INI style configuration file | ||
(see `configparser <https://docs.python.org/3/library/configparser.html>`_). | ||
Note: key/value entries can be separated only by the equal sign `=`. | ||
|
||
|
@@ -41,20 +123,24 @@ GLOBAL section | |
The `GLOBAL` section may contain command line options that will | ||
be used (if applicable) by any commands. | ||
|
||
Example setting the DB backend type:: | ||
Example setting the DB backend type: | ||
|
||
.. code-block:: ini | ||
|
||
[GLOBAL] | ||
backend = json | ||
|
||
All commands that has a `backend` option (*run*, *clean*, *forget*, etc), | ||
will use this option without the need this option in the command line. | ||
All commands that have a `backend` option (*run*, *clean*, *forget*, etc), | ||
will use this option without the need for this option in the command line. | ||
|
||
|
||
commands section | ||
^^^^^^^^^^^^^^^^ | ||
|
||
To configure options for a specific command, use a section with | ||
the command name:: | ||
the command name: | ||
|
||
.. code-block:: ini | ||
|
||
[list] | ||
status = True | ||
|
@@ -72,13 +158,16 @@ per-task sections | |
^^^^^^^^^^^^^^^^^ | ||
|
||
To configure options for a specific task, use a section with | ||
the task name prefixed with "task:":: | ||
the task name prefixed with "task:": | ||
|
||
.. code-block:: ini | ||
|
||
[task:make_cookies] | ||
cookie_type = chocolate | ||
temp = 375F | ||
duration = 12 | ||
|
||
|
||
configuration at *dodo.py* | ||
-------------------------- | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,13 +128,22 @@ config plugin | |
|
||
To enable a plugin create a section named after the plugin category. | ||
The value is an entry point to the python class/function/object | ||
that implements the plugin. The format is <module-name>:<attribute-name>. | ||
that implements the plugin. The format is `<module-name>:<attribute-name>`. | ||
|
||
Example of command plugin implemented in the *class* `FooCmd`, | ||
located at the module `my_plugins.py`:: | ||
Example of command plugin configured in `pyproject.toml`, implemented in | ||
the *class* `FooCmd`, located at the module `my_plugins.py`: | ||
|
||
[COMMAND] | ||
foo = my_plugins:FooCmd | ||
.. code-block:: toml | ||
|
||
[tools.doit.plugins] | ||
COMMAND = { foo = "my_plugins:FooCmd" } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what about?
Better name for "obj" ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, naming things is hard. If it was purely data, the more verbose form would feel good, but i think in this case spareness wins. I believe this could also be written [tool.doit.plugins.COMMAND]
foo = "my_plugins:FooCmd" (have updated docs to reflect both) |
||
|
||
Similarly, in `doit.cfg`: | ||
|
||
.. code-block:: ini | ||
|
||
[COMMAND] | ||
foo = my_plugins:FooCmd | ||
|
||
.. note:: | ||
|
||
|
@@ -171,13 +180,23 @@ Creates a custom task loader. Check :ref:`loader <custom_loader>` section | |
for details on how to create a new command. | ||
|
||
Apart from getting the plugin you also need to indicate which loader will be | ||
used in the `GLOBAL` section of your config file. | ||
used. In the `tool.doit` section in `pyproject.toml`: | ||
|
||
.. code-block:: toml | ||
|
||
.. code-block:: INI | ||
[tool.doit] | ||
loader = "my_loader" | ||
|
||
[tool.doit.plugins] | ||
LOADER = { my_loader = "my_plugins:Loader" } | ||
|
||
|
||
In the `GLOBAL` section of `doit.cfg`: | ||
|
||
.. code-block:: ini | ||
|
||
[GLOBAL] | ||
loader = my_loader | ||
|
||
[LOADER] | ||
my_loader = my_plugins:MyLoader | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? I think this is in anti-feature. And I could not see where this comes from, all python libs work like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a hangover from being able to reuse the existing
.ini
parsing logic, which only speaks string.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh. i see... I think that is not acceptable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Welp, that
config
object (wherever it gets read from or built dynamically) gets handed around throughout the entire running application, it appears, and (only) thecmd_options
know how to do the marshaling. It seems like changing (or even detecting the use of) that behavior would require deprecation of the ini format altogether, and a formal data schema throughout all these things... sounds very 1.0ish.