Skip to content

Commit 4a53f8c

Browse files
authored
Add support for pyproject.toml. (#253)
1 parent 8637853 commit 4a53f8c

30 files changed

+697
-287
lines changed

.pre-commit-config.yaml

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ repos:
4040
- id: pyupgrade
4141
args: [--py37-plus]
4242
- repo: https://github.com/asottile/setup-cfg-fmt
43-
rev: v1.20.0
43+
rev: v1.20.1
4444
hooks:
4545
- id: setup-cfg-fmt
4646
- repo: https://github.com/psf/black
47-
rev: 22.1.0
47+
rev: 22.3.0
4848
hooks:
4949
- id: black
5050
- repo: https://github.com/PyCQA/flake8
@@ -68,7 +68,7 @@ repos:
6868
Pygments,
6969
]
7070
- repo: https://github.com/PyCQA/doc8
71-
rev: 0.10.1
71+
rev: 0.11.1
7272
hooks:
7373
- id: doc8
7474
- repo: https://github.com/asottile/blacken-docs
@@ -107,7 +107,7 @@ repos:
107107
]
108108
additional_dependencies: [
109109
attrs>=19.2.0,
110-
types-click,
110+
click,
111111
types-setuptools
112112
]
113113
pass_filenames: false

docs/rtd_environment.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,17 @@ dependencies:
2020
- sphinx-panels
2121

2222
# Package dependencies necessary for sphinx-click
23-
- attrs >=17.4.0
23+
- attrs >=19.2.0
2424
- click
2525
- click-default-group
26-
- networkx
26+
- networkx >=2.4
2727
- pluggy
2828
- pony >=0.7.15
2929
- pybaum
3030
- pexpect
3131
- rich
32-
- typing-extensions
32+
- tomli >=1.0.0
33+
- tomli-w >=1.0.0
3334

3435
- pip:
3536
- ../

docs/source/changes.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and
3434
- {pull}`245` adds choices on the command line to the help pages as metavars and show
3535
defaults.
3636
- {pull}`246` formalizes choices for {class}`click.Choice` to {class}`enum.Enum`.
37-
- {pull}`248` adds a counter at the bottom of the execution table to show how many tasks
37+
- {pull}`252` adds a counter at the bottom of the execution table to show how many tasks
3838
have been processed.
39+
- {pull}`253` adds support for ``pyproject.toml``.
3940

4041
## 0.1.9 - 2022-02-23
4142

docs/source/how_to_guides/bp_parametrizations.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ First, let us take a look at the folder and file structure of such a project.
2626

