forked from gwnrtools/nr-catalog-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
124 lines (103 loc) · 3.74 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
#!/usr/bin/env python
# Copyright (c) 2023, Prayush Kumar
# See LICENSE file for details: <https://github.com/gwnrtools/nr-catalog-tools/blob/master/LICENSE>
from __future__ import print_function
import subprocess
from os import environ, path
from pathlib import Path
NAME = "nrcatalogtools"
VERSION = "v0.0.1"
def write_version_file(version):
"""Writes a file with version information to be used at run time
Parameters
----------
version: str
A string containing the current version information
Returns
-------
version_file: str
A path to the version file (relative to the src package directory)
"""
version_file = Path(NAME) / ".version"
try:
git_log = subprocess.check_output(
["git", "log", "-1", "--pretty=%h %ai"]
).decode("utf-8")
git_diff = (
subprocess.check_output(["git", "diff", "."])
+ subprocess.check_output(["git", "diff", "--cached", "."])
).decode("utf-8")
except subprocess.CalledProcessError as exc: # git calls failed
# we already have a version file, let's use it
if version_file.is_file():
return version_file.name
# otherwise error out
exc.args = (
"unable to obtain git version information, and {} doesn't "
"exist, cannot continue ({})".format(version_file, str(exc)),
)
raise
else:
git_version = "{}: ({}) {}".format(
version, "UNCLEAN" if git_diff else "CLEAN", git_log.rstrip()
)
print("parsed git version info as: {!r}".format(git_version))
try:
with open(version_file, "w") as f:
print(git_version, file=f)
print("created {}".format(version_file))
except Exception:
with open(str(version_file), "w") as f:
print(git_version, file=f)
print("created {}".format(version_file))
return version_file.name
def get_long_description():
"""Finds the README and reads in the description"""
here = path.abspath(path.dirname(__file__))
with open(path.join(here, "README.md")) as f:
long_description = f.read()
return long_description
def get_requirements():
with open("requirements.txt") as ff:
requirements = ff.readlines()
return requirements
if "package_version" in environ:
version = environ["package_version"]
print("Setup.py using environment version='{0}'".format(version))
else:
print("The variable 'package_version' was not present in the environment")
try:
from subprocess import check_output
version = (
check_output(
"""git log -1 --format=%cd --date=format:'%Y.%m.%d.%H.%M.%S'""",
)
.decode("ascii")
.rstrip()
)
print("Setup.py using git log version='{0}'".format(version))
except Exception:
from time import gmtime, strftime
version = strftime("%Y.%m.%d.%H.%M.%S", gmtime())
print("Setup.py using strftime version='{0}'".format(version))
if __name__ == "__main__":
from setuptools import find_packages, setup
setup(
name=NAME,
version=VERSION,
description="A collection of tools to interface wtih Numerical Relativity waveform catalogs",
long_description=get_long_description(),
license="GPL",
url="https://github.com/gwnrtools/nr-catalog-tools",
author="Prayush Kumar",
author_email="prayush.kumar@gmail.com",
packages=find_packages(),
package_dir={NAME: NAME},
package_data={
# version info
NAME: [write_version_file(VERSION)],
"template.data": [],
},
install_requires=get_requirements(),
scripts=[],
)