diff --git a/Makefile b/Makefile index 32ee5881..e66478d7 100644 --- a/Makefile +++ b/Makefile @@ -22,6 +22,7 @@ endif aw-server: set-version aw-webui cargo build $(cargoflag) --bin aw-server + poetry install --directory python aw-sync: set-version cargo build $(cargoflag) --bin aw-sync @@ -107,4 +108,5 @@ install: install -m 644 aw-server.service $(DESTDIR)$(PREFIX)/lib/systemd/user/aw-server.service clean: + rm -rf __pycache__ python/__pycache__ cargo clean diff --git a/python/aw_server_rust.py b/python/aw_server_rust.py new file mode 100644 index 00000000..e5e7e0cc --- /dev/null +++ b/python/aw_server_rust.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 + +import os +import sys +import subprocess + +def find_rust_binary(): + """Finds the Rust binary in the target directory.""" + + repo_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + target = "debug" if os.getenv("RELEASE", "") == "false" else "release" + + rust_binary = os.path.join(repo_root, "target", target, "aw-server") + + if os.path.exists(rust_binary): + return rust_binary + + print(f"Error: Rust binary '{rust_binary}' not found. Did you run `cargo build --release`?", file=sys.stderr) + sys.exit(1) + +def main(): + """Executes the Rust binary and forwards all arguments.""" + rust_binary = find_rust_binary() + if os.name == "posix": + # Replace current Python process with rust binary + os.execvp(rust_binary, (rust_binary, *sys.argv[1:])) + else: + subprocess.run([rust_binary] + sys.argv[1:]) + +if __name__ == "__main__": + main() diff --git a/python/poetry.lock b/python/poetry.lock new file mode 100644 index 00000000..d196c8d4 --- /dev/null +++ b/python/poetry.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Poetry 2.0.1 and should not be changed by hand. +package = [] + +[metadata] +lock-version = "2.1" +python-versions = "*" +content-hash = "1be3afc87beb00627d70ba9087279825e941f05a562df12e972061262422d79a" diff --git a/python/pyproject.toml b/python/pyproject.toml new file mode 100644 index 00000000..ca30a954 --- /dev/null +++ b/python/pyproject.toml @@ -0,0 +1,18 @@ +[tool.poetry] +name = "aw-server-rust" +version = "0.1.0" +description = "Server for ActivityWatch" +authors = ["Erik Bjäreholt "] +license = "MPL-2.0" +packages = [ + { include = "aw_server_rust.py" } +] + +[tool.poetry.scripts] +aw-server-rust = "aw_server_rust:main" + +[tool.poetry.dependencies] + +[build-system] +requires = ["poetry-core"] +build-backend = "poetry.core.masonry.api"