Implemented python gojsonnet get_version

This commit is contained in:
Alexander Petrov 2019-11-15 08:45:04 +00:00 committed by Stanisław Barzowski
parent 741eec05fe
commit d8f0505fc9
2 changed files with 15 additions and 3 deletions

View File

@ -23,8 +23,17 @@ LIB_DIR = DIR + '/c-bindings'
MODULE_SOURCES = ['cpp-jsonnet/python/_jsonnet.c']
def get_version():
# TODO think about it (how to get the version)
return '0.14.0'
"""
Parses the version out of libjsonnet.h
"""
with open(os.path.join(DIR, 'vm.go')) as f:
for line in f:
if 'const' in line and 'version' in line:
v_code = line.partition('=')[2].strip('\n "')
if v_code[0] == 'v':
return v_code[1:]
return None
class BuildJsonnetExt(BuildExt):
def run(self):

5
vm.go
View File

@ -124,6 +124,9 @@ const (
evalKindStream = iota
)
// version is the current gojsonnet's version
const version = "v0.14.0"
// Evaluate evaluates a Jsonnet program given by an Abstract Syntax Tree
// and returns serialized JSON as string.
// TODO(sbarzowski) perhaps is should return JSON in standard Go representation
@ -253,5 +256,5 @@ func SnippetToAST(filename string, snippet string) (ast.Node, error) {
// Version returns the Jsonnet version number.
func Version() string {
return "v0.14.0"
return version
}