-
Notifications
You must be signed in to change notification settings - Fork 185
/
setup.py
165 lines (146 loc) · 6.33 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/usr/bin/env python
# setup.py file for Verovio
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext as _build_ext
from setuptools.command.sdist import sdist as _sdist
from glob import glob
import platform
import os
import subprocess
class build_ext(_build_ext):
"""Override build_ext and sdist commands to generate the git version header file."""
def run(self):
# generate the git commit include file
get_commit()
_build_ext.run(self)
class sdist(_sdist):
"""Override build_sdist and sdist commands to generate the git version header file."""
def run(self):
# generate the git commit include file
get_commit()
_sdist.run(self)
def get_commit():
"""Call tools/get_git_commit.sh on any platform."""
if os.path.exists('./tools'):
print('running tools/get_git_commit.sh')
os.system('sh -c "cd tools; ./get_git_commit.sh"')
else:
print('tools directory is missing')
def get_readme() -> str:
"""Read the README file into the long_description."""
with open('README.md', 'r') as fh:
return fh.read()
def get_version() -> str:
"""Get the version from the header file and the git sha for dev versions."""
version = '0.0.0'
# If we have a PKG-INFO (e.g., in a sdist) use that
if os.path.exists('PKG-INFO'):
with open('PKG-INFO', 'r') as f:
lines = f.readlines()
for line in lines:
if line.startswith('Version:'):
return line[8:].strip()
with open('./include/vrv/vrvdef.h') as header_file:
defines = {}
for line in header_file:
if not line.startswith('#define'):
continue
definition = line.strip().split()
if len(definition) < 3:
continue
defines[definition[1]] = definition[2]
# as long as we don't need all defines
if 'vrv_cast' in defines:
break
version = '.'.join(
(defines['VERSION_MAJOR'], defines['VERSION_MINOR'], defines['VERSION_REVISION']))
if defines['VERSION_DEV'] == 'true':
version += '.dev'
if version.endswith('.dev'):
init_sha = subprocess.getoutput(
'git log -n 1 --pretty=format:%H -- bindings/python/.pypi-version')
count = subprocess.getoutput(
'git rev-list --count HEAD "^{}"'.format(init_sha))
version += count
print(version)
return version
# extra compile arguments
EXTRA_COMPILE_ARGS = ['-DPYTHON_BINDING']
if platform.system() != 'Windows':
EXTRA_COMPILE_ARGS += ['-std=c++23',
'-Wno-write-strings', '-Wno-overloaded-virtual', '-g0']
else:
EXTRA_COMPILE_ARGS += ['/std:c++23',
'-DNO_PAE_SUPPORT']
verovio_module = Extension('verovio._verovio',
sources=
glob('./src/*.cpp') +
glob('./src/hum/*.cpp') +
glob('./libmei/dist/*.cpp') +
glob('./libmei/addons/*.cpp') +
[
'./src/crc/crc.cpp',
'./src/json/jsonxx.cc',
'./src/pugi/pugixml.cpp',
'./src/midi/Binasc.cpp',
'./src/midi/MidiEvent.cpp',
'./src/midi/MidiEventList.cpp',
'./src/midi/MidiFile.cpp',
'./src/midi/MidiMessage.cpp',
'./bindings/python/verovio.i'],
swig_opts=['-c++', '-fastproxy', '-olddefs',
'-outdir', './bindings/python', '-doxygen'],
include_dirs=['./include/vrv',
'./include/crc',
'./include/json',
'./include/midi',
'./include/hum',
'./include/pugi',
'./include/win32',
'./include/zip',
'./libmei/dist',
'./libmei/addons'],
extra_compile_args=EXTRA_COMPILE_ARGS
)
setup(name='verovio',
version=get_version(),
cmdclass={'sdist': sdist, 'build_ext': build_ext},
url="https://www.verovio.org",
description="""A library and toolkit for engraving MEI music notation into SVG""",
long_description=get_readme(),
long_description_content_type="text/markdown",
license='LGPLv3',
classifiers=[
'License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)',
'Programming Language :: Python :: 3',
'Programming Language :: C++',
'Operating System :: OS Independent'
],
ext_modules=[verovio_module],
packages=['verovio',
'verovio.data',
'verovio.data.Bravura',
'verovio.data.Gootville',
'verovio.data.Leipzig',
'verovio.data.Leland',
'verovio.data.Petaluma',
'verovio.data.text'],
# cf. https://docs.python.org/3/distutils/examples.html#pure-python-distribution-by-package
package_dir={'verovio': './bindings/python',
'verovio.data': './data'},
package_data={
'verovio': ['py.typed'],
'verovio.data': [f for f in os.listdir('./data') if (f.endswith('.xml') or f.endswith(".css") or f.endswith(".svg"))],
'verovio.data.Bravura': os.listdir('./data/Bravura'),
'verovio.data.Gootville': os.listdir('./data/Gootville'),
'verovio.data.Leipzig': os.listdir('./data/Leipzig'),
'verovio.data.Leland': os.listdir('./data/Leland'),
'verovio.data.Petaluma': os.listdir('./data/Petaluma'),
'verovio.data.text': os.listdir('./data/text'),
},
python_requires='>=3.9',
project_urls={
'Bug Reports': 'https://github.com/rism-digital/verovio/issues',
'Source': 'https://github.com/rism-digital/verovio',
},
)