Skip to content

Commit

Permalink
Merge pull request #20 from unnonouno/version
Browse files Browse the repository at this point in the history
Add version option
  • Loading branch information
unnonouno committed Oct 12, 2014
2 parents 56df501 + 680887b commit 3ec0203
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions mrep/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = '0.1.1'
13 changes: 12 additions & 1 deletion scripts/mrep
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ if __name__ == '__main__':
parser = argparse.ArgumentParser(
description='MREP: morpheme regular expression printer')
parser.add_argument('pattern', metavar='PATTERN',
help='pattern')
nargs='?', help='pattern')
parser.add_argument('file', metavar='FILE',
nargs='*', help='data file')
parser.add_argument('-o', '--only-matching', action='store_true',
Expand All @@ -57,8 +57,19 @@ if __name__ == '__main__':
parser.add_argument('--mecab-arg', type=str, default='',
help='argument to pass to mecab '
'(ex: "-r /path/to/resource/file")')
parser.add_argument('--version', action='store_true',
help='show version number')
args = parser.parse_args()

if args.version:
sys.stdout.write('mrep %s\n' % mrep.__version__)
sys.exit(0)

if args.pattern is None:
parser.print_usage()
sys.stdout.write('mrep: error: PATTERN is required\n')
sys.exit(2)

try:
matcher = mrep.builder.parse(args.pattern)
except mrep.builder.ParseError as e:
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os
from setuptools import setup
from mrep import __version__

requires = [
'mecab-python3',
Expand All @@ -12,7 +13,7 @@ def read(name):

setup(
name='mrep',
version='0.1.1',
version=__version__,
description='MREP: morpheme regular expression printer',
long_description=read('README.rst'),
author='Yuya Unno',
Expand Down
11 changes: 11 additions & 0 deletions test/mrep_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import unittest
import subprocess
from mrep import __version__

ESCAPE = '\033[%sm'
RED = ESCAPE % '31'
Expand Down Expand Up @@ -57,3 +58,13 @@ def test_invalid_pattern(self):
self.call('"<"', 'test/data/1.txt')

self.assertEqual(3, cm.exception.returncode)

def test_no_pattern(self):
with self.assertRaises(subprocess.CalledProcessError) as cm:
self.call()

self.assertEqual(2, cm.exception.returncode)

def test_version(self):
out = self.call('--version')
self.assertTrue(__version__ in str(out))

0 comments on commit 3ec0203

Please sign in to comment.