Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3826d25

Browse filesBrowse files
committed
Rework Mac OS build
Use cmake && make to prebuild opencv libraries and use pip to pack them
1 parent 673effc commit 3826d25
Copy full SHA for 3826d25

File tree

5 files changed

+384
-1
lines changed
Filter options

5 files changed

+384
-1
lines changed

‎.travis.yml

Copy file name to clipboardExpand all lines: .travis.yml
+35Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ jobs:
8585
- ENABLE_CONTRIB=0
8686
- ENABLE_HEADLESS=0
8787
- TEST_DEPENDS=numpy==1.13.3
88+
cache:
89+
directories: $HOME/.ccache
8890

8991
- os: osx
9092
language: generic
@@ -94,6 +96,8 @@ jobs:
9496
- ENABLE_CONTRIB=0
9597
- ENABLE_HEADLESS=0
9698
- TEST_DEPENDS=numpy==1.14.5
99+
cache:
100+
directories: $HOME/.ccache
97101

98102
- os: osx
99103
language: generic
@@ -103,6 +107,8 @@ jobs:
103107
- ENABLE_CONTRIB=0
104108
- ENABLE_HEADLESS=0
105109
- TEST_DEPENDS=numpy==1.17.3
110+
cache:
111+
directories: $HOME/.ccache
106112

107113
- os: osx
108114
language: generic
@@ -112,6 +118,8 @@ jobs:
112118
- ENABLE_CONTRIB=0
113119
- ENABLE_HEADLESS=0
114120
- TEST_DEPENDS=numpy==1.19.3
121+
cache:
122+
directories: $HOME/.ccache
115123

116124

117125
# headless builds for MacOS
@@ -123,6 +131,8 @@ jobs:
123131
- ENABLE_CONTRIB=0
124132
- ENABLE_HEADLESS=1
125133
- TEST_DEPENDS=numpy==1.13.3
134+
cache:
135+
directories: $HOME/.ccache
126136

127137
- os: osx
128138
language: generic
@@ -132,6 +142,8 @@ jobs:
132142
- ENABLE_CONTRIB=0
133143
- ENABLE_HEADLESS=1
134144
- TEST_DEPENDS=numpy==1.14.5
145+
cache:
146+
directories: $HOME/.ccache
135147

136148
- os: osx
137149
language: generic
@@ -141,6 +153,8 @@ jobs:
141153
- ENABLE_CONTRIB=0
142154
- ENABLE_HEADLESS=1
143155
- TEST_DEPENDS=numpy==1.17.3
156+
cache:
157+
directories: $HOME/.ccache
144158

145159
- os: osx
146160
language: generic
@@ -150,6 +164,8 @@ jobs:
150164
- ENABLE_CONTRIB=0
151165
- ENABLE_HEADLESS=1
152166
- TEST_DEPENDS=numpy==1.19.3
167+
cache:
168+
directories: $HOME/.ccache
153169

154170

155171
# Contrib builds for MacOS
@@ -161,6 +177,8 @@ jobs:
161177
- ENABLE_CONTRIB=1
162178
- ENABLE_HEADLESS=0
163179
- TEST_DEPENDS=numpy==1.13.3
180+
cache:
181+
directories: $HOME/.ccache
164182

165183
- os: osx
166184
language: generic
@@ -170,6 +188,8 @@ jobs:
170188
- ENABLE_CONTRIB=1
171189
- ENABLE_HEADLESS=0
172190
- TEST_DEPENDS=numpy==1.14.5
191+
cache:
192+
directories: $HOME/.ccache
173193

174194
- os: osx
175195
language: generic
@@ -179,6 +199,8 @@ jobs:
179199
- ENABLE_CONTRIB=1
180200
- ENABLE_HEADLESS=0
181201
- TEST_DEPENDS=numpy==1.17.3
202+
cache:
203+
directories: $HOME/.ccache
182204

183205
- os: osx
184206
language: generic
@@ -188,6 +210,8 @@ jobs:
188210
- ENABLE_CONTRIB=1
189211
- ENABLE_HEADLESS=0
190212
- TEST_DEPENDS=numpy==1.19.3
213+
cache:
214+
directories: $HOME/.ccache
191215

192216

