alpaca: 1.0.1 -> 1.0.5
This commit is contained in:
parent
2bba36f6df
commit
648fefc4dd
@ -1,26 +0,0 @@
|
|||||||
diff --git a/src/alpaca.in b/src/alpaca.in
|
|
||||||
index cb883c8..a9822cc 100755
|
|
||||||
--- a/src/alpaca.in
|
|
||||||
+++ b/src/alpaca.in
|
|
||||||
@@ -35,7 +35,21 @@ locale.bindtextdomain('alpaca', localedir)
|
|
||||||
locale.textdomain('alpaca')
|
|
||||||
gettext.install('alpaca', localedir)
|
|
||||||
|
|
||||||
+# Use the right XDG paths outside flatpak
|
|
||||||
+def set_xdg_path(env, default):
|
|
||||||
+ app_id = "com.jeffser.Alpaca"
|
|
||||||
+ base = os.getenv(env) or os.path.expanduser(default)
|
|
||||||
+ path = os.path.join(base, app_id)
|
|
||||||
+ if not os.path.exists(path):
|
|
||||||
+ os.makedirs(path)
|
|
||||||
+ os.environ[env] = path
|
|
||||||
+ return
|
|
||||||
+
|
|
||||||
if __name__ == '__main__':
|
|
||||||
+ set_xdg_path("XDG_CONFIG_HOME", "~/.config")
|
|
||||||
+ set_xdg_path("XDG_DATA_HOME", "~/.local/share")
|
|
||||||
+ set_xdg_path("XDG_CACHE_HOME", "~/.cache")
|
|
||||||
+
|
|
||||||
import gi
|
|
||||||
|
|
||||||
from gi.repository import Gio
|
|
159
pkgs/by-name/al/alpaca/flatpak_path_fixes.patch
Normal file
159
pkgs/by-name/al/alpaca/flatpak_path_fixes.patch
Normal file
@ -0,0 +1,159 @@
|
|||||||
|
diff --git a/src/internal.py b/src/internal.py
|
||||||
|
new file mode 100644
|
||||||
|
index 0000000..b41e415
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/src/internal.py
|
||||||
|
@@ -0,0 +1,22 @@
|
||||||
|
+import os
|
||||||
|
+
|
||||||
|
+app_id = "com.jeffser.Alpaca"
|
||||||
|
+
|
||||||
|
+in_flatpak = True if os.getenv("FLATPAK_ID") else False
|
||||||
|
+
|
||||||
|
+def get_xdg_home(env, default):
|
||||||
|
+ if in_flatpak:
|
||||||
|
+ return os.getenv(env)
|
||||||
|
+ else:
|
||||||
|
+ base = os.getenv(env) or os.path.expanduser(default)
|
||||||
|
+ path = os.path.join(base, app_id)
|
||||||
|
+ if not os.path.exists(path):
|
||||||
|
+ os.makedirs(path)
|
||||||
|
+ return path
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+data_dir = get_xdg_home("XDG_DATA_HOME", "~/.local/share")
|
||||||
|
+config_dir = get_xdg_home("XDG_CONFIG_HOME", "~/.config")
|
||||||
|
+cache_dir = get_xdg_home("XDG_CACHE_HOME", "~/.cache")
|
||||||
|
+
|
||||||
|
+source_dir = os.path.abspath(os.path.dirname(__file__))
|
||||||
|
diff --git a/src/local_instance.py b/src/local_instance.py
|
||||||
|
index cb3ee51..1866f83 100644
|
||||||
|
--- a/src/local_instance.py
|
||||||
|
+++ b/src/local_instance.py
|
||||||
|
@@ -2,24 +2,24 @@
|
||||||
|
import subprocess, os, threading
|
||||||
|
from time import sleep
|
||||||
|
from logging import getLogger
|
||||||
|
+from .internal import data_dir, cache_dir
|
||||||
|
|
||||||
|
|
||||||
|
logger = getLogger(__name__)
|
||||||
|
|
||||||
|
instance = None
|
||||||
|
port = 11435
|
||||||
|
-data_dir = os.getenv("XDG_DATA_HOME")
|
||||||
|
overrides = {}
|
||||||
|
|
||||||
|
def start():
|
||||||
|
- if not os.path.isdir(os.path.join(os.getenv("XDG_CACHE_HOME"), 'tmp/ollama')):
|
||||||
|
- os.mkdir(os.path.join(os.getenv("XDG_CACHE_HOME"), 'tmp/ollama'))
|
||||||
|
+ if not os.path.isdir(os.path.join(cache_dir, 'tmp/ollama')):
|
||||||
|
+ os.mkdir(os.path.join(cache_dir, 'tmp/ollama'))
|
||||||
|
global instance, overrides
|
||||||
|
params = overrides.copy()
|
||||||
|
params["OLLAMA_HOST"] = f"127.0.0.1:{port}" # You can't change this directly sorry :3
|
||||||
|
params["HOME"] = data_dir
|
||||||
|
- params["TMPDIR"] = os.path.join(os.getenv("XDG_CACHE_HOME"), 'tmp/ollama')
|
||||||
|
- instance = subprocess.Popen(["/app/bin/ollama", "serve"], env={**os.environ, **params}, stderr=subprocess.PIPE, text=True)
|
||||||
|
+ params["TMPDIR"] = os.path.join(cache_dir, 'tmp/ollama')
|
||||||
|
+ instance = subprocess.Popen(["ollama", "serve"], env={**os.environ, **params}, stderr=subprocess.PIPE, text=True)
|
||||||
|
logger.info("Starting Alpaca's Ollama instance...")
|
||||||
|
logger.debug(params)
|
||||||
|
sleep(1)
|
||||||
|
diff --git a/src/main.py b/src/main.py
|
||||||
|
index 278914f..eeb54cd 100644
|
||||||
|
--- a/src/main.py
|
||||||
|
+++ b/src/main.py
|
||||||
|
@@ -27,6 +27,7 @@ gi.require_version('Adw', '1')
|
||||||
|
|
||||||
|
from gi.repository import Gtk, Gio, Adw, GLib
|
||||||
|
from .window import AlpacaWindow
|
||||||
|
+from .internal import cache_dir, data_dir
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
@@ -63,7 +64,7 @@ class AlpacaApplication(Adw.Application):
|
||||||
|
issue_url='https://github.com/Jeffser/Alpaca/issues',
|
||||||
|
license_type=3,
|
||||||
|
website="https://jeffser.com/alpaca",
|
||||||
|
- debug_info=open(os.path.join(os.getenv("XDG_DATA_HOME"), 'tmp.log'), 'r').read())
|
||||||
|
+ debug_info=open(os.path.join(data_dir, 'tmp.log'), 'r').read())
|
||||||
|
about.present(parent=self.props.active_window)
|
||||||
|
|
||||||
|
def create_action(self, name, callback, shortcuts=None):
|
||||||
|
@@ -75,16 +76,16 @@ class AlpacaApplication(Adw.Application):
|
||||||
|
|
||||||
|
|
||||||
|
def main(version):
|
||||||
|
- if os.path.isfile(os.path.join(os.getenv("XDG_DATA_HOME"), 'tmp.log')):
|
||||||
|
- os.remove(os.path.join(os.getenv("XDG_DATA_HOME"), 'tmp.log'))
|
||||||
|
- if os.path.isdir(os.path.join(os.getenv("XDG_CACHE_HOME"), 'tmp')):
|
||||||
|
- os.system('rm -rf ' + os.path.join(os.getenv("XDG_CACHE_HOME"), "tmp/*"))
|
||||||
|
+ if os.path.isfile(os.path.join(data_dir, 'tmp.log')):
|
||||||
|
+ os.remove(os.path.join(data_dir, 'tmp.log'))
|
||||||
|
+ if os.path.isdir(os.path.join(cache_dir, 'tmp')):
|
||||||
|
+ os.system('rm -rf ' + os.path.join(cache_dir, "tmp/*"))
|
||||||
|
else:
|
||||||
|
- os.mkdir(os.path.join(os.getenv("XDG_CACHE_HOME"), 'tmp'))
|
||||||
|
+ os.mkdir(os.path.join(cache_dir, 'tmp'))
|
||||||
|
logging.basicConfig(
|
||||||
|
format="%(levelname)s\t[%(filename)s | %(funcName)s] %(message)s",
|
||||||
|
level=logging.INFO,
|
||||||
|
- handlers=[logging.FileHandler(filename=os.path.join(os.getenv("XDG_DATA_HOME"), 'tmp.log')), logging.StreamHandler(stream=sys.stdout)]
|
||||||
|
+ handlers=[logging.FileHandler(filename=os.path.join(data_dir, 'tmp.log')), logging.StreamHandler(stream=sys.stdout)]
|
||||||
|
)
|
||||||
|
app = AlpacaApplication(version)
|
||||||
|
logger.info(f"Alpaca version: {app.version}")
|
||||||
|
diff --git a/src/meson.build b/src/meson.build
|
||||||
|
index 1781b7a..b212cbf 100644
|
||||||
|
--- a/src/meson.build
|
||||||
|
+++ b/src/meson.build
|
||||||
|
@@ -44,7 +44,8 @@ alpaca_sources = [
|
||||||
|
'local_instance.py',
|
||||||
|
'available_models.json',
|
||||||
|
'available_models_descriptions.py',
|
||||||
|
- 'table_widget.py'
|
||||||
|
+ 'table_widget.py',
|
||||||
|
+ 'internal.py'
|
||||||
|
]
|
||||||
|
|
||||||
|
install_data(alpaca_sources, install_dir: moduledir)
|
||||||
|
diff --git a/src/window.py b/src/window.py
|
||||||
|
index 0771919..0f3b892 100644
|
||||||
|
--- a/src/window.py
|
||||||
|
+++ b/src/window.py
|
||||||
|
@@ -29,20 +29,21 @@ from pypdf import PdfReader
|
||||||
|
from datetime import datetime
|
||||||
|
from . import dialogs, local_instance, connection_handler, available_models_descriptions
|
||||||
|
from .table_widget import TableWidget
|
||||||
|
+from .internal import config_dir, data_dir, cache_dir, source_dir
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@Gtk.Template(resource_path='/com/jeffser/Alpaca/window.ui')
|
||||||
|
class AlpacaWindow(Adw.ApplicationWindow):
|
||||||
|
- config_dir = os.getenv("XDG_CONFIG_HOME")
|
||||||
|
- data_dir = os.getenv("XDG_DATA_HOME")
|
||||||
|
app_dir = os.getenv("FLATPAK_DEST")
|
||||||
|
- cache_dir = os.getenv("XDG_CACHE_HOME")
|
||||||
|
+ config_dir = config_dir
|
||||||
|
+ data_dir = data_dir
|
||||||
|
+ cache_dir = cache_dir
|
||||||
|
|
||||||
|
__gtype_name__ = 'AlpacaWindow'
|
||||||
|
|
||||||
|
- localedir = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'locale')
|
||||||
|
+ localedir = os.path.join(source_dir, 'locale')
|
||||||
|
|
||||||
|
gettext.bindtextdomain('com.jeffser.Alpaca', localedir)
|
||||||
|
gettext.textdomain('com.jeffser.Alpaca')
|
||||||
|
@@ -1602,7 +1603,7 @@ Generate a title following these rules:
|
||||||
|
def __init__(self, **kwargs):
|
||||||
|
super().__init__(**kwargs)
|
||||||
|
GtkSource.init()
|
||||||
|
- with open('/app/share/Alpaca/alpaca/available_models.json', 'r') as f:
|
||||||
|
+ with open(os.path.join(source_dir, 'available_models.json'), 'r') as f:
|
||||||
|
self.available_models = json.load(f)
|
||||||
|
if not os.path.exists(os.path.join(self.data_dir, "chats")):
|
||||||
|
os.makedirs(os.path.join(self.data_dir, "chats"))
|
@ -17,28 +17,22 @@
|
|||||||
|
|
||||||
python3Packages.buildPythonApplication rec {
|
python3Packages.buildPythonApplication rec {
|
||||||
pname = "alpaca";
|
pname = "alpaca";
|
||||||
version = "1.0.1";
|
version = "1.0.5";
|
||||||
pyproject = false; # Built with meson
|
pyproject = false; # Built with meson
|
||||||
|
|
||||||
src = fetchFromGitHub {
|
src = fetchFromGitHub {
|
||||||
owner = "Jeffser";
|
owner = "Jeffser";
|
||||||
repo = "Alpaca";
|
repo = "Alpaca";
|
||||||
rev = version;
|
rev = version;
|
||||||
hash = "sha256-GxnYPnrjaJ47/i+pigw+on2dmbHwQSX+STasvqnAtuQ=";
|
hash = "sha256-xNQLaMvZaJq7Bmz+c8OQhta3IdFXpVB2bSNwXCRj6rY=";
|
||||||
};
|
};
|
||||||
|
|
||||||
patches = [
|
patches = [
|
||||||
# Change the way XDG paths are handled so it makes sense outside of flatpak
|
# Change the way XDG paths are handled so it makes sense outside of flatpak
|
||||||
./fix_xdg_path_flatpak.patch
|
# https://github.com/Jeffser/Alpaca/pull/187
|
||||||
|
./flatpak_path_fixes.patch
|
||||||
];
|
];
|
||||||
|
|
||||||
postPatch = ''
|
|
||||||
substituteInPlace src/local_instance.py \
|
|
||||||
--replace-fail '/app/bin/ollama' 'ollama'
|
|
||||||
substituteInPlace src/window.py \
|
|
||||||
--replace-fail '/app/share' "$out/share"
|
|
||||||
'';
|
|
||||||
|
|
||||||
nativeBuildInputs = [
|
nativeBuildInputs = [
|
||||||
appstream
|
appstream
|
||||||
meson
|
meson
|
||||||
|
Loading…
Reference in New Issue
Block a user