Skip to content

Commit 22d4786

Browse files
committed
fix some PEP8 style issues in setup.py
1 parent dfa0bb0 commit 22d4786

File tree

2 files changed

+77
-75
lines changed

2 files changed

+77
-75
lines changed

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[submodule "multibuild"]
55
path = multibuild
66
url = https://github.com/matthew-brett/multibuild.git
7-
branch = devel
7+
branch = devel
88
[submodule "opencv_contrib"]
99
path = opencv_contrib
1010
url = https://github.com/opencv/opencv_contrib.git

setup.py

Lines changed: 76 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# No 3rd-party modules here, see "3rd-party" note below
2-
import io, os, os.path, sys, runpy, subprocess, re, sysconfig
2+
import io
3+
import os
4+
import os.path
5+
import sys
6+
import runpy
7+
import subprocess
8+
import re
9+
import sysconfig
310

411

512
def main():
@@ -9,76 +16,72 @@ def main():
916
cmake_source_dir = "opencv"
1017
build_contrib = get_build_contrib()
1118

12-
1319
# Only import 3rd-party modules after having installed all the build dependencies:
1420
# any of them, or their dependencies, can be updated during that process,
1521
# leading to version conflicts
1622
numpy_version = get_or_install("numpy", "1.11.3" if sys.version_info[:2] >= (3, 6) else "1.11.1")
1723
get_or_install("scikit-build")
1824
import skbuild
19-
25+
2026
if os.path.exists('.git'):
27+
2128
import pip.vcs.git
2229
g = pip.vcs.git.Git()
2330
use_depth = g.get_git_version() >= type(g.get_git_version())("1.8.4")
24-
g.run_command(["submodule", "update", "--init", "--recursive"] + \
25-
(["--depth=1"] if use_depth else []) + \
26-
[cmake_source_dir])
31+
32+
g.run_command(["submodule", "update", "--init", "--recursive"] +
33+
(["--depth=1"] if use_depth else []) +
34+
[cmake_source_dir])
35+
2736
if build_contrib:
28-
g.run_command(["submodule", "update", "--init", "--recursive"] + \
29-
(["--depth=1"] if use_depth else []) + \
30-
["opencv_contrib"])
31-
del use_depth, g, pip
37+
g.run_command(["submodule", "update", "--init", "--recursive"] +
38+
(["--depth=1"] if use_depth else []) +
39+
["opencv_contrib"])
3240

41+
del use_depth, g, pip
3342

3443
# https://stackoverflow.com/questions/1405913/python-32bit-or-64bit-mode
35-
x64 = sys.maxsize>2**32
36-
44+
x64 = sys.maxsize > 2**32
3745

3846
package_name = "opencv-contrib-python" if build_contrib else "opencv-python"
3947
long_description = io.open('README_CONTRIB.rst' if build_contrib else 'README.rst', encoding="utf-8").read()
4048
package_version = get_opencv_version()
4149

4250
packages = ['cv2', 'cv2.data']
43-
package_data = \
44-
{'cv2':
45-
['*%s' % sysconfig.get_config_var('SO')] + (['*.dll'] if os.name == 'nt' else []) +
51+
package_data = {
52+
'cv2':
53+
['*%s' % sysconfig.get_config_var('SO')] +
54+
['*.dll'] if os.name == 'nt' else [] +
4655
["LICENSE.txt", "LICENSE-3RD-PARTY.txt"],
47-
'cv2.data':
56+
'cv2.data':
4857
["*.xml"]
49-
}
58+
}
5059

