setup.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import os
  2. import platform
  3. import subprocess
  4. import sys
  5. from setuptools import setup, Extension
  6. from setuptools.command.build_ext import build_ext
  7. # Adapted from here: https://github.com/pybind/cmake_example/blob/master/setup.py
  8. class CMakeExtension(Extension):
  9. def __init__(self, name, sourcedir=''):
  10. Extension.__init__(self, name, sources=[])
  11. self.sourcedir = os.path.abspath(sourcedir)
  12. class CMakeBuild(build_ext):
  13. def build_extension(self, ext):
  14. extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))
  15. cmake_args = ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir,
  16. '-DPython3_EXECUTABLE=' + sys.executable,
  17. '-DVERSION_INFO=' + self.distribution.get_version()]
  18. cfg = 'Debug' if self.debug else 'Release'
  19. build_args = ['--config', cfg,
  20. '-j', '8']
  21. if platform.system() == "Windows":
  22. cmake_args += ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}'.format(cfg.upper(), extdir)]
  23. if sys.maxsize > 2**32:
  24. cmake_args += ['-A', 'x64']
  25. else:
  26. cmake_args += ['-A', 'Win32']
  27. build_args += ['--', '/m']
  28. else:
  29. cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg]
  30. if not os.path.exists(self.build_temp):
  31. os.makedirs(self.build_temp)
  32. subprocess.check_call(['cmake', ext.sourcedir] + cmake_args, cwd=self.build_temp)
  33. subprocess.check_call(['cmake', '--build', '.'] + build_args, cwd=self.build_temp)
  34. with open("README.md", "r", encoding="utf-8") as fh:
  35. long_description = fh.read()
  36. setup(
  37. name='zxing-cpp',
  38. # setuptools_scm cannot be used because of the structure of the project until the following issues are solved:
  39. # https://github.com/pypa/setuptools_scm/issues/357
  40. # https://github.com/pypa/pip/issues/7549
  41. # Because pip works on a copy of current directory in a temporary directory, the temporary directory does not hold
  42. # the .git directory of the repo, so that setuptools_scm cannot guess the current version.
  43. # use_scm_version={
  44. # "root": "../..",
  45. # "version_scheme": "guess-next-dev",
  46. # "local_scheme": "no-local-version",
  47. # "tag_regex": "v?([0-9]+.[0-9]+.[0-9]+)",
  48. # },
  49. version='2.3.0',
  50. description='Python bindings for the zxing-cpp barcode library',
  51. long_description=long_description,
  52. long_description_content_type="text/markdown",
  53. author='ZXing-C++ Community',
  54. author_email='zxingcpp@gmail.com',
  55. url='https://github.com/zxing-cpp/zxing-cpp',
  56. license='Apache License 2.0',
  57. keywords=['barcode'],
  58. classifiers=[
  59. "Development Status :: 4 - Beta",
  60. "Programming Language :: Python :: 3",
  61. "License :: OSI Approved :: Apache Software License",
  62. "Operating System :: OS Independent",
  63. "Topic :: Multimedia :: Graphics",
  64. ],
  65. python_requires=">=3.6",
  66. ext_modules=[CMakeExtension('zxingcpp')],
  67. cmdclass=dict(build_ext=CMakeBuild),
  68. zip_safe=False,
  69. )