-
Notifications
You must be signed in to change notification settings - Fork 657
/
__metadata__.py
72 lines (56 loc) · 2.21 KB
/
__metadata__.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
"""
indy-node package metadata
"""
import os
import json
from typing import Any
import collections.abc
from indy_common.node_version import NodeVersion, InvalidVersionError
VERSION_FILENAME = '__version__.json'
VERSION_FILE = os.path.join(
os.path.abspath(os.path.dirname(__file__)), VERSION_FILENAME)
MANIFEST_FILENAME = '__manifest__.json'
MANIFEST_FILE = os.path.join(
os.path.abspath(os.path.dirname(__file__)), MANIFEST_FILENAME)
# TODO use/wrap plenum's set and load API
def load_version(version_file: str = VERSION_FILE) -> NodeVersion:
with open(version_file, 'r') as _f:
version = json.load(_f)
if not isinstance(version, collections.abc.Iterable):
raise InvalidVersionError(
"Failed to load from {}: data '{}' is not iterable"
.format(version_file, version)
)
return NodeVersion('.'.join([str(i) for i in version if str(i)]))
def set_version(version: str, version_file: str = VERSION_FILE):
version = NodeVersion(version)
with open(version_file, 'w') as _f:
json.dump(['' if i is None else i for i in version.parts], _f)
_f.write('\n')
def load_manifest(manifest_file: str = MANIFEST_FILE) -> Any:
try:
with open(manifest_file, 'r') as _f:
return json.load(_f)
except IOError:
return None
def set_manifest(manifest: Any, manifest_file: str = MANIFEST_FILE):
with open(manifest_file, 'w') as _f:
json.dump(manifest, _f, sort_keys=True)
_f.write('\n')
__title__ = 'indy-node'
__version_info__ = load_version()
__version__ = __version_info__.full
__manifest__ = load_manifest()
__description__ = 'Indy node'
__long_description__ = __description__
__keywords__ = 'Indy Node'
__url__ = 'https://github.com/hyperledger/indy-node'
__author__ = "Hyperledger"
__author_email__ = '[email protected]'
__maintainer__ = "Hyperledger"
__license__ = "Apache 2.0"
__all__ = [
'__title__', '__version_info__', '__version__', '__manifest__',
'__description__', '__long_description__', '__keywords__',
'__url__', '__author__', '__author_email__', '__maintainer__',
'__license__', 'load_version', 'set_version', 'load_manifest', 'set_manifest']