code: def main():
      os.chdir(os.path.dirname(os.path.abspath(__file__)))
  
      CI_BUILD = os.environ.get("CI_BUILD", "False")
      is_CI_build = True if CI_BUILD == "1" else False
      cmake_source_dir = "opencv"
      minimum_supported_numpy = "1.13.3"
      build_contrib = get_build_env_var_by_name("contrib")
      build_headless = get_build_env_var_by_name("headless")
      build_java = "ON" if get_build_env_var_by_name("java") else "OFF"
      build_rolling = get_build_env_var_by_name("rolling")
  
      install_requires = [
          'numpy>=1.13.3; python_version<"3.7"',
          'numpy>=1.17.0; python_version>="3.7"',  # https://github.com/numpy/numpy/pull/13725
          'numpy>=1.17.3; python_version>="3.8"',
          'numpy>=1.19.3; python_version>="3.9"',
          'numpy>=1.21.2; python_version>="3.10"',
          'numpy>=1.19.3; python_version>="3.6" and platform_system=="Linux" and platform_machine=="aarch64"',
          'numpy>=1.21.0; python_version<="3.9" and platform_system=="Darwin" and platform_machine=="arm64"',
          'numpy>=1.21.4; python_version>="3.10" and platform_system=="Darwin"',
          "numpy>=1.23.5; python_version>='3.11'",
          "numpy>=1.26.0; python_version>='3.12'",
      ]
  
      python_version = cmaker.CMaker.get_python_version()
      python_lib_path = (
          cmaker.CMaker.get_python_library(python_version) or ""
      )
      # HACK: For Scikit-build 0.17.3 and newer that returns None or empty sptring for PYTHON_LIBRARY in manylinux2014
      # A small release related to PYTHON_LIBRARY handling changes in 0.17.2; scikit-build 0.17.3 returns an empty string from get_python_library if no Python library is present (like on manylinux), where 0.17.2 returned None, and previous versions returned a non-existent path. Note that adding REQUIRED to find_package(PythonLibs will fail, but it is incorrect (you must not link to libPython.so) and was really just injecting a non-existent path before.
      # TODO: Remove the hack when the issue is handled correctly in main OpenCV CMake.
      if python_lib_path == "":
          python_lib_path = "libpython%sm.a" % python_version
      python_lib_path = python_lib_path.replace("\\", "/")
  
      python_include_dir = cmaker.CMaker.get_python_include_dir(
          python_version
      ).replace("\\", "/")
  
      if os.path.exists(".git"):
          import pip._internal.vcs.git as git
  
          g = (
              git.Git()
          )  # NOTE: pip API's are internal, this has to be refactored
  
          g.run_command(["submodule", "sync"])
  
          if build_rolling:
              g.run_command(
                  [
                      "submodule",
                      "update",
                      "--init",
                      "--recursive",
                      "--remote",
                      cmake_source_dir,
                  ]
              )
  
              if build_contrib:
                  g.run_command(
                      [
                          "submodule",
                          "update",
                          "--init",
                          "--recursive",
                          "--remote",
                          "opencv_contrib",
                      ]
                  )
          else:
              g.run_command(
                  [
                      "submodule",
                      "update",
                      "--init",
                      "--recursive",
                      cmake_source_dir,
                  ]
              )
  
              if build_contrib:
                  g.run_command(
                      [
                          "submodule",
                          "update",
                          "--init",
                          "--recursive",
                          "opencv_contrib",
                      ]
                  )
  
      (
          package_version,
          build_contrib,
          build_headless,
          build_rolling,
      ) = get_and_set_info(
          build_contrib, build_headless, build_rolling, is_CI_build
      )
  
      # https://stackoverflow.com/questions/1405913/python-32bit-or-64bit-mode
      is64 = sys.maxsize > 2**32
  
      package_name = "opencv-python"
  
      if build_contrib and not build_headless:
          package_name = "opencv-contrib-python"
  
      if build_contrib and build_headless:
          package_name = "opencv-contrib-python-headless"
  
      if build_headless and not build_contrib:
          package_name = "opencv-python-headless"
  
      if build_rolling:
          package_name += "-rolling"
  
      long_description = io.open("README.md", encoding="utf-8").read()
  
      packages = ["cv2", "cv2.data"]
  
      package_data = {
          "cv2": [
              "*%s" % sysconfig.get_config_vars().get("SO"),
              "version.py",
          ]
          + (["*.dll"] if os.name == "nt" else [])
          + ["LICENSE.txt", "LICENSE-3RD-PARTY.txt"],
          "cv2.data": ["*.xml"],
      }
  
      # Files from CMake output to copy to package.
      # Path regexes with forward slashes relative to CMake install dir.
      rearrange_cmake_output_data = {
          "cv2": (
              [
                  r"bin/opencv_videoio_ffmpeg\d{3}%s\.dll"
                  % ("_64" if is64 else "")
              ]
              if os.name == "nt"
              else []
          )
          +
          # In Windows, in python/X.Y/<arch>/; in Linux, in just python/X.Y/.
          # Naming conventions vary so widely between versions and OSes
          # had to give up on checking them.
          [r"python/cv2/python-%s/cv2.*" % (sys.version_info[0])]
          + [r"python/cv2/__init__.py"]
          + [r"python/cv2/.*config.*.py"]
          + [r"python/cv2/py.typed"]
          if sys.version_info >= (3, 6)
          else [],
          "cv2.data": [  # OPENCV_OTHER_INSTALL_PATH
              ("etc" if os.name == "nt" else "share/opencv4")
              + r"/haarcascades/.*\.xml"
          ],
          "cv2.gapi": ["python/cv2" + r"/gapi/.*\.py"],
          "cv2.mat_wrapper": ["python/cv2" + r"/mat_wrapper/.*\.py"],
          "cv2.misc": ["python/cv2" + r"/misc/.*\.py"],
          "cv2.utils": ["python/cv2" + r"/utils/.*\.py"],
      }
  
      if sys.version_info >= (3, 6):
          rearrange_cmake_output_data["cv2.typing"] = [
              "python/cv2" + r"/typing/.*\.py"
          ]
  
      # Files in sourcetree outside package dir that should be copied to package.
      # Raw paths relative to sourcetree root.
      files_outside_package_dir = {
          "cv2": ["LICENSE.txt", "LICENSE-3RD-PARTY.txt"]
      }
  
      ci_cmake_generator = (
          ["-G", "Visual Studio 14" + (" Win64" if is64 else "")]
          if os.name == "nt"
          else ["-G", "Unix Makefiles"]
      )
  
      cmake_args = (
          (ci_cmake_generator if is_CI_build else [])
          + [
              # skbuild inserts PYTHON_* vars. That doesn't satisfy opencv build scripts in case of Py3
              "-DPYTHON3_EXECUTABLE=%s" % sys.executable,
              "-DPYTHON_DEFAULT_EXECUTABLE=%s" % sys.executable,
              "-DPYTHON3_INCLUDE_DIR=%s" % python_include_dir,
              "-DPYTHON3_LIBRARY=%s" % python_lib_path,
              "-DBUILD_opencv_python3=ON",
              "-DBUILD_opencv_python2=OFF",
              # Disable the Java build by default as it is not needed
              "-DBUILD_opencv_java=%s" % build_java,
              # Relative dir to install the built module to in the build tree.
              # The default is generated from sysconfig, we'd rather have a constant for simplicity
              "-DOPENCV_PYTHON3_INSTALL_PATH=python",
              # Otherwise, opencv scripts would want to install `.pyd' right into site-packages,
              # and skbuild bails out on seeing that
              "-DINSTALL_CREATE_DISTRIB=ON",
              # See opencv/CMakeLists.txt for options and defaults
              "-DBUILD_opencv_apps=OFF",
              "-DBUILD_opencv_freetype=OFF",
              "-DBUILD_SHARED_LIBS=OFF",
              "-DBUILD_TESTS=OFF",
              "-DBUILD_PERF_TESTS=OFF",
              "-DBUILD_DOCS=OFF",
              "-DPYTHON3_LIMITED_API=ON",
              "-DBUILD_OPENEXR=ON",
          ]
          + (
              # CMake flags for windows/arm64 build
              [
                  "-DCMAKE_GENERATOR_PLATFORM=ARM64",
                  # Emulated cmake requires following flags to correctly detect
                  # target architecture for windows/arm64 build
                  "-DOPENCV_WORKAROUND_CMAKE_20989=ON",
                  "-DCMAKE_SYSTEM_PROCESSOR=ARM64",
              ]
              if platform.machine() == "ARM64"
              and sys.platform == "win32"
              # If it is not defined 'linker flags: /machine:X86' on Windows x64
              else ["-DCMAKE_GENERATOR_PLATFORM=x64"]
              if is64 and sys.platform == "win32"
              else []
          )
          + (
              [
                  "-DOPENCV_EXTRA_MODULES_PATH="
                  + os.path.abspath("opencv_contrib/modules")
              ]
              if build_contrib
              else []
          )
      )
  
      if build_headless:
          # it seems that cocoa cannot be disabled so on macOS the package is not truly headless
          cmake_args.append("-DWITH_WIN32UI=OFF")
          cmake_args.append("-DWITH_QT=OFF")
          cmake_args.append("-DWITH_GTK=OFF")
          if is_CI_build:
              cmake_args.append(
                  "-DWITH_MSMF=OFF"
              )  # see: https://github.com/skvark/opencv-python/issues/263
  
      if (
          sys.platform.startswith("linux")
          and not is64
          and "bdist_wheel" in sys.argv
      ):
          subprocess.check_call(
              "patch -p0 < patches/patchOpenEXR", shell=True
          )
  
      # OS-specific components during CI builds
      if is_CI_build:
          if (
              not build_headless
              and "bdist_wheel" in sys.argv
              and sys.platform.startswith("linux")
          ):
              cmake_args.append("-DWITH_QT=5")
              subprocess.check_call(
                  "patch -p1 < patches/patchQtPlugins", shell=True
              )
  
              if sys.platform.startswith("linux"):
                  rearrange_cmake_output_data[
                      "cv2.qt.plugins.platforms"
                  ] = [(r"lib/qt/plugins/platforms/libqxcb\.so")]
  
                  # add fonts for Qt5
                  fonts = []
                  for file in os.listdir("/usr/share/fonts/dejavu"):
                      if file.endswith(".ttf"):
                          fonts.append(
                              (
                                  r"lib/qt/fonts/dejavu/%s\.ttf"
                                  % file.split(".")[0]
                              )
                          )
  
                  rearrange_cmake_output_data["cv2.qt.fonts"] = fonts
  
              if sys.platform == "darwin":
                  rearrange_cmake_output_data[
                      "cv2.qt.plugins.platforms"
                  ] = [(r"lib/qt/plugins/platforms/libqcocoa\.dylib")]
  
          if sys.platform.startswith("linux"):
              cmake_args.append("-DWITH_V4L=ON")
              cmake_args.append("-DWITH_LAPACK=ON")
              cmake_args.append("-DENABLE_PRECOMPILED_HEADERS=OFF")
  
      # works via side effect
      RearrangeCMakeOutput(
          rearrange_cmake_output_data,
          files_outside_package_dir,
          package_data.keys(),
      )
  
      setup(
          name=package_name,
          version=package_version,
          url="https://github.com/opencv/opencv-python",
          license="Apache 2.0",
          description="Wrapper package for OpenCV python bindings.",
          long_description=long_description,
          long_description_content_type="text/markdown",
          packages=packages,
          package_data=package_data,
          maintainer="OpenCV Team",
          ext_modules=EmptyListWithLength(),
          install_requires=install_requires,
          python_requires=">=3.6",
          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 :: Apache Software License",
              "Operating System :: MacOS",
              "Operating System :: Microsoft :: Windows",
              "Operating System :: POSIX",
              "Operating System :: Unix",
              "Programming Language :: Python",
              "Programming Language :: Python :: 3",
              "Programming Language :: Python :: 3 :: Only",
              "Programming Language :: Python :: 3.6",
              "Programming Language :: Python :: 3.7",
              "Programming Language :: Python :: 3.8",
              "Programming Language :: Python :: 3.9",
              "Programming Language :: Python :: 3.10",
              "Programming Language :: Python :: 3.11",
              "Programming Language :: Python :: 3.12",
              "Programming Language :: C++",
              "Programming Language :: Python :: Implementation :: CPython",
              "Topic :: Scientific/Engineering",
              "Topic :: Scientific/Engineering :: Image Recognition",
              "Topic :: Software Development",
          ],
          cmake_args=cmake_args,
          cmake_source_dir=cmake_source_dir,
      )
  
      print(
          "OpenCV is raising funds to keep the library free for everyone, and we need the support of the entire community to do it. Donate to OpenCV on IndieGoGo:\nhttps://www.indiegogo.com/projects/opencv-5-support-non-profit-open-source-cv-ai#/"
      )
  
file_path: opencv-python/setup.py
imports: import io
  import os
  import os.path
  import sys
  import runpy
  import subprocess
  import re
  import sysconfig
  import platform
  from skbuild import cmaker, setup
label_desc: Use image node_id 1 for calling a global function with example usage: main() without return types