setup.py 3.2 KB
Newer Older
O
Olli-Pekka Heinisuo 已提交
1
from setuptools import setup
2 3
from setuptools.dist import Distribution
import pip
O
Olli-Pekka Heinisuo 已提交
4 5
import os
import sys
6
import io
7

8 9 10
# cv_version.py should be generated by running find_version.py
from cv_version import opencv_version

11 12
contrib_build = False
package_name = "opencv-python"
13 14 15
numpy_version = ""
long_description = ""
package_data = {}
16

17 18 19 20 21 22 23 24 25 26 27 28 29 30
contrib = os.getenv('ENABLE_CONTRIB', None)

if contrib is not None:
    if int(contrib) == 1:
        contrib_build = True
else:
    try:
        print("Trying to read contrib enable flag from file...")
        with open("contrib.enabled") as f:
            flag = int(f.read(1))
            if flag == 1:
                contrib_build = True
    except:
        pass
31

32
# Use different README and package name for contrib build.
33 34
if contrib_build:
    package_name = "opencv-contrib-python"
35 36 37 38 39
    with io.open('README_CONTRIB.rst', encoding="utf-8") as f:
        long_description = f.read()
else:
    with io.open('README.rst', encoding="utf-8") as f:
        long_description = f.read()
40 41 42 43 44 45

# Get required numpy version
for package in pip.get_installed_distributions():
    if package.key == "numpy":
        numpy_version = package.version

46 47 48 49 50
if os.name == 'posix':
    package_data['cv2'] = ['*.so']
else:
    package_data['cv2'] = ['*.pyd', '*.dll']

J
Jon Winsley 已提交
51
package_data['cv2'] += ["LICENSE.txt", "LICENSE-3RD-PARTY.txt"]
52

O
Olli-Pekka Heinisuo 已提交
53 54 55 56 57
This is my old hack to force binary distribution.

However, it doesn't work properly because the binaries
are placed into purelib instead of platlib.

58
class BinaryDistribution(Distribution):
O
Olli-Pekka Heinisuo 已提交
59
    def has_ext_modules(self):
60 61
        return True

62 63
    def is_pure(self):
        return False
O
Olli-Pekka Heinisuo 已提交
64 65 66 67 68 69 70 71 72 73
"""

# This creates a list which is empty but returns a length of 1.
# Should make the wheel a binary distribution and platlib compliant.


class EmptyListWithLength(list):
    def __len__(self):
        return 1

74

75
setup(name=package_name,
O
Olli-Pekka Heinisuo 已提交
76
      version=opencv_version,
77 78 79
      url='https://github.com/skvark/opencv-python',
      license='MIT',
      description='Wrapper package for OpenCV python bindings.',
80
      long_description=long_description,
O
Olli-Pekka Heinisuo 已提交
81 82
      packages=['cv2'],
      package_data=package_data,
83 84
      maintainer="Olli-Pekka Heinisuo",
      include_package_data=True,
O
Olli-Pekka Heinisuo 已提交
85
      ext_modules=EmptyListWithLength(),
86
      install_requires="numpy>=%s" % numpy_version,
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
      classifiers=[
        'Development Status :: 5 - Production/Stable',
        'Environment :: Console',
        'Intended Audience :: Developers',
        'Intended Audience :: Education',
        'Intended Audience :: Information Technology',
        'Intended Audience :: Science/Research',
        'License :: OSI Approved :: MIT License',
        'Operating System :: MacOS',
        'Operating System :: Microsoft :: Windows',
        'Operating System :: POSIX',
        'Operating System :: Unix',
        'Programming Language :: Python',
        'Programming Language :: C++',
        'Programming Language :: Python :: Implementation :: CPython',
        'Topic :: Scientific/Engineering',
        'Topic :: Scientific/Engineering :: Image Recognition',
        'Topic :: Software Development',
        ]
106
      )