5160
# Files from CMake output to copy to package.
5261
# Path regexes with forward slashes relative to CMake install dir.
53-
rearrange_cmake_output_data = \
54-
{'cv2':
55-
([r'bin/opencv_ffmpeg\d{3}%s\.dll' %
56-
('_64' if x64 else '')] if os.name == 'nt' else []
57-
) + \
62+
rearrange_cmake_output_data = {
63+
'cv2': [r'bin/opencv_ffmpeg\d{3}%s\.dll' % ('_64' if x64 else '')] if os.name == 'nt' else [] +
5864
# In Windows, in python/X.Y/<arch>/; in Linux, in just python/X.Y/.
5965
# Naming conventions vary so widely between versions and OSes
6066
# had to give up on checking them.
61-
['python/([^/]+/){1,2}cv2[^/]*%(ext)s' % {
62-
'ext': re.escape(sysconfig.get_config_var('SO'))
63-
}
64-
],
65-
'cv2.data':
66-
[ # OPENCV_OTHER_INSTALL_PATH
67-
('etc' if os.name =='nt' else 'share/OpenCV')
68-
+ r'/haarcascades/.*\.xml']
69-
}
67+
['python/([^/]+/){1,2}cv2[^/]*%(ext)s' % {'ext': re.escape(sysconfig.get_config_var('SO'))}],
68+
'cv2.data': [ # OPENCV_OTHER_INSTALL_PATH
69+
('etc' if os.name == 'nt' else 'share/OpenCV') +
70+
r'/haarcascades/.*\.xml'
71+
]
72+
}
73+
7074
# Files in sourcetree outside package dir that should be copied to package.
7175
# Raw paths relative to sourcetree root.
72-
files_outside_package_dir = \
73-
{'cv2':
74-
['LICENSE.txt', 'LICENSE-3RD-PARTY.txt']
75-
}
76+
files_outside_package_dir = {
77+
'cv2': ['LICENSE.txt', 'LICENSE-3RD-PARTY.txt']
78+
}
7679

7780
cmake_args = ([
7881
"-G", "Visual Studio 14" + (" Win64" if x64 else '')
7982
] if os.name == 'nt' else [
80-
"-G", "Unix Makefiles" #don't make CMake try (and fail) Ninja first
81-
]) + \
83+
"-G", "Unix Makefiles" # don't make CMake try (and fail) Ninja first
84+
]) +
8285
[
8386
# skbuild inserts PYTHON_* vars. That doesn't satisfy opencv build scripts in case of Py3
8487
"-DPYTHON%d_EXECUTABLE=%s" % (sys.version_info[0], sys.executable),
@@ -92,30 +95,29 @@ def main():
9295
"-DBUILD_TESTS=OFF",
9396
"-DBUILD_PERF_TESTS=OFF",
9497
"-DBUILD_DOCS=OFF"
95-
] + \
96-
([ "-DOPENCV_EXTRA_MODULES_PATH=" + os.path.abspath("opencv_contrib/modules") ]
97-
if build_contrib else [])
98-
98+
] +
99+
(["-DOPENCV_EXTRA_MODULES_PATH=" + os.path.abspath("opencv_contrib/modules")] if build_contrib else [])
100+
99101
# OS-specific components
100102
if sys.platform == 'darwin' or sys.platform.startswith('linux'):
101-
cmake_args.append( "-DWITH_QT=4" )
103+
cmake_args.append("-DWITH_QT=4")
104+
102105
if sys.platform.startswith('linux'):
103-
cmake_args.append( "-DWITH_V4L=ON" )
106+
cmake_args.append("-DWITH_V4L=ON")
107+
104108
if all(v in os.environ for v in ('JPEG_INCLUDE_DIR', 'JPEG_LIBRARY')):
105109
cmake_args += [
106-
"-DBUILD_JPEG=OFF",
107-
"-DJPEG_INCLUDE_DIR=%s" % os.environ['JPEG_INCLUDE_DIR'],
108-
"-DJPEG_LIBRARY=%s" % os.environ['JPEG_LIBRARY']
110+
"-DBUILD_JPEG=OFF",
111+
"-DJPEG_INCLUDE_DIR=%s" % os.environ['JPEG_INCLUDE_DIR'],
112+
"-DJPEG_LIBRARY=%s" % os.environ['JPEG_LIBRARY']
109113
]
110-
114+
111115
# Turn off broken components
112116
if sys.platform == 'darwin':
113117
cmake_args.append("-DWITH_LAPACK=OFF") # Some OSX LAPACK fns are incompatible, see
114118
# https://github.com/skvark/opencv-python/issues/21
115119
if sys.platform.startswith('linux'):
116-
cmake_args.append( "-DWITH_IPP=OFF" ) # https://github.com/opencv/opencv/issues/10411
117-
118-
120+
cmake_args.append("-DWITH_IPP=OFF") # https://github.com/opencv/opencv/issues/10411
119121

