Skip to content

Commit

Permalink
Use platformdirs to determine config and data paths on different plat…
Browse files Browse the repository at this point in the history
…forms and adhere to the XDG Base Directory specification.
  • Loading branch information
Bzero committed Nov 10, 2024
1 parent e299c87 commit 27c0353
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ Typstwriter looks for configuration files in the following locations:

* /etc/typstwriter/typstwriter.ini
* /usr/local/etc/typstwriter/typstwriter.ini
* ~/.config/typstwriter/typstwriter.ini
* Platform specific configuration directory:
* $XDG_CONFIG_HOME/typstwriter/typstwriter.ini
* %USERPROFILE%\AppData\Local\typstwriter\typstwriter\typstwriter.ini
* ~/.typstwriter.ini
* ./typstwriter.ini

Expand Down
2 changes: 1 addition & 1 deletion docs/example_config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ show_compiler_output = True

[Internals]
# The path where the list of recent files will be saved
recent_files_path = ~/.config/typstwriter/recentFiles.txt
recent_files_path = ~/.local/share/typstwriter/recentFiles.txt
# The number of recently opened files to remember
recent_files_length = 16
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies = [
"qtpy >= 2.3",
"pyside6 >= 6.4.0",
"pygments >= 2.18",
"platformdirs >= 4.0"
]
dynamic = ["version"]

Expand Down
7 changes: 5 additions & 2 deletions typstwriter/configuration.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import os
import configparser

import platformdirs

from typstwriter import logging

logger = logging.getLogger(__name__)


default_config_path = os.path.expanduser("~/.config/typstwriter/typstwriter.ini")
default_config_path = os.path.join(platformdirs.user_config_dir("typstwriter", "typstwriter"), "typstwriter.ini")
default_recent_files_path = os.path.join(platformdirs.user_data_dir("typstwriter", "typstwriter"), "recentFiles.txt")

config_paths = ["/etc/typstwriter/typstwriter.ini",
"/usr/local/etc/typstwriter/typstwriter.ini",
Expand All @@ -28,7 +31,7 @@
"show_fs_explorer": True,
"show_compiler_options": True,
"show_compiler_output": True},
"Internals": {"recent_files_path": "~/.config/typstwriter/recentFiles.txt",
"Internals": {"recent_files_path": default_recent_files_path,
"recent_files_length": 16}} # fmt: skip


Expand Down

0 comments on commit 27c0353

Please sign in to comment.