Skip to content

Commit

Permalink
Switched to using Poetry script
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Lenihan committed Feb 3, 2025
1 parent 9f526fa commit 4a3b0b6
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 65 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

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

DESTDIR :=
ifeq ($(SUDO_USER),)
Expand All @@ -23,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
Expand Down Expand Up @@ -108,5 +108,5 @@ install:
install -m 644 aw-server.service $(DESTDIR)$(PREFIX)/lib/systemd/user/aw-server.service

clean:
python scripts/copy_rust_binaries.py --clean target/$(targetdir)
rm -rf __pycache__ python/__pycache__
cargo clean
31 changes: 31 additions & 0 deletions python/aw_server_rust.py
Original file line number Diff line number Diff line change
@@ -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()
7 changes: 7 additions & 0 deletions python/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[tool.poetry]
name = "aw-server-rust"
version = "0.1.0"
description = "Trayicon for ActivityWatch"
authors = ["Erik Bjäreholt <[email protected]>"]
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"
63 changes: 0 additions & 63 deletions scripts/copy_rust_binaries.py

This file was deleted.

0 comments on commit 4a3b0b6

Please sign in to comment.