Skip to content

Commit 65f3cfa

Browse files
authored
Merge pull request #69 from KumarLabJax/task/add-github-actions
Task/add GitHub actions
2 parents 462366a + 87a151c commit 65f3cfa

27 files changed

+857
-512
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: 'Build Docker Image'
2+
on:
3+
workflow_call:
4+
env:
5+
REGISTRY: docker.io
6+
IMAGE_NAME: aberger4/mouse-tracking
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: read
12+
packages: write
13+
14+
steps:
15+
16+
- name: Checkout repository
17+
uses: actions/checkout@v4
18+
19+
- name: Log in to Container Registry
20+
if: github.event_name != 'pull_request'
21+
uses: docker/login-action@v3
22+
with:
23+
registry: ${{ env.REGISTRY }}
24+
username: aberger4
25+
password: ${{ secrets.DOCKER_SECRET }}
26+
27+
- name: Extract metadata
28+
id: meta
29+
uses: docker/metadata-action@v5
30+
with:
31+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
32+
tags: |
33+
type=ref,event=branch
34+
type=ref,event=pr
35+
type=semver,pattern={{version}}
36+
type=semver,pattern={{major}}.{{minor}}
37+
type=raw,value=latest,enable={{is_default_branch}}
38+
39+
- name: Set up Docker Buildx
40+
uses: docker/setup-buildx-action@v3
41+
42+
- name: Build and push Docker image
43+
uses: docker/build-push-action@v5
44+
with:
45+
context: .
46+
push: ${{ github.event_name != 'pull_request' }}
47+
tags: ${{ steps.meta.outputs.tags }}
48+
labels: ${{ steps.meta.outputs.labels }}
49+
cache-from: type=gha
50+
cache-to: type=gha,mode=max
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: 'Lint Code Definition'
2+
on:
3+
workflow_call:
4+
inputs:
5+
python-version:
6+
description: 'Python version to set up'
7+
required: false
8+
default: '3.10'
9+
type: string
10+
jobs:
11+
format-lint:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v3
15+
16+
- name: Set up Python
17+
uses: actions/setup-python@v4
18+
with:
19+
python-version: ${{ inputs.python-version }}
20+
21+
- name: Install uv
22+
uses: astral-sh/setup-uv@v3
23+
with:
24+
version: "latest"
25+
26+
- name: Install dependencies with uv
27+
run: uv sync --only-group lint
28+
29+
- name: Run Ruff Linter
30+
run: uv run --only-group lint ruff check src/ tests/
31+
32+
- name: Run Ruff Formatter
33+
run: uv run --only-group lint ruff format --check src/ tests/
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: 'Python Tests Definition'
2+
on:
3+
workflow_call:
4+
inputs:
5+
python-version:
6+
description: Python version to set up'
7+
required: false
8+
default: '3.10'
9+
type: string
10+
runner-os:
11+
description: 'Runner OS'
12+
required: false
13+
default: 'ubuntu-latest'
14+
type: string
15+
jobs:
16+
run-tests:
17+
runs-on: ${{ inputs.runner-os }}
18+
steps:
19+
- uses: actions/checkout@v3
20+
21+
- name: Set up Python ${{ inputs.python-version }}
22+
uses: actions/setup-python@v4
23+
with:
24+
python-version: ${{ inputs.python-version }}
25+
26+
- name: Install uv
27+
uses: astral-sh/setup-uv@v3
28+
with:
29+
version: "latest"
30+
31+
- name: Install dependencies with uv
32+
run: uv sync --extra cpu
33+
34+
- name: Make Sure PyTorch is Installed
35+
run: uv pip install torch==2.6.0 torchvision==0.21.0 torchaudio==2.6.0 --index-url https://download.pytorch.org/whl/cpu
36+
37+
- name: Test with pytest
38+
run: uv run pytest tests

.github/workflows/pull-request.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Pull Request Checks
2+
3+
on:
4+
pull_request:
5+
branches: [ main, repository-reorganization ]
6+
7+
jobs:
8+
format-lint:
9+
name: "Format and Lint"
10+
uses: ./.github/workflows/_format-lint-action.yml
11+
12+
test:
13+
name: "Run Tests"
14+
needs: format-lint
15+
uses: ./.github/workflows/_run-tests-action.yml
16+
17+
build:
18+
name: "Build Docker Image"
19+
needs: [format-lint, test]
20+
uses: ./.github/workflows/_build-docker-action.yml

