forked from hegelai/prompttools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
118 lines (94 loc) · 3.5 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
#!/usr/bin/env python
import distutils.command.clean
import os
import shutil
import subprocess
from pathlib import Path
from setuptools import find_packages, setup
ROOT_DIR = Path(__file__).parent.resolve()
def _get_requirements():
"""Get dependency requirements from `requirements.txt`."""
req_list = []
with Path("requirements.txt").open("r") as f:
for line in f:
req = line.strip()
if len(req) == 0 or req.startswith("#"):
continue
req_list.append(req)
return req_list
def _get_version():
"""Get package version."""
with open(os.path.join(ROOT_DIR, "version.txt")) as f:
version = f.readline().strip()
sha = "Unknown"
try:
sha = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=str(ROOT_DIR)).decode("ascii").strip()
except Exception:
pass
os_build_version = os.getenv("BUILD_VERSION")
if os_build_version:
version = os_build_version
elif sha != "Unknown":
version += "+" + sha[:7]
return version, sha
def _export_version(version, sha):
version_path = ROOT_DIR / "prompttools" / "version.py"
with open(version_path, "w") as f:
f.write(f"__version__ = '{version}'\n")
f.write(f"git_version = {repr(sha)}\n")
requirements = _get_requirements()
class Clean(distutils.command.clean.clean):
def run(self):
# Run default behavior first
distutils.command.clean.clean.run(self)
# Remove prompttools extension
def remove_extension(pattern):
for path in (ROOT_DIR / "prompttools").glob(pattern):
print(f"removing extension '{path}'")
path.unlink()
for ext in ["so", "dylib", "pyd"]:
remove_extension("**/*." + ext)
# Remove build directory
build_dirs = [
ROOT_DIR / "build", # Remove build
ROOT_DIR / "prompttools.egg-info", # Remove egg metadata
]
for path in build_dirs:
if path.exists():
print(f"removing '{path}' (and everything under it)")
shutil.rmtree(str(path), ignore_errors=True)
if __name__ == "__main__":
VERSION, SHA = _get_version()
# TODO: Exporting the version here breaks `python -m build`
_export_version(VERSION, SHA)
print("-- Building version " + VERSION)
setup(
# Metadata
name="prompttools",
version=VERSION,
description="Tools for prompts.",
long_description=Path("README.md").read_text(encoding="utf-8"),
long_description_content_type="text/markdown",
url="https://github.com/hegelai/prompttools",
author="Hegel AI",
author_email="steve@hegel-ai.com, kevin@hegel-ai.com",
license="Proprietary",
install_requires=requirements,
python_requires=">=3.10",
classifiers=[
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"Operating System :: MacOS :: MacOS X",
"Operating System :: Microsoft :: Windows",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: Implementation :: CPython",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
],
# Package Info
packages=find_packages(exclude=["test*", "examples*", "build*"]),
zip_safe=False,
cmdclass={
"clean": Clean,
},
)