193217
# headless contrib builds for MacOS
@@ -199,6 +223,8 @@ jobs:
199223
- ENABLE_CONTRIB=1
200224
- ENABLE_HEADLESS=1
201225
- TEST_DEPENDS=numpy==1.13.3
226+
cache:
227+
directories: $HOME/.ccache
202228

203229
- os: osx
204230
language: generic
@@ -208,6 +234,8 @@ jobs:
208234
- ENABLE_CONTRIB=1
209235
- ENABLE_HEADLESS=1
210236
- TEST_DEPENDS=numpy==1.14.5
237+
cache:
238+
directories: $HOME/.ccache
211239

212240
- os: osx
213241
language: generic
@@ -217,6 +245,8 @@ jobs:
217245
- ENABLE_CONTRIB=1
218246
- ENABLE_HEADLESS=1
219247
- TEST_DEPENDS=numpy==1.17.3
248+
cache:
249+
directories: $HOME/.ccache
220250

221251
- os: osx
222252
language: generic
@@ -226,6 +256,8 @@ jobs:
226256
- ENABLE_CONTRIB=1
227257
- ENABLE_HEADLESS=1
228258
- TEST_DEPENDS=numpy==1.19.3
259+
cache:
260+
directories: $HOME/.ccache
229261

230262

231263
# default builds for Linux
@@ -896,6 +928,9 @@ install: |
896928
if [[ $SDIST == 1 ]]; then
897929
python -m pip install --upgrade pip
898930
python -m pip install scikit-build
931+
git submodule sync
932+
git submodule update --init --recursive opencv
933+
git submodule update --init --recursive opencv_contrib
899934
python setup.py sdist
900935
else
901936
build_wheel $REPO_DIR $PLAT

‎setup-osx.py

Copy file name to clipboard
+138Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
import io
2+
import os
3+
import os.path
4+
import sys
5+
import runpy
6+
import re
7+
import sysconfig
8+
import setuptools
9+
10+
11+
def main():
12+
os.chdir(os.path.dirname(os.path.abspath(__file__)))
13+
14+
minimum_supported_numpy = "1.13.3"
15+
if sys.version_info[:2] >= (3, 6):
16+
minimum_supported_numpy = "1.13.3"
17+
if sys.version_info[:2] >= (3, 7):
18+
minimum_supported_numpy = "1.14.5"
19+
if sys.version_info[:2] >= (3, 8):
20+
minimum_supported_numpy = "1.17.3"
21+
if sys.version_info[:2] >= (3, 9):
22+
minimum_supported_numpy = "1.19.3"
23+
24+
numpy_version = "numpy>=%s" % minimum_supported_numpy
25+
26+
build_contrib = get_build_env_var_by_name("contrib")
27+
build_headless = get_build_env_var_by_name("headless")
28+
build_java = "ON" if get_build_env_var_by_name("java") else "OFF"
29+
30+
version = {}
31+
here = os.path.abspath(os.path.dirname(__file__))
32+
version_file = os.path.join(here, "cv2", "version.py")
33+
34+
# generate a fresh version.py always when Git repository exists
35+
if os.path.exists(".git"):
36+
old_args = sys.argv.copy()
37+
sys.argv = ["", str(build_contrib), str(build_headless), str(False)]
38+
runpy.run_path("find_version.py", run_name="__main__")
39+
sys.argv = old_args
40+
41+
with open(version_file) as fp:
42+
exec(fp.read(), version)
43+
44+
package_version = version["opencv_version"]
45+
build_contrib = version["contrib"]
46+
build_headless = version["headless"]
47+
48+
package_name = "opencv-python"
49+
50+
if build_contrib and not build_headless:
51+
package_name = "opencv-contrib-python"
52+
53+
if build_contrib and build_headless:
54+
package_name = "opencv-contrib-python-headless"
55+
56+
if build_headless and not build_contrib:
57+
package_name = "opencv-python-headless"
58+
59+
long_description = io.open("README.md", encoding="utf-8").read()
60+
61+
packages = ["cv2", "cv2.data"]
62+
63+
package_data = {
64+
"cv2": ["*%s" % sysconfig.get_config_vars().get("SO"), "version.py"]
65+
+ (["*.dll"] if os.name == "nt" else [])
66+
+ ["LICENSE.txt", "LICENSE-3RD-PARTY.txt"],
67+
"cv2.data": ["*.xml"],
68+
}
69+
70+
setuptools.setup(
71+
name=package_name,
72+
version=package_version,
73+
url="https://github.com/skvark/opencv-python",
74+
license="MIT",
75+
description="Wrapper package for OpenCV python bindings.",
76+
long_description=long_description,
77+
long_description_content_type="text/markdown",
78+
packages=packages,
79+
package_data=package_data,
80+
include_package_data=True,
81+
maintainer="Olli-Pekka Heinisuo",
82+
ext_modules=EmptyListWithLength(),
83+
install_requires=numpy_version,
84+
python_requires=">=3.6",
85+
classifiers=[
86+
"Development Status :: 5 - Production/Stable",
87+
"Environment :: Console",
88+
"Intended Audience :: Developers",
89+
"Intended Audience :: Education",
90+
"Intended Audience :: Information Technology",
91+
"Intended Audience :: Science/Research",
92+
"License :: OSI Approved :: MIT License",
93+
"Operating System :: MacOS",
94+
"Operating System :: Microsoft :: Windows",
95+
"Operating System :: POSIX",
96+
"Operating System :: Unix",
97+
"Programming Language :: Python",
98+
"Programming Language :: Python :: 3",
99+
"Programming Language :: Python :: 3 :: Only",
100+
"Programming Language :: Python :: 3.6",
101+
"Programming Language :: Python :: 3.7",
102+
"Programming Language :: Python :: 3.8",
103+
"Programming Language :: Python :: 3.9",
104+
"Programming Language :: C++",
105+
"Programming Language :: Python :: Implementation :: CPython",
106+
"Topic :: Scientific/Engineering",
107+
"Topic :: Scientific/Engineering :: Image Recognition",
108+
"Topic :: Software Development",
109+
],
110+
)
111+
112+
113+
def get_build_env_var_by_name(flag_name):
114+
flag_set = False
115+
116+
try:
117+
flag_set = bool(int(os.getenv("ENABLE_" + flag_name.upper(), None)))
118+
except Exception:
119+
pass
120+
121+
if not flag_set:
122+
try:
123+
flag_set = bool(int(open(flag_name + ".enabled").read(1)))
124+
except Exception:
125+
pass
126+
127+
return flag_set
128+
129+
130+
# This creates a list which is empty but returns a length of 1.
131+
# Should make the wheel a binary distribution and platlib compliant.
132+
class EmptyListWithLength(list):
133+
def __len__(self):
134+
return 1
135+
136+
137+
if __name__ == "__main__":
138+
main()

