Skip to content

Commit 1106322

Browse files
authored
Merge pull request #4 from blab/slim-install
Move OpenCV to an optional dependency
2 parents cb68889 + d858bec commit 1106322

File tree

6 files changed

+31
-10
lines changed

6 files changed

+31
-10
lines changed

.github/workflows/python-package.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- name: Install
2828
run: |
2929
python -m pip install --upgrade pip
30-
python -m pip install .[test]
30+
python -m pip install .[full,test]
3131
- name: Lint with flake8
3232
run: |
3333
# stop the build if there are any warnings or errors.

CHANGES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Change log
22

3+
## 2.0.0
4+
5+
### Major changes
6+
7+
- Make [OpenCV](https://pypi.org/project/opencv-python/) an optional dependency, simplifying installation requirements for forecasting from an existing model. This change requires users to specify the "full" package version at installation to get support for model fitting. [#4](https://github.com/blab/popcast/pull/4) (@huddlej)
8+
39
## 1.1.0
410

511
### Features

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,16 @@ See the methods of [Huddleston et al. 2020](https://doi.org/10.7554/eLife.60067)
44

55
## Install
66

7+
For a full installation with the OpenCV package that's required for model fitting, specify the "full" package dependencies.
8+
9+
``` bash
10+
python -m pip install 'popcast[full]'
11+
```
12+
13+
For a smaller installation that only supports forecasting with an existing model, omit the optional package dependency.
14+
715
``` bash
8-
python3 -m pip install popcast
16+
python -m pip install popcast
917
```
1018

1119
## Usage
@@ -30,7 +38,7 @@ popcast fit \
3038
### Install locally
3139

3240
``` bash
33-
python3 -m pip install ".[test]"
41+
python -m pip install '.[full,test]'
3442
```
3543

3644
### Lint and run tests
@@ -52,17 +60,17 @@ cram --shell=/bin/bash tests/
5260
Install or upgrade publishing tools.
5361

5462
``` bash
55-
python3 -m pip install --upgrade build twine
63+
python -m pip install --upgrade build twine
5664
```
5765

5866
Build the distribution packages.
5967

6068
``` bash
61-
python3 -m build
69+
python -m build
6270
```
6371

6472
Upload the distribution packages.
6573

6674
``` bash
67-
python3 -m twine upload dist/*
75+
python -m twine upload dist/*
6876
```

pyproject.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "flit_core.buildapi"
44

55
[project]
66
name = "popcast"
7-
version = "1.1.0"
7+
version = "2.0.0"
88
authors = [
99
{ name="John Huddleston", email="[email protected]" },
1010
]
@@ -20,13 +20,15 @@ classifiers = [
2020

2121
dependencies = [
2222
"jellyfish >=0.8.2, ==0.*",
23-
"opencv-python >=4.5, ==4.*",
2423
"numpy >=1.17.0, ==1.*",
2524
"pandas >=1.2.0, ==1.*",
2625
"scipy >=1.5.4, ==1.*",
2726
]
2827

2928
[project.optional-dependencies]
29+
full = [
30+
"opencv-python >=4.5, ==4.*",
31+
]
3032
test = [
3133
"coverage[toml] >=5.2.1, ==5.*",
3234
"cram >=0.7, ==0.*",

src/popcast/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
__author__ = """John Huddleston"""
44
__email__ = '[email protected]'
5-
__version__ = '1.1.0'
5+
__version__ = '2.0.0'

src/popcast/fit.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Fit a model for the given data using the requested predictors and evaluate the model by time series cross-validation.
22
"""
3-
import cv2
43
import json
54
import numpy as np
65
import pandas as pd
@@ -418,6 +417,12 @@ def _fit(self, coefficients, X, y, use_l1_penalty=True, calculate_optimal_distan
418417
error between estimated values using the given coefficients and
419418
input data and the observed values
420419
"""
420+
try:
421+
import cv2
422+
except ImportError:
423+
print("Failed to import cv2 package required for model fitting. Install popcast with OpenCV using \"python -m pip install 'popcast[full]'\".", file=sys.stderr)
424+
sys.exit(1)
425+
421426
# Estimate target values.
422427
y_hat = self.predict(X, coefficients)
423428

0 commit comments

Comments
 (0)