Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy executables to Python virtual environment #500

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
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 = "Server 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"