120122
# ABI config variables are introduced in PEP 425
121123
if sys.version_info[:2] < (3, 2):
@@ -125,7 +127,6 @@ def main():
125127
category=RuntimeWarning)
126128
del warnings
127129

128-
129130
# works via side effect
130131
RearrangeCMakeOutput(rearrange_cmake_output_data,
131132
files_outside_package_dir,
@@ -175,8 +176,10 @@ def main():
175176

176177

177178
class RearrangeCMakeOutput(object):
178-
"""Patch SKBuild logic to only take files related to the Python package
179-
and construct a file hierarchy that SKBuild expects (see below)"""
179+
"""
180+
Patch SKBuild logic to only take files related to the Python package
181+
and construct a file hierarchy that SKBuild expects (see below)
182+
"""
180183
_setuptools_wrap = None
181184

182185
# Have to wrap a function reference, or it's converted
@@ -202,6 +205,7 @@ def __init__(self, package_paths_re, files_outside_package, packages):
202205
cls.package_paths_re = package_paths_re
203206
cls.files_outside_package = files_outside_package
204207
cls.packages = packages
208+
205209
def __del__(self):
206210
cls = self.__class__
207211
cls._setuptools_wrap._classify_files = cls.wraps._classify_files
@@ -214,15 +218,18 @@ def _classify_files_override(self, install_paths,
214218
scripts, new_scripts,
215219
data_files,
216220
cmake_source_dir, cmake_install_reldir):
217-
"""From all CMake output, we're only interested in a few files
218-
and must place them into CMake install dir according
219-
to Python conventions for SKBuild to find them:
220-
package\
221-
file
222-
subpackage\
223-
etc.
224221
"""
222+
From all CMake output, we're only interested in a few files
223+
and must place them into CMake install dir according
224+
to Python conventions for SKBuild to find them:
225+
package\
226+
file
227+
subpackage\
228+
etc.
229+
"""
230+
225231
cls = self.__class__
232+
226233
# 'relpath'/'reldir' = relative to CMAKE_INSTALL_DIR/cmake_install_dir
227234
# 'path'/'dir' = relative to sourcetree root
228235
cmake_install_dir = os.path.join(cls._setuptools_wrap.CMAKE_INSTALL_DIR,
@@ -283,19 +290,15 @@ def _classify_files_override(self, install_paths,
283290
py_modules, new_py_modules,
284291
scripts, new_scripts,
285292
data_files,
286-
# To get around a demented check
287-
# that prepends source dir to paths and breaks package detection code.
288-
# Can't imagine what the authors were thinking that should be doing.
289-
cmake_source_dir = '',
290-
cmake_install_dir = cmake_install_reldir
291-
)
293+
# To get around a check that prepends source dir to paths and breaks package detection code.
294+
cmake_source_dir='',
295+
cmake_install_dir=cmake_install_reldir
296+
)
292297

293298

294299
def install_packages(*requirements):
295300
# No more convenient way until PEP 518 is implemented; setuptools only handles eggs
296-
subprocess.check_call([sys.executable,
297-
"-m", "pip", "install"]
298-
+ list(requirements))
301+
subprocess.check_call([sys.executable, "-m", "pip", "install"] + list(requirements))
299302

300303

301304
def get_opencv_version():
@@ -320,19 +323,18 @@ def get_build_contrib():
320323
return build_contrib
321324

322325

323-
def get_or_install(name, version = None):
326+
def get_or_install(name, version=None):
324327
"""If a package is already installed, build against it. If not, install"""
325328
# Do not import 3rd-party modules into the current process
326329
import json
327330
js_packages = json.loads(
328-
subprocess.check_output(
329-
[sys.executable, "-m", "pip", "list", "--format=json"])
330-
.decode('ascii')) #valid names & versions are ASCII as per PEP 440
331+
subprocess.check_output([sys.executable, "-m", "pip", "list", "--format=json"])
332+
.decode('ascii')) # valid names & versions are ASCII as per PEP 440
331333
try:
332334
[package] = (package for package in js_packages
333335
if package['name'] == name)
334336
except ValueError:
335-
install_packages("%s==%s"%(name, version) if version else name)
337+
install_packages("%s==%s" % (name, version) if version else name)
336338
return version
337339
else:
338340
return package['version']

0 commit comments

Comments
 (0)