mirror of
https://github.com/yusufipk/dikte.git
synced 2026-09-11 10:56:10 +00:00
Twenty-two files at the top of the tree was the first thing anybody saw of this repository. They are one package now, imported relatively, and the three scripts that are not the front door moved under scripts/. install.sh stays where the README has always said it is. What starts the application is dikte/__main__.py: python3 -m dikte runs it, and so does naming the file, which is what the launcher symlink, both .desktop files, the macOS bundle and every registered shortcut do. Run by path there is no package around it, so it puts the checkout on sys.path itself. The installers now keep the keys you chose when they are given none, which is what an update is: update.sh no longer has to read them out and pass them back. An updater from before this commit cannot read them at all, so the one thing it can say, the default key with an empty discard key, is read as "nothing was asked for" rather than obeyed. That guard can go once nobody is updating across this commit.
63 lines
2.4 KiB
Python
63 lines
2.4 KiB
Python
"""Where the settings and the data are kept, per system.
|
|
|
|
Its own file because the answer has to be one answer: config.py and ggml.py
|
|
both need it, and when each worked it out for itself only one of them knew
|
|
about macOS.
|
|
"""
|
|
|
|
import os
|
|
import unittest
|
|
from unittest import mock
|
|
|
|
from dikte import config as cfg
|
|
from dikte import ggml
|
|
from dikte import paths
|
|
|
|
|
|
class Directories(unittest.TestCase):
|
|
def test_linux_keeps_them_apart_and_follows_xdg(self):
|
|
with mock.patch.dict(os.environ, {"XDG_CONFIG_HOME": "/c",
|
|
"XDG_DATA_HOME": "/d"}):
|
|
config_dir, data_dir = paths.directories("linux")
|
|
self.assertEqual(str(config_dir), "/c/dikte")
|
|
self.assertEqual(str(data_dir), "/d/dikte")
|
|
|
|
def test_linux_without_the_variables_set(self):
|
|
with mock.patch.dict(os.environ, {}, clear=True):
|
|
config_dir, data_dir = paths.directories("linux")
|
|
self.assertTrue(str(config_dir).endswith("/.config/dikte"))
|
|
self.assertTrue(str(data_dir).endswith("/.local/share/dikte"))
|
|
|
|
def test_a_mac_keeps_both_in_application_support(self):
|
|
config_dir, data_dir = paths.directories("darwin")
|
|
self.assertEqual(config_dir, data_dir)
|
|
self.assertTrue(str(config_dir).endswith("/Library/Application Support/Dikte"))
|
|
|
|
def test_a_mac_does_not_read_the_xdg_variables(self):
|
|
"""A Mac with them set from some other tool still stores in one place."""
|
|
with mock.patch.dict(os.environ, {"XDG_CONFIG_HOME": "/c"}):
|
|
config_dir, _ = paths.directories("darwin")
|
|
self.assertNotIn("/c", str(config_dir))
|
|
|
|
|
|
class OnePlace(unittest.TestCase):
|
|
"""The programs and the models go where everything else goes.
|
|
|
|
ggml.py used to read XDG_DATA_HOME itself, which is right on Linux and
|
|
wrong on a Mac: the settings and the dictations went to ~/Library while
|
|
several gigabytes of models went to ~/.local/share, where no Mac user looks
|
|
and where `uninstall.sh --purge` would never have found them.
|
|
"""
|
|
|
|
def test_the_models_live_under_the_data_directory(self):
|
|
self.assertEqual(ggml.DATA_DIR, paths.DATA_DIR)
|
|
self.assertEqual(ggml.MODELS_DIR.parent, paths.DATA_DIR)
|
|
self.assertEqual(ggml.BIN_DIR.parent, paths.DATA_DIR)
|
|
|
|
def test_config_and_ggml_cannot_disagree(self):
|
|
self.assertEqual(cfg.DATA_DIR, ggml.DATA_DIR)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|