From 0c96a311d6ffd075c8a0fd0c16a21f35a670b622 Mon Sep 17 00:00:00 2001 From: cernst72 Date: Sun, 9 Nov 2025 15:49:20 +0100 Subject: [PATCH] feat(config): move configuration file fixes #11 New lookup scheme for configuration file: 1. `$VJA_CONFIGDIR/config.rc` 2. `$XDG_CONFIG_HOME/vja/config.rc` 3. `$HOME/.config/vja/config.rc` 4. `$HOME/.vjacli/vja.rc` (deprecated - for backward compatibility --- .vjacli/vja.rc => .config/vja/config.rc | 0 CHANGELOG.md | 4 +- README.md | 23 ++++++----- requirements_dev.txt | 2 +- tests/.vjatest/{vja.rc => config.rc} | 0 tests/.vjatest_dind/{vja.rc => config.rc} | 0 vja/config.py | 48 +++++++++++++++++++++-- 7 files changed, 61 insertions(+), 16 deletions(-) rename .vjacli/vja.rc => .config/vja/config.rc (100%) mode change 100755 => 100644 rename tests/.vjatest/{vja.rc => config.rc} (100%) rename tests/.vjatest_dind/{vja.rc => config.rc} (100%) diff --git a/.vjacli/vja.rc b/.config/vja/config.rc old mode 100755 new mode 100644 similarity index 100% rename from .vjacli/vja.rc rename to .config/vja/config.rc diff --git a/CHANGELOG.md b/CHANGELOG.md index fae8207..e478eed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,8 +2,8 @@ ### Features -* **ls:** add custom formats "updated" and "created" ([caa2b62](https://gitlab.com/ce72/vja/commit/caa2b6255ef02a4a288ab01aa07e5ce7b101e1ba)) -* **ls:** output of task count must now be activated with -v flag ([8a7216b](https://gitlab.com/ce72/vja/commit/8a7216b44e8bdf268cecd9979ddd6fd8108baa6c)) +* **task ls:** add custom formats "updated" and "created" ([caa2b62](https://gitlab.com/ce72/vja/commit/caa2b6255ef02a4a288ab01aa07e5ce7b101e1ba)) +* **task ls:** output of task count must now be activated with -v flag ([8a7216b](https://gitlab.com/ce72/vja/commit/8a7216b44e8bdf268cecd9979ddd6fd8108baa6c)) ### Misc diff --git a/README.md b/README.md index 067748c..d8459d4 100755 --- a/README.md +++ b/README.md @@ -5,15 +5,14 @@ [![pipeline status](https://gitlab.com/ce72/vja/badges/main/pipeline.svg)](https://gitlab.com/ce72/vja/-/pipelines) [![coverage report](https://gitlab.com/ce72/vja/badges/main/coverage.svg)](https://gitlab.com/ce72/vja/commits/main) -This is a simple CLI for Vikunja > [The todo app to organize your life.](https://vikunja.io/) +A command line interface for Vikunja > [The todo app to organize your life](https://vikunja.io/). +Manage your tasks and projects directly from the terminal with simple commands. It provides a command line interface for adding, viewing and editing todo tasks on a Vikunja Server. The goal is to support a command line based task workflow ~ similar to taskwarrior. -#### Breaking changes in vja 4.0 - -vja 4.0 supports (and requires) the most recent Vikunja API >= 0.24.0. -Use vja up to version 3.3.1 for compatibility with Vikunja API 0.23.0. +#### Important change in vja 4.9 +New name for configuration file (`config.rc`) and XDG conform path lookup, see [Configuration](#configuration) ## Usage @@ -48,22 +47,28 @@ Not recommended as it might break system dependencies. ## Configuration Before using vja you must provide a configuration. -An example can be found in [vja.rc](https://gitlab.com/ce72/vja/-/blob/main/.vjacli/vja.rc). +vja looks for its configuration at the following paths (in order): +1. `$VJA_CONFIGDIR/config.rc` +2. `$XDG_CONFIG_HOME/vja/config.rc` +3. `$HOME/.config/vja/config.rc` +4. `$HOME/.vjacli/vja.rc` (deprecated - for backward compatibility only) + +A full example can be found in [config.rc](https://gitlab.com/ce72/vja/-/blob/main/.config/vja/config.rc). -- Create a configuration file $HOME/.vjacli/vja.rc with ~ the following contents +- Create a configuration file at any valid path (see above) with ~ the following contents ```shell [application] frontend_url=https://try.vikunja.io/ api_url=https://try.vikunja.io/api/v1 ``` - (If you cloned from git, you may copy the folder .vjacli to your `$HOME` directory instead.) + (If you cloned from git, you may copy the folder `.config/vja` to your `$HOME/.config` directory instead.) - Adjust to your needs. `frontend_url` and `api_url` must point to your own Vikunja server. Especially, the api_url must be reachable from your client. This can be verified, for example, by `curl https://mydomain.com/api/v1/info`. You may change the location of the configuration directory with an environment variable -like `VJA_CONFIGDIR=/not/my/home` +like `VJA_CONFIGDIR=/not/my/home`. ### Description of configuration diff --git a/requirements_dev.txt b/requirements_dev.txt index 4113a4f..b11d35c 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -1,4 +1,4 @@ -pip==25.2 +pip==25.3 pylint==4.0.2 flake8==7.3.0 pytest==8.4.2 diff --git a/tests/.vjatest/vja.rc b/tests/.vjatest/config.rc similarity index 100% rename from tests/.vjatest/vja.rc rename to tests/.vjatest/config.rc diff --git a/tests/.vjatest_dind/vja.rc b/tests/.vjatest_dind/config.rc similarity index 100% rename from tests/.vjatest_dind/vja.rc rename to tests/.vjatest_dind/config.rc diff --git a/vja/config.py b/vja/config.py index 0c0493b..67db3fe 100755 --- a/vja/config.py +++ b/vja/config.py @@ -1,21 +1,22 @@ import configparser import logging import os +from pathlib import Path from vja import VjaError logger = logging.getLogger(__name__) -_DEFAULT_CONFIGDIR = os.path.expanduser("~/.vjacli") -_FILENAME = "vja.rc" +_FILENAME = "config.rc" +_FILENAME_LEGACY = "vja.rc" _TOKEN_JSON = "token.json" class VjaConfiguration: def __init__(self): - self._directory = os.environ.get("VJA_CONFIGDIR", _DEFAULT_CONFIGDIR) - self._file = os.path.join(self._directory, _FILENAME) + self._directory = self.find_config_path() + self._file = self.get_config_file() self._parser = self._load(self._file) @property @@ -46,6 +47,45 @@ class VjaConfiguration: except (configparser.NoSectionError, configparser.NoOptionError): return {} + @staticmethod + def find_config_path() -> Path: + # 1) $VJA_CONFIGDIR + vja_configdir = os.getenv("VJA_CONFIGDIR") + if vja_configdir: + config_path = Path(vja_configdir).expanduser() + candidate = config_path / "config.rc" + if candidate.is_file(): + return config_path + + # 2) $XDG_CONFIG_HOME/vja/config.rc + xdg_config_home = os.getenv("XDG_CONFIG_HOME") + if xdg_config_home: + config_path = Path(xdg_config_home).expanduser() / "vja" + if config_path.is_dir(): + candidate = config_path / "config.rc" + if candidate.is_file(): + return config_path + + # 3) $HOME/.config/vja/config.rc + home = os.getenv("HOME") or str(Path.home()) + config_path = Path(home).expanduser() / ".config" / "vja" + candidate = config_path / "config.rc" + if candidate.is_file(): + return config_path + + # 4) Legacy: $HOME/.vjacli/vja.rc + return Path.home().expanduser() / ".vjacli" + + def get_config_file(self) -> Path: + if self._directory.name != ".vjacli": + return self._directory / _FILENAME + logger.info( + "Using legacy config path %s. Please move your config file (and token.json) to %s.", + os.path.abspath(self._directory / _FILENAME_LEGACY), + os.path.abspath(self._directory.parent / ".config" / "vja" / _FILENAME), + ) + return self._directory / _FILENAME_LEGACY + @staticmethod def _load(filepath): logger.debug("Read config from %s", os.path.abspath(filepath)) -- GitLab