-
Notifications
You must be signed in to change notification settings - Fork 31
/
setup.py
55 lines (39 loc) · 1.49 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
"""setup.py to build package."""
import os
import pathlib
import re
import setuptools
import setuptools.command.bdist_rpm
# It might throw IndexError and so on.
VERSION = '0.1.0'
VER_REG = re.compile(r"^__version__ = '([^']+)'")
for fpath in pathlib.Path('src').glob('**/__init__.py'):
for line in fpath.open():
match = VER_REG.match(line)
if match:
VERSION = match.groups()[0]
break
# For daily snapshot versioning mode:
RELEASE = "1%{?dist}"
if os.environ.get("_SNAPSHOT_BUILD", None) is not None:
import datetime
RELEASE = RELEASE.replace('1',
datetime.datetime.now().strftime("%Y%m%d"))
def _replace(line):
"""Replace some strings in the RPM SPEC template."""
if "@VERSION@" in line:
return line.replace("@VERSION@", VERSION)
if "@RELEASE@" in line:
return line.replace("@RELEASE@", RELEASE)
if "Source0:" in line: # Dirty hack
return "Source0: %{pkgname}-%{version}.tar.gz"
return line
class bdist_rpm(setuptools.command.bdist_rpm.bdist_rpm):
"""Override the default content of the RPM SPEC."""
spec_tmpl = pathlib.Path('pkg/package.spec.in').resolve()
def _make_spec_file(self):
"""Generate the RPM SPEC file."""
return [_replace(line.rstrip()) for line in self.spec_tmpl.open()]
setuptools.setup(version=VERSION, cmdclass=dict(bdist_rpm=bdist_rpm),
data_files=[("share/man/man1", ["docs/anyconfig_cli.1"])])
# vim:sw=4:ts=4:et: