Skip to content

Commit d3e9156

Browse files
committed
[dist] Update tweak_setup_cfg_for_headless.py to modify pyproject.toml
1 parent b05fbd1 commit d3e9156

File tree

8 files changed

+63
-76
lines changed

8 files changed

+63
-76
lines changed

.github/workflows/build.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,15 @@ jobs:
5050
version: "0.5.11"
5151
python-version: ${{ matrix.python-version }}
5252

53-
# TODO(#257): Unpin OpenCV versions once we figure out why frame numbers are mismatching in tests.
5453
- name: Install Dependencies
5554
run: |
5655
uv pip install --upgrade build wheel virtualenv
57-
uv pip install opencv-python-headless\<4.13 opencv-contrib-python-headless\<4.13 --only-binary :all:
58-
uv pip install -r requirements_headless.txt -r docs/requirements.txt
56+
# TODO: Figure out how to avoid installing the original OpenCV package.
57+
uv pip install -e ".[dev]" -r docs/requirements.txt
58+
# TODO(#257): Unpin OpenCV versions once we figure out why frame numbers are mismatching in tests.
59+
# Use headless OpenCV variant on CI to reduce download size.
60+
uv pip uninstall opencv-python opencv-contrib-python
61+
uv pip install opencv-python-headless<4.13 opencv-contrib-python-headless<4.13 --only-binary :all:
5962
6063
- name: Setup FFmpeg
6164
# TODO: This action currently does not work for non-x64 builders (e.g. macos-14):
@@ -79,7 +82,7 @@ jobs:
7982
- name: Build Package (Headless)
8083
shell: bash
8184
run: |
82-
python dist/tweak_setup_cfg_for_headless.py
85+
python dist/build_headless.py
8386
python -m build
8487
git reset --hard HEAD
8588

.github/workflows/check-code-format.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ jobs:
3535
- name: Install Dependencies
3636
run: |
3737
uv pip install --upgrade pip
38-
uv pip install --upgrade yapf toml
39-
uv pip install -r requirements_headless.txt
38+
uv pip install --upgrade yapf toml ruff
4039
4140
- name: Check Code Format (yapf)
4241
if: ${{ hashFiles('.style.yapf') != '' }}

.github/workflows/publish-pypi.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,13 @@ jobs:
103103
run: |
104104
uv pip install --upgrade build wheel virtualenv
105105
uv pip install opencv-python-headless opencv-contrib-python-headless --only-binary :all:
106-
uv pip install -r requirements_headless.txt -r docs/requirements.txt
106+
uv pip install -e . -r docs/requirements.txt
107107
108108
- name: Build Package
109109
run: |
110110
python dist/pre_release.py
111111
python -m build
112-
python dist/tweak_setup_cfg_for_headless.py
112+
python dist/build_headless.py
113113
python -m build
114114
mkdir pkg
115115
mv dist/*.tar.gz pkg/

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ site/
1010
build/
1111
# Working directory for distribution assembly
1212
dist/dvr-scan/*
13-
dist/dvr-scan-*
14-
dist/dvr_scan-*
1513

1614
# Editors/environment
1715
.DS_Store

dist/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*
2+
!*.py
3+
!*.txt
4+
!.gitignore

dist/build_headless.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#
2+
# DVR-Scan: Video Motion Event Detection & Extraction Tool
3+
# --------------------------------------------------------------
4+
# [ Site: https://www.dvr-scan.com/ ]
5+
# [ Repo: https://github.com/Breakthrough/DVR-Scan ]
6+
#
7+
# Copyright (C) 2016 Brandon Castellano <http://www.bcastell.com>.
8+
#
9+
10+
# This script generates a headless (no GUI) version of the package
11+
# by modifying the pyproject.toml file. When the project is next built,
12+
# the headless variant will be used.
13+
#
14+
# *WARNING*: This modifies the existing pyproject.toml file in place.
15+
# The changes must be reverted to restore the full package.
16+
#
17+
18+
import os
19+
import re
20+
21+
# Correctly locate pyproject.toml relative to the script's location
22+
script_dir = os.path.dirname(os.path.abspath(__file__))
23+
project_root = os.path.abspath(os.path.join(script_dir, ".."))
24+
pyproject_path = os.path.join(project_root, "pyproject.toml")
25+
26+
with open(pyproject_path, "r") as f:
27+
content = f.read()
28+
29+
# Rename package to headless variant
30+
assert 'name = "dvr-scan"' in content
31+
content = content.replace('name = "dvr-scan"', 'name = "dvr-scan-headless"', 1)
32+
33+
# Remove dvr-scan-app entry point
34+
assert "dvr-scan-app" in content
35+
content = re.sub(r'^dvr-scan-app\s*=.*\n', "", content, flags=re.MULTILINE)
36+
37+
# Swap GUI opencv for headless opencv
38+
assert "opencv-contrib-python<4.13" in content
39+
content = content.replace('"opencv-contrib-python<4.13"', '"opencv-contrib-python-headless<4.13"', 1)
40+
41+
# Remove screeninfo (GUI dependency)
42+
assert "screeninfo" in content
43+
content = re.sub(r'^\s*"screeninfo",?\n', "", content, flags=re.MULTILINE)
44+
45+
with open(pyproject_path, "w") as f:
46+
f.write(content)
47+
48+
print("Successfully generated headless pyproject.toml.")

dist/tweak_setup_cfg_for_headless.py

Lines changed: 0 additions & 59 deletions
This file was deleted.

pyproject.toml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,12 @@ dependencies = [
5252
"scenedetect>=0.6.2",
5353
"tqdm",
5454
"pillow",
55-
# TODO(#257): Unpin OpenCV versions once we figure out why frame numbers are mismatching in tests.
56-
"opencv-contrib-python-headless<4.13",
57-
]
58-
59-
[project.optional-dependencies]
60-
gui = [
6155
# TODO(#257): Unpin OpenCV versions once we figure out why frame numbers are mismatching in tests.
6256
"opencv-contrib-python<4.13",
6357
"screeninfo",
6458
]
6559

66-
[dependency-groups]
60+
[project.optional-dependencies]
6761
dev = [
6862
"pytest",
6963
"ruff",

0 commit comments

Comments
 (0)