Skip to content

Commit 87c95ee

Browse files
committed
New section on the itables.toml configuration file
1 parent 2383415 commit 87c95ee

File tree

11 files changed

+143
-78
lines changed

11 files changed

+143
-78
lines changed

docs/_toc.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ parts:
1111
- file: apps/streamlit
1212
- file: apps/shiny
1313
- file: apps/quarto
14+
- caption: Configuration
15+
chapters:
16+
- file: configuration
1417
- caption: Options
1518
chapters:
1619
- file: options/options

docs/configuration.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
jupytext:
3+
formats: docs///md:myst,docs/py///py:percent
4+
notebook_metadata_filter: -jupytext.text_representation.jupytext_version
5+
text_representation:
6+
extension: .md
7+
format_name: myst
8+
format_version: 0.13
9+
kernelspec:
10+
display_name: itables
11+
language: python
12+
name: itables
13+
---
14+
15+
# Configuration
16+
17+
ITables exposes many of the `datatables` [options](options/options.md). Since ITables v2.5, the default values for these options can be set in an `itables.toml` configuration file.
18+
19+
## Prerequisites
20+
21+
You will need ITables v2.5 or higher, and two dependencies: either `tomllib` or `tomli`, and `platformdirs`, which can be installed with `pip install itables[config]`.
22+
23+
## Configuration file
24+
25+
The configuration file is identified using `get_config_file` from [`itables.config`](https://github.com/mwouts/itables/blob/main/src/itables/config.py). It can be:
26+
27+
- The file pointed to by the environment variable `ITABLES_CONFIG`, if set and non-empty (if the variable is an empty string, no configuration file is used)
28+
- An `itables.toml` file in the current directory or a parent directory
29+
- A `tool.itables` section in a `pyproject.toml` file in the current directory or a parent directory
30+
31+
## Example configuration
32+
33+
A simple `itables.toml` configuration file that makes the tables a bit more [compact](options/classes.md) looks like this:
34+
```
35+
classes = ["display", "nowrap", "compact"]
36+
```
37+
38+
If you want the Excel export button on each table, add this:
39+
```
40+
buttons = ["pageLength", "copyHtml5", "csvHtml5", "excelHtml5"]
41+
```
42+
43+
And if you want to use the [column control](options/column_control.md) extension:
44+
```
45+
[[columnControl]]
46+
target = 0
47+
content = ["order"]
48+
[[columnControl]]
49+
target = "tfoot"
50+
content = ["search"]
51+
52+
[ordering]
53+
indicators = false
54+
handler = false
55+
```
56+
57+
## Modifying the configuration
58+
59+
The configuration file is loaded when `itables` is imported. If you make changes to the configuration file, these will take effect only when you restart Python and re-import ITables.
60+
61+
You can confirm which configuration file is being used (in a given directory) by running:
62+
```
63+
python -m itables.show_config
64+
```

docs/options/buttons.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ You can also add
4343
```
4444
buttons = ["pageLength", "copyHtml5", "csvHtml5", "excelHtml5"]
4545
```
46-
to your `itables.toml` configuration file.
46+
to your `itables.toml` [configuration file](../configuration.md).
4747

4848

4949
By default, the exported file name is the name of the HTML page. To change it, set a

docs/options/classes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ itables.show(df, classes="display")
4646
itables.show(df, classes="display nowrap cell-border")
4747
```
4848

49-
```tip
50-
You can change the default for all your notebooks and apps by creating an `itables.toml` file in the current or a parent directory, with e.g. this content:
49+
```{tip}
50+
You can change the default for all your notebooks and apps by creating an `itables.toml` [configuration file](../configuration.md) in the current or a parent directory, with e.g. this content:
5151
~~~
5252
classes = ["display", "nowrap", "compact"]
5353
~~~

docs/options/column_control.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ itables.show(
7373
)
7474
```
7575

76-
As usual, you can make this the default by either setting `itables.options.columnControl` in your notebook or application, or by adding this to your `itables.toml` configuration file:
76+
As usual, you can make this the default by either setting `itables.options.columnControl` in your notebook or application, or by adding this to your `itables.toml` [configuration file](../configuration.md):
7777
```
7878
[[columnControl]]
7979
target = 0

docs/options/options.md

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -42,41 +42,7 @@ itables.options.maxBytes = "128KB"
4242

4343
## Configuration File
4444

45-
Since v2.5.0, ITable can load its default options from a configuration file. This requires two dependencies: either `tomllib` or `tomli`, and `platformdirs`, which can be installed with `pip install itables[config]`.
46-
47-
The configuration file is identified using `get_config_file` from [`itables.config`](https://github.com/mwouts/itables/blob/main/src/itables/config.py). It can be:
48-
49-
- The file pointed to by the environment variable `ITABLES_CONFIG`, if set and non-empty (if the variable is an empty string, no configuration file is used)
50-
- An `itables.toml` file in the current or a parent directory
51-
- A `tool.itables` section in a `pyproject.toml` file in the current or a parent directory
52-
53-
A sample configuration file could look like this:
54-
```
55-
# itables.toml
56-
classes = ["display", "nowrap", "compact"]
57-
buttons = ["pageLength", "copyHtml5", "csvHtml5", "excelHtml5"]
58-
```
59-
60-
Add this to use the [column control](column_control.md) extension:
61-
```
62-
[[columnControl]]
63-
target = 0
64-
content = ["order"]
65-
[[columnControl]]
66-
target = "tfoot"
67-
content = ["search"]
68-
69-
[ordering]
70-
indicators = false
71-
handler = false
72-
```
73-
74-
The configuration file is loaded when `itables` is imported - you will need to restart Python and re-import ITables to get the latest configuration.
75-
76-
You can confirm which configuration file is being used (in a given directory) by running
77-
```
78-
python -m itables.show_config
79-
```
45+
You can also change the default options for all your notebooks and applications by creating an `itables.toml` [configuration file](../configuration.md).
8046

8147

8248
## Option Names and Type Checks

docs/py/configuration.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# ---
2+
# jupyter:
3+
# jupytext:
4+
# formats: docs///md:myst,docs/py///py:percent
5+
# notebook_metadata_filter: -jupytext.text_representation.jupytext_version
6+
# text_representation:
7+
# extension: .py
8+
# format_name: percent
9+
# format_version: '1.3'
10+
# kernelspec:
11+
# display_name: itables
12+
# language: python
13+
# name: itables
14+
# ---
15+
16+
# %% [markdown]
17+
# # Configuration
18+
#
19+
# ITables exposes many of the `datatables` [options](options/options.md). Since ITables v2.5, the default values for these options can be set in an `itables.toml` configuration file.
20+
#
21+
# ## Prerequisites
22+
#
23+
# You will need ITables v2.5 or higher, and two dependencies: either `tomllib` or `tomli`, and `platformdirs`, which can be installed with `pip install itables[config]`.
24+
#
25+
# ## Configuration file
26+
#
27+
# The configuration file is identified using `get_config_file` from [`itables.config`](https://github.com/mwouts/itables/blob/main/src/itables/config.py). It can be:
28+
#
29+
# - The file pointed to by the environment variable `ITABLES_CONFIG`, if set and non-empty (if the variable is an empty string, no configuration file is used)
30+
# - An `itables.toml` file in the current directory or a parent directory
31+
# - A `tool.itables` section in a `pyproject.toml` file in the current directory or a parent directory
32+
#
33+
# ## Example configuration
34+
#
35+
# A simple `itables.toml` configuration file that makes the tables a bit more [compact](options/classes.md) looks like this:
36+
# ```
37+
# classes = ["display", "nowrap", "compact"]
38+
# ```
39+
#
40+
# If you want the Excel export button on each table, add this:
41+
# ```
42+
# buttons = ["pageLength", "copyHtml5", "csvHtml5", "excelHtml5"]
43+
# ```
44+
#
45+
# And if you want to use the [column control](options/column_control.md) extension:
46+
# ```
47+
# [[columnControl]]
48+
# target = 0
49+
# content = ["order"]
50+
# [[columnControl]]
51+
# target = "tfoot"
52+
# content = ["search"]
53+
#
54+
# [ordering]
55+
# indicators = false
56+
# handler = false
57+
# ```
58+
#
59+
# ## Modifying the configuration
60+
#
61+
# The configuration file is loaded when `itables` is imported. If you make changes to the configuration file, these will take effect only when you restart Python and re-import ITables.
62+
#
63+
# You can confirm which configuration file is being used (in a given directory) by running:
64+
# ```
65+
# python -m itables.show_config
66+
# ```

docs/py/options/buttons.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
# ```
4545
# buttons = ["pageLength", "copyHtml5", "csvHtml5", "excelHtml5"]
4646
# ```
47-
# to your `itables.toml` configuration file.
47+
# to your `itables.toml` [configuration file](../configuration.md).
4848
#
4949
#
5050
# By default, the exported file name is the name of the HTML page. To change it, set a

docs/py/options/classes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343
itables.show(df, classes="display nowrap cell-border")
4444

4545
# %% [markdown]
46-
# ```tip
47-
# You can change the default for all your notebooks and apps by creating an `itables.toml` file in the current or a parent directory, with e.g. this content:
46+
# ```{tip}
47+
# You can change the default for all your notebooks and apps by creating an `itables.toml` [configuration file](../configuration.md) in the current or a parent directory, with e.g. this content:
4848
# ~~~
4949
# classes = ["display", "nowrap", "compact"]
5050
# ~~~

docs/py/options/column_control.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
)
7575

7676
# %% [markdown]
77-
# As usual, you can make this the default by either setting `itables.options.columnControl` in your notebook or application, or by adding this to your `itables.toml` configuration file:
77+
# As usual, you can make this the default by either setting `itables.options.columnControl` in your notebook or application, or by adding this to your `itables.toml` [configuration file](../configuration.md):
7878
# ```
7979
# [[columnControl]]
8080
# target = 0

0 commit comments

Comments
 (0)