Skip to content

Commit ad59e0c

Browse files
authored
[dist] Make opencv-python/pillow required, add headless distribution (#222)
1 parent da621e2 commit ad59e0c

File tree

7 files changed

+93
-14
lines changed

7 files changed

+93
-14
lines changed

.github/workflows/build.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,34 @@ jobs:
7575
python -m build
7676
echo "dvr_scan_version=`python -c \"import dvr_scan; print(dvr_scan.__version__.replace('-', '.'))\"`" >> "$GITHUB_ENV"
7777
78+
- name: Build Package (Headless)
79+
shell: bash
80+
run: |
81+
python dist/tweak_setup_cfg_for_headless.py
82+
python -m build
83+
git reset --hard HEAD
84+
7885
- name: Smoke Test (Source)
7986
run: |
8087
uv pip install dist/dvr_scan-${{ env.dvr_scan_version }}.tar.gz
8188
python -m dvr_scan --version
8289
python -m dvr_scan -i tests/resources/simple_movement.mp4 -so -df 4 -et 100
8390
uv pip uninstall dvr-scan
91+
uv pip install dist/dvr_scan_headless-${{ env.dvr_scan_version }}.tar.gz
92+
python -m dvr_scan --version
93+
python -m dvr_scan -i tests/resources/simple_movement.mp4 -so -df 4 -et 100
94+
uv pip uninstall dvr-scan-headless
8495
8596
- name: Smoke Test (Wheel)
8697
run: |
8798
uv pip install dist/dvr_scan-${{ env.dvr_scan_version }}-py3-none-any.whl
8899
python -m dvr_scan --version
89100
python -m dvr_scan -i tests/resources/simple_movement.mp4 -so -df 4 -et 100
90101
uv pip uninstall dvr-scan
102+
uv pip install dist/dvr_scan_headless-${{ env.dvr_scan_version }}-py3-none-any.whl
103+
python -m dvr_scan --version
104+
python -m dvr_scan -i tests/resources/simple_movement.mp4 -so -df 4 -et 100
105+
uv pip uninstall dvr-scan-headless
91106
92107
- name: Upload Package
93108
if: ${{ matrix.python-version == '3.13' && matrix.os == 'ubuntu-latest' }}

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ENV DEBIAN_FRONTEND=noninteractive
55

66
RUN apt-get update && apt-get install -y python3 python3-pip libgl1-mesa-glx libglib2.0-0
77

8-
RUN pip3 install dvr-scan[opencv]
8+
RUN pip3 install dvr-scan
99

1010
WORKDIR /video/
1111

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ DVR-Scan is a command-line application that **automatically detects motion event
2020

2121
## Quick Install
2222

23-
pip install dvr-scan[opencv] --upgrade
23+
pip install dvr-scan --upgrade
2424

2525
Windows builds (installer + portable) are also available on [the Downloads page](https://www.dvr-scan.com/download/).
2626

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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 setup.cfg file. When the project is next built,
12+
# the headless variant will be used.
13+
#
14+
# *WARNING*: This modifies the existing setup.cfg file in place.
15+
# The changes must be reverted to restore the full package.
16+
#
17+
18+
import configparser
19+
import os
20+
21+
COPYRIGHT_TEXT = """#
22+
# DVR-Scan: Video Motion Event Detection & Extraction Tool
23+
# --------------------------------------------------------------
24+
# [ Site: https://www.dvr-scan.com/ ]
25+
# [ Repo: https://github.com/Breakthrough/DVR-Scan ]
26+
#
27+
# Copyright (C) 2016 Brandon Castellano <http://www.bcastell.com>.
28+
#
29+
30+
"""
31+
32+
# Correctly locate setup.cfg relative to the script's location
33+
script_dir = os.path.dirname(os.path.abspath(__file__))
34+
project_root = os.path.abspath(os.path.join(script_dir, ".."))
35+
setup_cfg_path = os.path.join(project_root, "setup.cfg")
36+
37+
# Read setup.cfg
38+
config = configparser.ConfigParser()
39+
# Preserve case of keys
40+
config.optionxform = str
41+
config.read(setup_cfg_path)
42+
43+
assert config.has_option("metadata", "name")
44+
name = config.get("metadata", "name")
45+
config.set("metadata", "name", f"{name}-Headless")
46+
47+
# Remove dvr-scan-app from console_scripts
48+
assert config.has_section("options.entry_points")
49+
assert config.has_option("options.entry_points", "console_scripts")
50+
scripts = config.get("options.entry_points", "console_scripts").splitlines()
51+
scripts = [s.strip() for s in scripts if s.strip() and "dvr-scan-app" not in s]
52+
config.set("options.entry_points", "console_scripts", "\n" + "\n".join(scripts))
53+
54+
# Write back to setup.cfg
55+
with open(setup_cfg_path, "w") as configfile:
56+
configfile.write(COPYRIGHT_TEXT)
57+
config.write(configfile)
58+
59+
print("Successfully generated headless setup.cfg.")

docs/changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,8 @@ This version of DVR-Scan includes a new, faster background subtraction algorithm
346346

347347
### In Development
348348

349+
* [general] The Python distribution now requires `opencv-python`
350+
* There is a separate `dvr-scan-headless` package available for servers which requires `opencv-python-headless` and only includes CLI functionality
349351
* [bugfix] Fix bounding box overlay stuck on when using the OpenCV output mode [#213](https://github.com/Breakthrough/DVR-Scan/issues/209)
350352
* [feature] various UI enhancements:
351353
* input videos can now be sorted

docs/download.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ hide:
1515

1616
<h3>pipx (recommended):</h3>
1717

18-
pipx install dvr-scan[opencv]
18+
pipx install dvr-scan
1919

2020
<h3>pip:</h3>
2121

22-
python3 -m pip install dvr-scan[opencv]
22+
python3 -m pip install dvr-scan
2323

2424
DVR-Scan requires Python 3.9 or higher to run, and works on Windows, Linux, and OSX. [`pipx` is recommended](https://pipx.pypa.io/stable/installation/) for installing DVR-Scan, however installing via `pip` or from source is also supported.
2525

@@ -40,7 +40,7 @@ The installer is recommended for most users. Windows builds include all require
4040

4141
## Servers
4242

43-
For headless systems that do not require the UI, you can install `dvr-scan[opencv-headless]`. This will make sure that [the headless version of OpenCV](https://pypi.org/project/opencv-python-headless/) is installed, which avoids any dependencies on X11 libraries or any other GUI components. This allows DVR-Scan to run with less dependencies, and can result in smaller Docker images.
43+
For headless systems that do not require the UI, you can install `dvr-scan-headless`. This will make sure that [the headless version of OpenCV](https://pypi.org/project/opencv-python-headless/) is installed, which avoids any dependencies on X11 libraries or any other GUI components. This allows DVR-Scan to run with less dependencies, and can result in smaller Docker images.
4444

4545
-------------------------------
4646

setup.cfg

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
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+
#
19

210
[metadata]
3-
name = dvr-scan
11+
name = DVR-Scan
412
version = attr: dvr_scan.__version__
513
license = BSD 2-Clause License
614
author = Brandon Castellano
@@ -42,6 +50,9 @@ install_requires =
4250
scenedetect
4351
screeninfo
4452
tqdm
53+
opencv-python
54+
opencv-contrib-python
55+
pillow
4556
packages =
4657
# Main application
4758
dvr_scan
@@ -55,14 +66,6 @@ packages =
5566
python_requires = >=3.9
5667
include_package_data = True
5768

58-
# TODO: Split the headless version into it's own package so we can directly depend on
59-
# everything below.
60-
[options.extras_require]
61-
opencv =
62-
opencv-python
63-
pillow
64-
opencv-headless = opencv-python-headless
65-
6669
[options.entry_points]
6770
console_scripts =
6871
dvr-scan = dvr_scan.__main__:main

0 commit comments

Comments
 (0)