2727
```
2828
my_project
29-
├───pytask.ini or tox.ini or setup.cfg
29+
├───pyproject.toml
3030
3131
├───src
3232
│ └───my_project

docs/source/reference_guides/configuration.md

+39-52
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,17 @@
11
# The configuration
22

3-
This document lists all options to configure pytask via the configuration files.
3+
This document lists all options to configure pytask with a `pyproject.toml` file.
44

55
## The basics
66

77
To learn about the basics visit the {doc}`tutorial <../tutorials/configuration>`.
88

9-
## Truthy and falsy values
9+
Examples for the TOML specification be found [here](https://toml.io/en/) or in [PEP
10+
518](https://peps.python.org/pep-0518/).
1011

11-
For some of the configuration values you need truthy or falsy values. pytask recognizes
12-
the following values.
13-
14-
- truthy: `True`, `true`, `1`.
15-
- falsy: `False`, `false`, `0`.
16-
17-
Additionally, the following values are interpreted as None which is neither truthy or
18-
falsy.
19-
20-
- `None`
21-
- `none`
12+
The configuration values are set under the `[tool.pytask.ini_options]` section to mimic
13+
the old ini configurations and to allow pytask leveraging the full potential of the TOML
14+
format in the future.
2215

2316
## The options
2417

@@ -34,7 +27,7 @@ falsy.
3427
If you have very strong reasons for relying on this inaccuracy, although, it is
3528
strongly discouraged, you can deactivate the warning in the configuration file with
3629
37-
.. code-block:: ini
30+
.. code-block:: toml
3831
3932
check_casing_of_paths = false
4033
@@ -52,31 +45,31 @@ falsy.
5245
the modules in which tasks are defined. By default, following the link will open the
5346
module with your default application. It is done with
5447
55-
.. code-block:: ini
48+
.. code-block:: toml
5649
57-
editor_url_scheme = file
50+
editor_url_scheme = "file"
5851
5952
If you use ``vscode`` or ``pycharm`` instead, the file will be opened in the
6053
specified editor and the cursor will also jump to the corresponding line.
6154
62-
.. code-block:: ini
55+
.. code-block:: toml
6356
64-
editor_url_scheme = vscode | pycharm
57+
editor_url_scheme = "vscode" | "pycharm"
6558
6659
For complete flexibility, you can also enter a custom url which can use the
6760
variables ``path`` and ``line_number`` to open the file.
6861
69-
.. code-block:: ini
62+
.. code-block:: toml
7063
71-
editor_url_scheme = editor://{path}:{line_number}
64+
editor_url_scheme = "editor://{path}:{line_number}"
7265
7366
Maybe you want to contribute this URL scheme to make it available to more people.
7467
7568
To disable links, use
7669
77-
.. code-block:: ini
70+
.. code-block:: toml
7871
79-
editor_url_scheme = no_link
72+
editor_url_scheme = "no_link"
8073
8174
```
8275

