-
Notifications
You must be signed in to change notification settings - Fork 17
/
setup.py
118 lines (106 loc) · 3.4 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
import sys
import subprocess as sp
if sys.version_info[0:2] < (2, 7):
from distutils.core import setup
else:
from setuptools import setup
from simplemkv.tomp4 import __doc__
try:
from simplemkv.version import __version__
except ImportError:
__version__ = 'unknown'
# A list of classifiers can be found here:
# http://pypi.python.org/pypi?%3Aaction=list_classifiers
classifiers = """\
Natural Language :: English
Development Status :: 4 - Beta
Environment :: Console
Topic :: Multimedia
Topic :: Multimedia :: Sound/Audio :: Conversion
Topic :: Multimedia :: Video :: Conversion
Intended Audience :: End Users/Desktop
License :: OSI Approved :: MIT License
Programming Language :: Python
Programming Language :: Python :: 2
Programming Language :: Python :: 3
Operating System :: OS Independent
"""
def write_version(v):
f = open('simplemkv/version.py', 'w')
try:
f.write('__version__ = %s\n' % repr(v))
finally:
f.close()
def git_version():
cmd = ['git', 'describe', '--abbrev=4']
try:
proc = sp.Popen(cmd, stdout=sp.PIPE)
stdouts = proc.communicate()[0]
if stdouts is not str:
stdouts = stdouts.decode('utf_8')
stdout = stdouts.rstrip('\n')
except OSError:
sys.stderr.write('git not found: leaving __version__ alone\n')
return __version__
if proc.returncode != 0:
sys.stderr.write('git describe failed: leaving __version__ alone\n')
return __version__
ver = stdout.lstrip('mkvtomp4-v')
ver = ver.replace('-', '+', 1)
ver = ver.replace('-', '.')
write_version(ver)
try:
proc = sp.Popen(['git', 'update-index', '-q', '--refresh'])
proc.communicate()
except OSError:
return ver
if proc.returncode != 0:
return ver
try:
gitdiff = ['git', 'diff-index', '--name-only', 'HEAD', '--']
proc = sp.Popen(gitdiff, stdout=sp.PIPE)
stdout = proc.communicate()[0]
if stdout is not str:
stdout = stdout.decode('utf_8')
except OSError:
sys.stderr.write('git diff-index failed\n')
if stdout.strip('\n'):
ver = ver + '.dirty'
write_version(ver)
return ver
if sys.version_info < (2, 3):
_setup = setup
def setup(**kwargs):
if kwargs.has_key("classifiers"):
del kwargs["classifiers"]
_setup(**kwargs)
doclines_ = __doc__.split("\n")
if sys.version_info < (3,):
classifiersval = filter(None, classifiers.split("\n"))
else:
classifiersval = classifiers.split("\n")
codeopts = {
'name': 'mkvtomp4',
'description': doclines_[0],
'long_description': "\n".join(doclines_[2:]),
'author': 'Gavin Beatty',
'author_email': '[email protected]',
'maintainer': 'Gavin Beatty',
'maintainer_email': '[email protected]',
'license': 'http://opensource.org/licenses/MIT',
'platforms': ["any"],
'classifiers': classifiersval,
'url': 'https://github.com/gavinbeatty/mkvtomp4/',
'version': __version__,
'scripts': ['mkvtomp4.py'],
'py_modules': ['simplemkv.version', 'simplemkv.info', 'simplemkv.tomp4'],
}
fullopts = codeopts.copy()
fullopts['data_files'] = [
('share/doc/mkvtomp4', ['README.md', 'LICENSE', 'doc/mkvtomp4.txt']),
('share/man/man1', ['doc/mkvtomp4.1', 'doc/mkvtomp4.1.html']),
]
if __name__ == '__main__':
__version__ = git_version()
fullopts['version'] = __version__
setup(**fullopts)