forked from otsaloma/catapult
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-partial.py
More file actions
executable file
·46 lines (37 loc) · 1.46 KB
/
Copy pathsetup-partial.py
File metadata and controls
executable file
·46 lines (37 loc) · 1.46 KB
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
#!/usr/bin/env python3
import os
import re
from pathlib import Path
from setuptools import find_packages
from setuptools import setup
from setuptools.command.install_lib import install_lib
class InstallLib(install_lib):
def install(self):
# Patch installation paths into catapult/__init__.py.
prefix = os.getenv("CATAPULT_PREFIX", "/usr/local")
data_dir = Path(prefix) / "share" / "catapult"
locale_dir = Path(prefix) / "share" / "locale"
init_path = Path(self.build_dir) / "catapult" / "__init__.py"
init_text = init_path.read_text("utf-8")
patt = r"^DATA_DIR = .*$"
repl = f"DATA_DIR = Path({str(data_dir)!r})"
init_text = re.sub(patt, repl, init_text, flags=re.MULTILINE)
assert init_text.count(repl) == 1
patt = r"^LOCALE_DIR = .*$"
repl = f"LOCALE_DIR = Path({str(locale_dir)!r})"
init_text = re.sub(patt, repl, init_text, flags=re.MULTILINE)
assert init_text.count(repl) == 1
init_path.write_text(init_text, "utf-8")
return install_lib.install(self)
def get_version(fm="catapult/__init__.py"):
for line in Path(fm).read_text("utf-8").splitlines():
if line.startswith("__version__ = "):
return line.split()[-1].strip('"')
assert get_version()
setup(
name="catapult",
version=get_version(),
packages=find_packages(exclude=["*.test"]),
scripts=["bin/catapult-start"],
cmdclass={"install_lib": InstallLib},
)