@@ -95,15 +88,13 @@ falsy.
9588
9689
Or, use the configuration file:
9790
98-
.. code-block:: ini
91+
.. code-block:: toml
9992
10093
# For single entries only.
101-
ignore = some_file.py
94+
ignore = "some_file.py"
10295
10396
# Or single and multiple entries.
104-
ignore =
105-
some_directory/*
106-
some_file.py
97+
ignore = ["some_directory/*", "some_file.py"]
10798
10899
```
109100

@@ -123,10 +114,10 @@ falsy.
123114
silence the warning and document the marker, provide the following information in
124115
your pytask configuration file.
125116
126-
.. code-block:: ini
117+
.. code-block:: toml
127118
128-
markers =
129-
wip: Work-in-progress. These are tasks which I am currently working on.
119+
[tool.pytask.ini_options.markers]
120+
wip = "Work-in-progress. These are tasks which I am currently working on."
130121
131122
```
132123

@@ -143,9 +134,9 @@ falsy.
143134
144135
and in the configuration use
145136
146-
.. code-block:: ini
137+
.. code-block:: toml
147138
148-
n_entries_in_table = all # default 15
139+
n_entries_in_table = "all" # default 15
149140
150141
```
151142

@@ -156,15 +147,13 @@ falsy.
156147
command line, you can add the paths to the configuration file. Paths passed via the
157148
command line will overwrite the configuration value.
158149
159-
.. code-block:: ini
150+
.. code-block:: toml
160151
161152
# For single entries only.
162-
paths = src
153+
paths = "src"
163154
164155
# Or single and multiple entries.
165-
paths =
166-
folder_1
167-
folder_2/task_2.py
156+
paths = ["folder_1", "folder_2/task_2.py"]
168157
169158
```
170159

@@ -180,9 +169,9 @@ falsy.
180169
181170
or use a truthy configuration value.
182171
183-
.. code-block:: ini
172+
.. code-block:: toml
184173
185-
pdb = True
174+
pdb = true
186175
187176
```
188177

@@ -196,9 +185,9 @@ falsy.
196185
197186
pytask build --show-errors-immediately
198187
199-
.. code-block:: ini
188+
.. code-block:: toml
200189
201-
show_errors_immediately = True
190+
show_errors_immediately = true
202191
203192
```
204193

@@ -212,9 +201,9 @@ falsy.
212201
213202
pytask build --show-locals
214203
215-
.. code-block:: ini
204+
.. code-block:: toml
216205
217-
show_locals = True
206+
show_locals = true
218207
219208
```
220209

@@ -229,9 +218,9 @@ falsy.
229218
230219
or set the option to a truthy value.
231220
232-
.. code-block:: ini
221+
.. code-block:: toml
233222
234-
strict_markers = True
223+
strict_markers = true
235224
236225
```
237226

@@ -240,13 +229,11 @@ falsy.
240229
241230
Change the pattern which identify task files.
242231
243-
.. code-block:: ini
232+
.. code-block:: toml
244233
245-
task_files = task_*.py # default
234+
task_files = "task_*.py" # default
246235
247-
task_files =
248-
task_*.py
249-
tasks_*.py
236+
task_files = ["task_*.py", "tasks_*.py"]
250237
251238
```
252239

@@ -261,7 +248,7 @@ falsy.
261248
262249
or set this option to a truthy value.
263250
264-
.. code-block:: ini
251+
.. code-block:: toml
265252
266-
trace = True
253+
trace = true
267254
```

docs/source/tutorials/configuration.md

+32-20
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,55 @@
11
# Configuration
22

33
pytask can be configured via the command-line interface or permanently with a
4-
configuration file.
4+
`pyproject.toml` file.
55

6-
## The configuration file
6+
The file also indicates the root of your project where pytask stores information on
7+
whether tasks need to be executed or not in a `.pytask.sqlite3` database.
78

8-
pytask accepts configurations in three files which are `pytask.ini`, `tox.ini` and
9-
`setup.cfg`. Place a `[pytask]` section in those files and add your configuration below.
9+
:::{important}
10+
pytask.ini, tox.ini, and setup.cfg will be deprecated as configuration files for pytask
11+
starting with v0.3 or v1.0. Switch to a `pyproject.toml` file! If you execute pytask
12+
with an old configuration file, pytask provides you with a copy-paste snippet of your
13+
configuration in the `toml` format to facilitate the transition.
14+
:::
15+
16+
## The configuration file
1017

11-
```ini
12-
# Content of tox.ini
18+
You only need to add the header to the configuration file if you want to indicate the
19+
root of your project.
1320

14-
[pytask]
15-
ignore =
16-
some_path
21+
```toml
22+
[tool.pytask.ini_options]
1723
```
1824

19-
You can also leave the section empty. It will still have the benefit that pytask has a
20-
stable root and will store the information about tasks, dependencies, and products in
21-
the same directory as the configuration file in a database called `.pytask.sqlite3`.
25+
We can also overwrite pytask's behavior of collecting tasks from the current working
26+
directory and, instead, search for paths in a directory called `src` next to the
27+
configuration file.
28+
29+
```toml
30+
[tool.pytask.ini_options]
31+
paths = src
32+
```
2233

2334
## The location
2435

25-
There are two ways to find the configuration file when invoking pytask.
36+
There are two ways to point pytask to the configuration file.
2637

2738
First, it is possible to pass the location of the configuration file via
2839
{option}`pytask build -c` like
2940

3041
```console
31-
$ pytask -c config/pytask.ini
42+
$ pytask -c config/pyproject.toml
3243
```
3344

34-
The second option is to let pytask try to find the configuration itself. pytask will
35-
first look in the current working directory or the common ancestors of multiple paths to
36-
tasks. It will search for `pytask.ini`, `tox.ini` and `setup.cfg` in this order.
37-
Whenever a `[pytask]` section is found, the search stops.
45+
The second option is to let pytask try to find the configuration itself.
3846

39-
If no file is found in the current directory, pytask will climb up the directory tree
40-
and search in parent directories.
47+
1. Find the common base directory of all paths passed to pytask (default to the current
48+
working directory).
49+
2. Starting from this directory, look at all parent directories, and return the file if
50+
it is found.
51+
3. If a directory contains a `.git` directory/file, a `.hg` directory or a valid
52+
configuration file with the right section stop searching.
4153

4254
## The options
4355

0 commit comments

Comments
 (0)