-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsetup.py
143 lines (120 loc) · 4.3 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
#!/usr/bin/env python3
import os
import re
import subprocess
from distutils.core import setup, Command
from distutils.command.sdist import sdist as _sdist
from distutils.command.build import build as _build
REPOSITORY_URL = "https://github.com/metabrainz/mb-rngpy"
DOWNLOAD_URL = "{url}/archive/v-{version}.tar.gz"
VERSION_PATH = "mbrng/__init__.py"
# The following code is taken from
# https://github.com/warner/python-ecdsa/blob/f03abf93968019758c6e00753d1b34b87fecd27e/setup.py
# which is released under the MIT license (see LICENSE for the full license
# text) and (c) 2012 Brian Warner
VERSION_PY = """
# This file is originally generated from Git information by running 'setup.py
# version'. Distribution tarballs contain a pre-generated copy of this file.
__version__ = '%s'
"""
def update_version_py():
if not os.path.isdir(".git"):
print("This does not appear to be a Git repository.")
write_init_py()
return
try:
p = subprocess.Popen(["git", "describe",
"--tags", "--dirty", "--always"],
stdout=subprocess.PIPE)
except EnvironmentError:
print("Unable to run git.")
write_init_py()
return
stdout = p.communicate()[0]
if p.returncode != 0:
print("Running git failed.")
write_init_py()
return
version = stdout.decode('utf-8').strip()
if version.startswith('v-'):
version = version[2:]
write_init_py(version)
def write_init_py(version="unknown"):
if version == "unknown" and os.path.isfile(VERSION_PATH):
print("Skip erasing version in '{path}'.".format(
path=VERSION_PATH))
return
f = open(VERSION_PATH, "w")
f.write(VERSION_PY % version)
f.close()
print("Set version to '{version}' in '{path}'.".format(
path=VERSION_PATH, version=version))
def get_version():
try:
f = open(VERSION_PATH)
except IOError as e:
import errno
if e.errno == errno.ENOENT:
update_version_py()
return get_version()
except EnvironmentError:
return None
for line in f.readlines():
mo = re.match("__version__ = '([^']+)'", line)
if mo:
version = mo.group(1)
return version
return None
class Version(Command):
description = "Update '{path}' from Git repository.".format(
path=VERSION_PATH)
user_options = []
boolean_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
update_version_py()
print("Version is now '{0}'.".format(get_version()))
class sdist(_sdist):
def run(self):
update_version_py()
# unless we update this, the sdist command will keep using the old
# version
self.distribution.metadata.version = get_version()
return _sdist.run(self)
class build(_build):
def run(self):
update_version_py()
# unless we update this, the build command will keep using the old
# version
self.distribution.metadata.version = get_version()
return _build.run(self)
# Here ends the code taken from Brian Warner
def download_url(version):
return DOWNLOAD_URL.format(url=REPOSITORY_URL, version=version)
setup(name="mb-rngpy",
python_requires=">=3",
version=get_version(),
author="Wieland Hoffmann",
author_email="themineo@gmail.com",
description="Python bindings for the "
"MusicBrainz XML Metadata RELAX NG schema",
long_description="Python bindings for the "
"MusicBrainz XML Metadata RELAX NG schema",
packages=["mbrng"],
package_dir={"mbrng": "mbrng"},
install_requires=["lxml==4.9.1"],
download_url=download_url(get_version()),
url=REPOSITORY_URL,
license="MIT",
classifiers=["Development Status :: 5 - Production/Stable",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Topic :: Software Development :: Libraries "
":: Python Modules"],
cmdclass={"version": Version, "sdist": sdist, "build": build}
)