From d8f0505fc9cd66a039ecf3b62415779f779a0faa Mon Sep 17 00:00:00 2001 From: Alexander Petrov Date: Fri, 15 Nov 2019 08:45:04 +0000 Subject: [PATCH] Implemented python gojsonnet get_version --- setup.py | 13 +++++++++++-- vm.go | 5 ++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index d43e0af..46bf28d 100644 --- a/setup.py +++ b/setup.py @@ -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): diff --git a/vm.go b/vm.go index 975fabd..1395d6c 100644 --- a/vm.go +++ b/vm.go @@ -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 }