Skip to content

Commit ec8c8cd

Browse files
authored
Merge pull request #85 from ins-amu/cli-entry-pyinstaller
<(^_^)> new exe cli
2 parents 1b22675 + cb63004 commit ec8c8cd

2 files changed

Lines changed: 118 additions & 0 deletions

File tree

.github/workflows/pyinstaller.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: PyInstaller builds
2+
3+
on:
4+
push:
5+
branches: [ main, cli-entry-pyinstaller ]
6+
release:
7+
types: [ published ]
8+
9+
permissions:
10+
contents: read
11+
packages: write
12+
actions: write
13+
14+
jobs:
15+
build:
16+
name: Build PyInstaller single-file executables
17+
runs-on: ${{ matrix.os }}
18+
strategy:
19+
matrix:
20+
os: [ubuntu-latest, macos-latest, windows-latest]
21+
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v4
25+
26+
- name: Set up Python
27+
uses: actions/setup-python@v4
28+
with:
29+
python-version: '3.11'
30+
31+
- name: Install build dependencies
32+
run: |
33+
python -m pip install --upgrade pip
34+
pip install pyinstaller
35+
pip install .
36+
37+
- name: Build single-file executable
38+
run: |
39+
# Create a dist directory for pyinstaller
40+
pyinstaller --onefile --name vbjax vbjax/__main__.py
41+
shell: bash
42+
43+
- name: Upload artifact
44+
uses: actions/upload-artifact@v4
45+
with:
46+
name: vbjax-cli-${{ matrix.os }}
47+
path: dist/
48+
49+
attach-release:
50+
name: Attach artifacts to release (when release event)
51+
needs: build
52+
if: github.event_name == 'release'
53+
runs-on: ubuntu-latest
54+
steps:
55+
- name: Download build artifacts
56+
uses: actions/download-artifact@v4
57+
with:
58+
path: build-artifacts
59+
60+
- name: Create release assets
61+
uses: softprops/turnstyle@v1
62+
with:
63+
artifacts: 'build-artifacts/**/dist/**'

vbjax/__main__.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env python3
2+
"""Simple CLI entrypoint for the vbjax package.
3+
4+
Usage: python -m vbjax <subcommand> [args]
5+
6+
Currently implements:
7+
- run-tests [pytest args...] : run the project's tests via pytest
8+
9+
This uses argparse so it's easy to extend later or swap to rich/typer.
10+
"""
11+
from __future__ import annotations
12+
13+
import argparse
14+
import subprocess
15+
import sys
16+
from typing import List, Optional
17+
18+
19+
def run_tests(pytest_args: Optional[List[str]] = None) -> int:
20+
"""Run pytest in a subprocess and return its exit code."""
21+
if pytest_args is None:
22+
pytest_args = []
23+
cmd = [sys.executable, "-m", "pytest"] + pytest_args
24+
# Forward exit code from pytest
25+
try:
26+
proc = subprocess.run(cmd)
27+
return proc.returncode
28+
except KeyboardInterrupt:
29+
return 130
30+
31+
32+
def build_parser() -> argparse.ArgumentParser:
33+
p = argparse.ArgumentParser(prog="python -m vbjax", description="vbjax convenience CLI")
34+
subs = p.add_subparsers(dest="command")
35+
subs.required = True
36+
37+
p_tests = subs.add_parser("run-tests", help="Run tests via pytest")
38+
# capture remaining args and forward to pytest
39+
p_tests.add_argument("pytest_args", nargs=argparse.REMAINDER, help="Arguments forwarded to pytest")
40+
41+
return p
42+
43+
44+
def main(argv: Optional[List[str]] = None) -> None:
45+
parser = build_parser()
46+
args = parser.parse_args(argv)
47+
48+
if args.command == "run-tests":
49+
# argparse.REMAINDER will include any leading '--'; keep as-is
50+
rc = run_tests(args.pytest_args or [])
51+
raise SystemExit(rc)
52+
53+
54+
if __name__ == "__main__":
55+
main()

0 commit comments

Comments
 (0)