forked from markreidvfx/pyavb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
130 lines (105 loc) · 4.02 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import os
import sys
from setuptools import setup, find_packages
import setuptools.command.build_py
import setuptools.command.build_ext
from distutils.extension import Extension
PROJECT_METADATA = {
"version": "1.3.0",
"author": 'Mark Reid',
"author_email": '[email protected]',
"license": 'MIT',
}
METADATA_TEMPLATE = """
__version__ = "{version}"
__author__ = "{author}"
__author_email__ = "{author_email}"
__license__ = "{license}"
"""
sourcefiles = [
"src/avb/_ext.pyx",
]
extensions =[]
try:
from Cython.Build import cythonize
if int(os.environ.get("PYAVB_BUILD_EXT", '1')):
extensions = cythonize([Extension("avb._ext",
sourcefiles,
language="c++")])
except ImportError as e:
print('unable to build optional cython extension')
class PyavbBuildExt(setuptools.command.build_ext.build_ext):
"""Custom Extension command"""
def build_extensions(self):
for ext in self.extensions:
flags = []
if self.compiler.compiler_type == 'msvc':
if sys.version_info[0] == 2:
# If we are compiling for Python 2.7 on Windows, statically link
# the runtime libraries. THis will allow to compile using an
# msvc greater than the one used to compile Python 2.7.
# See See https://docs.microsoft.com/en-us/cpp/build/reference/md-mt-ld-use-run-time-library?view=msvc-160.
flags.append('/MT')
flags.append('/O2')
else:
flags.extend(['-g0', '-O3'])
ext.extra_compile_args = flags
setuptools.command.build_ext.build_ext.build_extensions(self)
class AddMetadata(setuptools.command.build_py.build_py):
"""Stamps PROJECT_METADATA into __init__ files."""
def run(self):
setuptools.command.build_py.build_py.run(self)
if self.dry_run:
return
target_file = os.path.join(self.build_lib, 'avb', "__init__.py")
source_file = os.path.join(os.path.dirname(__file__), 'src', 'avb', "__init__.py")
# get the base data from the original file
with open(source_file, 'r') as fi:
src_data = fi.read()
# write that + the suffix to the target file
with open(target_file, 'w') as fo:
fo.write(src_data)
fo.write(METADATA_TEMPLATE.format(**PROJECT_METADATA))
setup(
name='pyavb',
description='A python module for the reading and writing Avid Bin Files files.',
url='https://github.com/markreidvfx/pyavb',
project_urls={
'Source':
'https://github.com/markreidvfx/pyavb',
'Documentation':
'http://pyavb.readthedocs.io',
'Issues':
'https://github.com/markreidvfx/pyavb/issues',
},
classifiers=[
'Development Status :: 3 - Alpha',
'Topic :: Multimedia :: Graphics',
'Topic :: Multimedia :: Video',
'Topic :: Multimedia :: Video :: Display',
'Topic :: Multimedia :: Video :: Non-Linear Editor',
'Topic :: Software Development :: Libraries :: Python Modules',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Operating System :: OS Independent',
'Natural Language :: English',
],
keywords='film tv editing editorial edit non-linear edl time',
platforms='any',
packages=['avb'],
package_dir={'': 'src'},
cmdclass={
'build_py': AddMetadata,
'build_ext': PyavbBuildExt
},
ext_modules = extensions,
extras_require= {'cython' : ['cython']},
python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*, !=3.5.*, !=3.6.*',
**PROJECT_METADATA
)