-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
109 lines (93 loc) · 3.64 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
#!/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
from os import environ, path
import subprocess
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:
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
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'""",
shell=use_shell).decode('ascii').rstrip()
print("Setup.py using git log version='{0}'".format(version))
except:
from time import strftime, gmtime
version = strftime("%Y.%m.%d.%H.%M.%S", gmtime())
print("Setup.py using strftime version='{0}'".format(version))
if __name__ == "__main__":
from setuptools import setup, find_packages
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='[email protected]',
packages=find_packages(),
package_dir={NAME: NAME},
package_data={
# version info
NAME: [write_version_file(VERSION)],
'template.data': []
},
install_requires=[],
scripts=[],
)