Skip to content
This repository was archived by the owner on Mar 9, 2023. It is now read-only.

Commit 93a42ec

Browse files
author
Sorami Hisamoto
authored
Improve error messages related to dictionary setup (#122)
1 parent 1a6649b commit 93a42ec

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

sudachipy/command_line.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,9 @@ def _command_link(args, print_usage):
134134
try:
135135
return set_default_dict_package(dict_package, output=output)
136136
except ImportError:
137-
print_usage()
138-
print('{} not installed'.format(dict_package), file=sys.stderr)
137+
print('Package `{0}` does not exist.\n'
138+
'You may install it with a command `$ pip install {0}`'
139+
.format(dict_package), file=sys.stderr)
139140
exit(1)
140141

141142

sudachipy/config.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,29 @@
2424
DEFAULT_SETTINGFILE = DEFAULT_SETTINGFILE.as_posix()
2525

2626

27-
def unlink_default_dict_package(output):
27+
def unlink_default_dict_package(output, verbose=True):
2828
try:
2929
dst_path = Path(import_module('sudachidict').__file__).parent
3030
except ImportError:
31-
print('sudachidict not exists', file=output)
31+
if verbose:
32+
print('Package `sudachidict` does not exist.', file=output)
3233
return
3334

3435
if dst_path.is_symlink():
35-
print('unlinking sudachidict', file=output)
3636
dst_path.unlink()
37-
print('sudachidict unlinked', file=output)
37+
if verbose:
38+
print('Removed the package symbolic link `sudachidict`.', file=output)
3839
if dst_path.exists():
39-
raise IOError('unlink failed (directory exists)')
40+
raise IOError('Unlink failed (The `sudachidict` directory exists and it is not a symbolic link).')
4041

4142

4243
def set_default_dict_package(dict_package, output):
43-
unlink_default_dict_package(output)
44+
unlink_default_dict_package(output, verbose=False)
4445

4546
src_path = Path(import_module(dict_package).__file__).parent
4647
dst_path = src_path.parent / 'sudachidict'
4748
dst_path.symlink_to(src_path)
48-
print('default dict package = {}'.format(dict_package), file=output)
49+
print('Set the default dictionary to `{}`.'.format(dict_package), file=output)
4950

5051
return dst_path
5152

@@ -57,15 +58,15 @@ def create_default_link_for_sudachidict_core(output):
5758
try:
5859
import_module('sudachidict_core')
5960
except ImportError:
60-
raise KeyError('`systemDict` must be specified if `SudachiDict_core` not installed')
61+
raise KeyError('You need to specify `systemDict` in the config when `sudachidict_core` is not installed.')
6162
try:
6263
import_module('sudachidict_full')
63-
raise KeyError('Multiple packages of `SudachiDict_*` installed. Set default dict with link command.')
64+
raise KeyError('Multiple dictionaries installed. Set the default with `link -t` command.')
6465
except ImportError:
6566
pass
6667
try:
6768
import_module('sudachidict_small')
68-
raise KeyError('Multiple packages of `SudachiDict_*` installed. Set default dict with link command.')
69+
raise KeyError('Multiple dictionaries installed. Set the default with `link -t` command.')
6970
except ImportError:
7071
pass
7172
dict_path = set_default_dict_package('sudachidict_core', output=output)

0 commit comments

Comments
 (0)