‎tools/python_path.py

Copy file name to clipboard
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import sys
2+
3+
4+
def main():
5+
if len(sys.argv) < 2:
6+
print("Usage: ", sys.argv[0], "bin|lib|include")
7+
return 1
8+
9+
if (sys.argv[1] == "bin"):
10+
print(sys.executable)
11+
elif (sys.argv[1] == "lib"):
12+
from skbuild import cmaker
13+
python_version = cmaker.CMaker.get_python_version()
14+
python_lib_path = cmaker.CMaker.get_python_library(python_version).replace("\\", "/")
15+
# FIXME: Wrong extension:
16+
# import os
17+
# from sysconfig import get_config_var
18+
# python_lib_path = os.path.join(get_config_var('LIBDIR'), get_config_var('LIBRARY'))
19+
print(python_lib_path)
20+
else:
21+
from sysconfig import get_paths
22+
info = get_paths()
23+
print(info['platinclude'])
24+
25+
26+
if __name__ == "__main__":
27+
main()

‎travis_config.sh

Copy file name to clipboardExpand all lines: travis_config.sh
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ function bdist_wheel_cmd {
1414
# copied from multibuild's common_utils.sh
1515
# add osx deployment target so it doesnt default to 10.6
1616
local abs_wheelhouse=$1
17-
CI_BUILD=1 pip wheel --verbose --wheel-dir="$PWD/dist" . $BDIST_PARAMS
17+
if [ -n "$IS_MACOS" ]; then
18+
source travis_osx_build.sh
19+
build_bdist_osx_wheel $@
20+
else
21+
CI_BUILD=1 pip wheel --verbose --wheel-dir="$PWD/dist" . $BDIST_PARAMS
22+
fi
1823
cp dist/*.whl $abs_wheelhouse
1924
if [ -z "$IS_MACOS" ]; then
2025
TOOLS_PATH=/opt/_internal/tools

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.