-
Notifications
You must be signed in to change notification settings - Fork 5
/
hatch_build.py
36 lines (27 loc) · 1.14 KB
/
hatch_build.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
import tempfile
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
from hatchling.metadata.plugin.interface import MetadataHookInterface
version = {"__file__": "re6st/version.py"}
with open(version["__file__"]) as f:
code = compile(f.read(), version["__file__"], 'exec')
exec(code, version)
class CustomMetadataHook(MetadataHookInterface):
def update(self, metadata):
metadata['version'] = egg_version = "0.%(revision)s" % version
metadata['readme'] = {
'content-type': 'text/x-rst',
'text': ".. contents::\n\n" + open('README.rst').read()
+ "\n" + open('CHANGES.rst').read() + """
Git Revision: %s == %s
""" % (egg_version, version["short"]),
}
class CustomBuildHook(BuildHookInterface):
def initialize(self, _, build_data):
f = self.__version = tempfile.NamedTemporaryFile('w')
for x in sorted(version.items()):
if not x[0].startswith("_"):
f.write("%s = %r\n" % x)
f.flush()
build_data["force_include"][f.name] = version["__file__"]
def finalize(self, *_):
self.__version.close()