Skip to content

Commit 282e22c

Browse files
authored
Add platformdirs as an optional dependency (#439)
1 parent 0960e88 commit 282e22c

File tree

7 files changed

+30
-9
lines changed

7 files changed

+30
-9
lines changed

docs/changelog.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
ITables ChangeLog
22
=================
33

4+
2.5.2-dev (2025-09-02)
5+
------------------
6+
7+
**Fixed**
8+
- `platformdirs` is an optional dependency of ITables ([#437](https://github.com/mwouts/itables/issues/437))
9+
10+
411
2.5.1 (2025-08-31)
512
------------------
613

docs/options/options.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ itables.options.maxBytes = "128KB"
4242

4343
## Configuration File
4444

45-
Since v2.5.0, ITable can load its default options from a configuration file. 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:
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:
4648

4749
- 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)
4850
- An `itables.toml` file in the current or a parent directory

docs/py/options/options.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@
4444
#
4545
# ## Configuration File
4646
#
47-
# Since v2.5.0, ITable can load its default options from a configuration file. 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:
47+
# 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]`.
48+
#
49+
# 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:
4850
#
4951
# - 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)
5052
# - An `itables.toml` file in the current or a parent directory

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ dependencies = ["IPython", "pandas", "numpy"]
3131
dynamic = ["version"]
3232

3333
[project.optional-dependencies]
34-
config = ["tomli;python_version<\"3.11\""]
34+
config = ["tomli;python_version<\"3.11\"", "platformdirs"]
3535
polars = ["polars", "pyarrow"]
3636
check_type = ["typeguard>=4.4.1"]
3737
style = ["matplotlib"]

src/itables/config.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@
2121
except ImportError:
2222
tomllib = None # type: ignore[assignment]
2323

24-
from platformdirs import user_config_path
24+
try:
25+
from platformdirs import user_config_path
26+
except ImportError:
27+
user_config_path = None
2528

2629
from itables.typing import ITableOptions, check_itable_arguments
2730

@@ -62,9 +65,10 @@ def get_config_file(path: Path = Path.cwd()) -> Optional[Path]:
6265
if parent in ceiling_directories:
6366
break
6467

65-
config_file = user_config_path("itables") / "itables.toml"
66-
if config_file.exists():
67-
return config_file
68+
if user_config_path is not None:
69+
config_file = user_config_path("itables") / "itables.toml"
70+
if config_file.exists():
71+
return config_file
6872

6973
return None
7074

src/itables/show_config.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,19 @@
66

77
from pathlib import Path
88

9-
from itables.config import get_config_file, load_config_file
9+
from itables.config import get_config_file, load_config_file, tomllib, user_config_path
1010

1111

1212
def show_config(path: Path):
1313
"""
1414
Show the ITables config file location and content.
1515
"""
16+
if (tomllib is None) or (user_config_path is None):
17+
print(
18+
"Missing itables[config] dependencies. Please install them with 'pip install itables[config]'"
19+
)
20+
return
21+
1622
if (config_file := get_config_file(path)) is None:
1723
print("No ITables config file found")
1824
return

src/itables/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""ITables' version number"""
22

3-
__version__ = "2.5.1"
3+
__version__ = "2.5.2-dev"

0 commit comments

Comments
 (0)