pyproject.toml

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ dependencies = [
99
"scipy==1.11.4",
1010
"pandas==2.0.3",
1111
"opencv-python-headless==4.8.0.76",
12-
"imageio==2.31.6",
12+
"imageio[ffmpeg]==2.31.6",
1313
"pillow==9.4.0",
1414
"matplotlib==3.7.1",
1515
"typer>=0.12.4",
@@ -40,16 +40,33 @@ cpu = [
4040

4141

4242
# ---- uv configuration: point Torch family at cu126 index ----
43+
# ---- uv indexes ----
44+
[[tool.uv.index]]
45+
name = "pypi"
46+
url = "https://pypi.org/simple"
47+
explicit = false
48+
4349
[[tool.uv.index]]
4450
name = "pytorch-cu126"
4551
url = "https://download.pytorch.org/whl/cu126"
4652
explicit = true
4753

54+
# ---- uv per-package sources with markers ----
55+
# Use CUDA wheels only when installing the `gpu` extra AND on platforms that can use them.
56+
# Fall back to CPU wheels when installing the `cpu` extra.
4857
[tool.uv.sources]
49-
torch = { index = "pytorch-cu126" }
50-
torchvision = { index = "pytorch-cu126" }
51-
torchaudio = { index = "pytorch-cu126" }
52-
58+
torch = [
59+
{ index = "pytorch-cu126", marker = "sys_platform == 'linux' and extra == 'gpu'" },
60+
{ index = "pypi", marker = "sys_platform == 'linux' and extra != 'gpu'" },
61+
]
62+
torchvision = [
63+
{ index = "pytorch-cu126", marker = "sys_platform == 'linux' and extra == 'gpu'" },
64+
{ index = "pypi", marker = "sys_platform == 'linux' and extra != 'gpu'" },
65+
]
66+
torchaudio = [
67+
{ index = "pytorch-cu126", marker = "sys_platform == 'linux' and extra == 'gpu'" },
68+
{ index = "pypi", marker = "sys_platform == 'linux' and extra != 'gpu'" },
69+
]
5370

5471
[project.scripts]
5572
mouse-tracking-runtime = "mouse_tracking.cli.main:app"
@@ -98,8 +115,14 @@ addopts = "--benchmark-skip"
98115

99116
[dependency-groups]
100117
dev = [
118+
{include-group = "lint"},
119+
{include-group = "test"}
120+
]
121+
test = [
101122
"pytest>=8.3.5",
102123
"pytest-benchmark>=5.1.0",
103124
"pytest-cov>=6.1.1",
125+
]
126+
lint = [
104127
"ruff>=0.11.2",
105128
]

tests/cli/infer/test_arena_corner.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,9 @@ def test_arena_corner_frame_options(self, mock_infer, num_frames, frame_interval
255255
def test_arena_corner_help_text(self):
256256
"""Test that the command has proper help text."""
257257
# Arrange & Act
258-
result = self.runner.invoke(app, ["arena-corner", "--help"])
258+
result = self.runner.invoke(
259+
app, ["arena-corner", "--help"], env={"TERM": "dumb"}
260+
)
259261

260262
# Assert
261263
assert result.exit_code == 0

tests/cli/infer/test_commands.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def test_infer_commands_help_structure():
111111

112112
# Act & Assert
113113
for command in commands:
114-
result = runner.invoke(app, [command, "--help"])
114+
result = runner.invoke(app, [command, "--help"], env={"TERM": "dumb"})
115115
assert result.exit_code == 0
116116
assert "Usage:" in result.stdout
117117
assert "--help" in result.stdout
@@ -252,7 +252,7 @@ def test_infer_command_help_format(command_name):
252252
runner = CliRunner()
253253

254254
# Act
255-
result = runner.invoke(app, [command_name, "--help"])
255+
result = runner.invoke(app, [command_name, "--help"], env={"TERM": "dumb"})
256256

257257
# Assert
258258
assert result.exit_code == 0

tests/cli/infer/test_fecal_boli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def test_fecal_boli_default_values(self, mock_infer):
280280
def test_fecal_boli_help_text(self):
281281
"""Test that the fecal boli command has proper help text."""
282282
# Arrange & Act
283-
result = self.runner.invoke(app, ["fecal-boli", "--help"])
283+
result = self.runner.invoke(app, ["fecal-boli", "--help"], env={"TERM": "dumb"})
284284

285285
# Assert
286286
assert result.exit_code == 0

tests/cli/infer/test_food_hopper.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,9 @@ def test_food_hopper_default_values(self, mock_infer):
278278
def test_food_hopper_help_text(self):
279279
"""Test that the food hopper command has proper help text."""
280280
# Arrange & Act
281-
result = self.runner.invoke(app, ["food-hopper", "--help"])
281+
result = self.runner.invoke(
282+
app, ["food-hopper", "--help"], env={"TERM": "dumb"}
283+
)
282284

283285
# Assert
284286
assert result.exit_code == 0

tests/cli/infer/test_lixit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def test_lixit_default_values(self, mock_infer):
276276
def test_lixit_help_text(self):
277277
"""Test that the lixit command has proper help text."""
278278
# Arrange & Act
279-
result = self.runner.invoke(app, ["lixit", "--help"])
279+
result = self.runner.invoke(app, ["lixit", "--help"], env={"TERM": "dumb"})
280280

281281
# Assert
282282
assert result.exit_code == 0

0 commit comments

Comments
 (0)