Skip to content

Commit 197b7ad

Browse files
frafraBreakthrough
andauthored
[dist] Make dvr-scan installable via pyproject.toml. (#205)
* [dist] Make dvr-scan installable via pyproject.toml * [dist] pin packages using uv * [dist] Update tweak_setup_cfg_for_headless.py to modify pyproject.toml --------- Co-authored-by: Breakthrough <brandon248@gmail.com>
1 parent 76080b0 commit 197b7ad

File tree

12 files changed

+756
-110
lines changed

12 files changed

+756
-110
lines changed

.github/workflows/build.yml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,15 @@ jobs:
5858
version: "0.5.11"
5959
python-version: ${{ matrix.python-version }}
6060

61-
# TODO(#257): Unpin OpenCV versions once we figure out why frame numbers are mismatching in tests.
6261
- name: Install Dependencies
6362
run: |
6463
uv pip install --upgrade build wheel virtualenv
65-
uv pip install opencv-python-headless\<4.13 opencv-contrib-python-headless\<4.13 --only-binary :all:
66-
uv pip install -r requirements_headless.txt -r docs/requirements.txt
64+
# TODO: Figure out how to avoid installing the original OpenCV package.
65+
uv pip install -e ".[dev]" -r docs/requirements.txt
66+
# TODO(#257): Unpin OpenCV versions once we figure out why frame numbers are mismatching in tests.
67+
# Use headless OpenCV variant on CI to reduce download size.
68+
uv pip uninstall opencv-python opencv-contrib-python
69+
uv pip install "opencv-contrib-python-headless<4.13" --only-binary :all:
6770
6871
- name: Setup FFmpeg
6972
# TODO: This action currently does not work for non-x64 builders (e.g. macos-14):
@@ -87,7 +90,7 @@ jobs:
8790
- name: Build Package (Headless)
8891
shell: bash
8992
run: |
90-
python dist/tweak_setup_cfg_for_headless.py
93+
python dist/build_headless.py
9194
python -m build
9295
git reset --hard HEAD
9396

.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: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,79 @@
99
# LICENSE file, or visit one of the above pages for details.
1010
#
1111
[build-system]
12-
requires = ["setuptools"]
12+
requires = ["setuptools>=64"]
1313
build-backend = "setuptools.build_meta"
1414

15+
[project]
16+
name = "dvr-scan"
17+
dynamic = ["version"]
18+
description = "Tool for finding and extracting motion events in video files (e.g. security camera footage)."
19+
readme = "README.md"
20+
license = { text = "BSD-2-Clause" }
21+
requires-python = ">=3.10"
22+
authors = [
23+
{ name = "Brandon Castellano", email = "brandon248@gmail.com" },
24+
]
25+
keywords = [
26+
"analysis",
27+
"computer-vision",
28+
"video",
29+
]
30+
classifiers = [
31+
"Development Status :: 5 - Production/Stable",
32+
"Environment :: Console",
33+
"Environment :: Console :: Curses",
34+
"Intended Audience :: Developers",
35+
"Intended Audience :: End Users/Desktop",
36+
"Intended Audience :: System Administrators",
37+
"License :: OSI Approved :: MIT License",
38+
"Operating System :: OS Independent",
39+
"Programming Language :: Python :: 3",
40+
"Programming Language :: Python :: 3.10",
41+
"Programming Language :: Python :: 3.11",
42+
"Programming Language :: Python :: 3.12",
43+
"Programming Language :: Python :: 3.13",
44+
"Topic :: Multimedia :: Video",
45+
"Topic :: Multimedia :: Video :: Conversion",
46+
"Topic :: Multimedia :: Video :: Non-Linear Editor",
47+
"Topic :: Utilities",
48+
]
49+
dependencies = [
50+
"numpy",
51+
"platformdirs",
52+
"scenedetect>=0.6.2",
53+
"tqdm",
54+
"pillow",
55+
# TODO(#257): Unpin OpenCV versions once we figure out why frame numbers are mismatching in tests.
56+
"opencv-contrib-python<4.13",
57+
"screeninfo",
58+
]
59+
60+
[project.optional-dependencies]
61+
dev = [
62+
"pytest",
63+
"ruff",
64+
]
65+
66+
[project.scripts]
67+
dvr-scan = "dvr_scan.__main__:main"
68+
dvr-scan-app = "dvr_scan.app.__main__:main"
69+
70+
[project.urls]
71+
"Bug Tracker" = "https://github.com/Breakthrough/DVR-Scan/issues"
72+
Documentation = "https://www.dvr-scan.com/docs"
73+
Homepage = "https://www.dvr-scan.com/"
74+
Repository = "https://github.com/Breakthrough/DVR-Scan"
75+
76+
[tool.setuptools]
77+
include-package-data = true
78+
79+
[tool.setuptools.packages.find]
80+
include = ["dvr_scan*"]
81+
82+
[tool.setuptools.dynamic]
83+
version = {attr = "dvr_scan.__version__"}
84+
1585
[tool.ruff]
1686
exclude = [
1787
"docs"
@@ -43,3 +113,7 @@ select = [
43113
]
44114
fixable = ["ALL"]
45115
unfixable = []
116+
117+
[tool.pytest.ini_options]
118+
addopts = "--verbose"
119+
python_files = ["tests/*.py"]

requirements.txt

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

requirements_headless.txt

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

0 commit comments

Comments
 (0)