Skip to content

Commit fd1dba5

Browse files
committed
Show version of language-check itself too
1 parent 8aec2bf commit fd1dba5

3 files changed

Lines changed: 22 additions & 6 deletions

File tree

‎language_check/__init__.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
from .which import which
4242

4343

44+
__version__ = '0.6.1'
45+
46+
4447
__all__ = ['LanguageTool', 'Error', 'get_languages', 'correct', 'get_version',
4548
'get_directory', 'set_directory']
4649

‎language_check/main.py‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import re
77
import sys
88

9+
from . import __version__
910
from . import get_build_date
1011
from . import get_version
1112
from . import LanguageTool
@@ -32,11 +33,13 @@ def parse_args():
3233
help='list of rule IDs to be enabled')
3334
parser.add_argument('--api', action='store_true',
3435
help='print results as XML')
35-
parser.add_argument('--version', action='version',
36-
version='LanguageTool {} ({})'
37-
.format(get_version(),
38-
get_build_date()),
39-
help='show LanguageTool version and build date')
36+
parser.add_argument(
37+
'--version', action='version',
38+
version='%(prog)s {} (LanguageTool {} ({}))'.format(
39+
__version__,
40+
get_version(),
41+
get_build_date()),
42+
help='show version')
4043
parser.add_argument('-a', '--apply', action='store_true',
4144
help='automatically apply suggestions if available')
4245
parser.add_argument('-s', '--spell-check-off', dest='spell_check',

‎setup.py‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# -*- coding: utf-8 -*-
33
"""Backward-compatible setup script."""
44

5+
import ast
56
import codecs
67
import glob
78
import os
@@ -131,6 +132,14 @@ def __len__(self):
131132
python_full_version = sys.version.split()[0]
132133

133134

135+
def get_version():
136+
"""Return version string."""
137+
with open('language_check/__init__.py') as input_file:
138+
for line in input_file:
139+
if line.startswith('__version__'):
140+
return ast.parse(line).body[0].value.s
141+
142+
134143
def which(program, win_allow_cross_arch=True):
135144
"""Identify the location of an executable file."""
136145
def is_exe(path):
@@ -301,7 +310,6 @@ def cfg_to_args(config):
301310
opts_to_args = {
302311
'metadata': [
303312
('name', 'name'),
304-
('version', 'version'),
305313
('author', 'author'),
306314
('author-email', 'author_email'),
307315
('maintainer', 'maintainer'),
@@ -352,6 +360,8 @@ def cfg_to_args(config):
352360
if 'data_files' in kwargs:
353361
kwargs['data_files'] = get_data_files(kwargs['data_files'])
354362

363+
kwargs['version'] = get_version()
364+
355365
return kwargs
356366

357367

0 commit comments

Comments
 (0)