diff options
author | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2018-04-26 00:00:00 +0000 |
---|---|---|
committer | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2018-04-26 13:00:19 +0200 |
commit | eb4e0fc8f9e278e81a3191f5e30610aaf4aaa762 (patch) | |
tree | a46142828e4a1b892f5b013d65ffa8727c80ee00 /giscanner | |
parent | cf758608312525fb1826027757412f2b62e77f7f (diff) | |
download | gobject-introspection-eb4e0fc8f9e278e81a3191f5e30610aaf4aaa762.tar.gz |
Add --version option to Python based tools.
Version file is generated at build time and stored as _version.py.
To support running uninstalled tools, a fallback version is included as
well. Example output of `--version` option:
```
$ for t in g-ir-{annotation-tool,scanner,doc-tool}; do $t --version; done
g-ir-annotation-tool 1.57.1
g-ir-scanner 1.57.1
g-ir-doc-tool 1.57.1
```
Diffstat (limited to 'giscanner')
-rw-r--r-- | giscanner/__init__.py | 4 | ||||
-rw-r--r-- | giscanner/_version.py.in | 1 | ||||
-rw-r--r-- | giscanner/annotationmain.py | 4 | ||||
-rw-r--r-- | giscanner/docmain.py | 5 | ||||
-rw-r--r-- | giscanner/meson.build | 10 | ||||
-rwxr-xr-x | giscanner/scannermain.py | 4 |
6 files changed, 23 insertions, 5 deletions
diff --git a/giscanner/__init__.py b/giscanner/__init__.py index 139b5187..391d36bd 100644 --- a/giscanner/__init__.py +++ b/giscanner/__init__.py @@ -22,3 +22,7 @@ import os builddir = os.environ.get('UNINSTALLED_INTROSPECTION_BUILDDIR') if builddir is not None: __path__.append(os.path.join(builddir, 'giscanner')) +try: + from ._version import __version__ +except ImportError: + __version__ = '0.0.0' diff --git a/giscanner/_version.py.in b/giscanner/_version.py.in new file mode 100644 index 00000000..4b56f5ba --- /dev/null +++ b/giscanner/_version.py.in @@ -0,0 +1 @@ +__version__ = '@VERSION@' diff --git a/giscanner/annotationmain.py b/giscanner/annotationmain.py index b82ff818..c7be4f7c 100644 --- a/giscanner/annotationmain.py +++ b/giscanner/annotationmain.py @@ -28,6 +28,7 @@ import optparse import codecs from contextlib import contextmanager +import giscanner from giscanner import message from giscanner.annotationparser import GtkDocCommentBlockParser, GtkDocCommentBlockWriter from giscanner.scannermain import (get_preprocessor_option_group, @@ -54,7 +55,8 @@ def encode_stdout(encoding): def annotation_main(args): - parser = optparse.OptionParser('%prog [options] sources') + parser = optparse.OptionParser('%prog [options] sources', + version='%prog ' + giscanner.__version__) group = optparse.OptionGroup(parser, "Tool modes, one is required") group.add_option("-e", "--extract", diff --git a/giscanner/docmain.py b/giscanner/docmain.py index 3bea5421..53f5206c 100644 --- a/giscanner/docmain.py +++ b/giscanner/docmain.py @@ -24,8 +24,10 @@ from __future__ import print_function from __future__ import unicode_literals import os +import sys import argparse +import giscanner from .docwriter import DocWriter from .sectionparser import generate_sections_file, write_sections_file from .transformer import Transformer @@ -33,7 +35,8 @@ from .transformer import Transformer def doc_main(args): parser = argparse.ArgumentParser() - + parser.add_argument('--version', action='version', + version='%(prog)s ' + giscanner.__version__) parser.add_argument("girfile") parser.add_argument("-o", "--output", action="store", dest="output", diff --git a/giscanner/meson.build b/giscanner/meson.build index 006722d2..5a1e44c9 100644 --- a/giscanner/meson.build +++ b/giscanner/meson.build @@ -31,12 +31,18 @@ pkglibdir = join_paths(get_option('libdir'), meson.project_name()) giscannerdir = join_paths(pkglibdir, 'giscanner') giscanner_built_files = [] -blank_conf = configuration_data() +giscanner_conf_data = configuration_data() +giscanner_conf_data.set('VERSION', meson.project_version()) +giscanner_built_files += configure_file(input: '_version.py.in', + output: '_version.py', + install : true, + install_dir : giscannerdir, + configuration: giscanner_conf_data) foreach f : giscanner_files giscanner_built_files += configure_file(input : f, output : f, install : true, install_dir : giscannerdir, - configuration : blank_conf) + configuration : giscanner_conf_data) endforeach install_subdir('doctemplates', install_dir: giscannerdir) diff --git a/giscanner/scannermain.py b/giscanner/scannermain.py index ffcb95cd..c608d04f 100755 --- a/giscanner/scannermain.py +++ b/giscanner/scannermain.py @@ -35,6 +35,7 @@ import sys import tempfile import platform +import giscanner from giscanner import message from giscanner.annotationparser import GtkDocCommentBlockParser from giscanner.ast import Include, Namespace @@ -101,7 +102,8 @@ def get_windows_option_group(parser): def _get_option_parser(): - parser = optparse.OptionParser('%prog [options] sources') + parser = optparse.OptionParser('%prog [options] sources', + version='%prog ' + giscanner.__version__) parser.add_option('', "--quiet", action="store_true", dest="quiet", default=False, |