Skip to content

Commit 691a4ab

Browse files
author
Patrick Lenihan
committed
Switched to using Poetry script
1 parent 9f526fa commit 691a4ab

File tree

5 files changed

+58
-65
lines changed

5 files changed

+58
-65
lines changed

Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
all: build
44
build: aw-server aw-sync
5-
python scripts/copy_rust_binaries.py target/$(targetdir)
65

76
DESTDIR :=
87
ifeq ($(SUDO_USER),)
@@ -23,6 +22,7 @@ endif
2322

2423
aw-server: set-version aw-webui
2524
cargo build $(cargoflag) --bin aw-server
25+
poetry install --directory python
2626

2727
aw-sync: set-version
2828
cargo build $(cargoflag) --bin aw-sync
@@ -108,5 +108,5 @@ install:
108108
install -m 644 aw-server.service $(DESTDIR)$(PREFIX)/lib/systemd/user/aw-server.service
109109

110110
clean:
111-
python scripts/copy_rust_binaries.py --clean target/$(targetdir)
111+
rm -rf __pycache__ python/__pycache__
112112
cargo clean

python/aw_server_rust.py

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env python3
2+
3+
import os
4+
import sys
5+
import subprocess
6+
7+
def find_rust_binary():
8+
"""Finds the Rust binary in the target directory."""
9+
10+
repo_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
11+
target = "debug" if os.getenv("RELEASE", "") == "false" else "release"
12+
13+
rust_binary = os.path.join(repo_root, "target", target, "aw-server")
14+
15+
if os.path.exists(rust_binary):
16+
return rust_binary
17+
18+
print(f"Error: Rust binary '{rust_binary}' not found. Did you run `cargo build --release`?", file=sys.stderr)
19+
sys.exit(1)
20+
21+
def main():
22+
"""Executes the Rust binary and forwards all arguments."""
23+
rust_binary = find_rust_binary()
24+
if os.name == "posix":
25+
# Replace current Python process with rust binary
26+
os.execvp(rust_binary, (rust_binary, *sys.argv[1:]))
27+
else:
28+
subprocess.run([rust_binary] + sys.argv[1:])
29+
30+
if __name__ == "__main__":
31+
main()

python/poetry.lock

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

python/pyproject.toml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[tool.poetry]
2+
name = "aw-server-rust"
3+
version = "0.1.0"
4+
description = "Server for ActivityWatch"
5+
authors = ["Erik Bjäreholt <[email protected]>"]
6+
license = "MPL-2.0"
7+
packages = [
8+
{ include = "aw_server_rust.py" }
9+
]
10+
11+
[tool.poetry.scripts]
12+
aw-server-rust = "aw_server_rust:main"
13+
14+
[tool.poetry.dependencies]
15+
16+
[build-system]
17+
requires = ["poetry-core"]
18+
build-backend = "poetry.core.masonry.api"

scripts/copy_rust_binaries.py

-63
This file was deleted.

0 commit comments

Comments
 (0)