Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manuskript does not start with PyEnchant on MacOS #188

Closed
katafrakt opened this issue Nov 4, 2017 · 10 comments · Fixed by #202
Closed

Manuskript does not start with PyEnchant on MacOS #188

katafrakt opened this issue Nov 4, 2017 · 10 comments · Fixed by #202
Labels
Milestone

Comments

@katafrakt
Copy link
Contributor

This happens with PyEnchant enabled on MacOS.

Debug: Web rendering engine used: QWebEngineView
Running manuskript version 0.5.0.
Note: No translator found or loaded for locale en_US.
Traceback (most recent call last):
  File "bin/manuskript", line 13, in <module>
    main.run()
  File "/Users/pawel/dev/github/manuskript/bin/../manuskript/main.py", line 64, in run
    launch()
  File "/Users/pawel/dev/github/manuskript/bin/../manuskript/main.py", line 70, in launch
    main = MainWindow()
  File "/Users/pawel/dev/github/manuskript/bin/../manuskript/mainWindow.py", line 54, in __init__
    self.setupUi(self)
  File "/Users/pawel/dev/github/manuskript/bin/../manuskript/ui/mainWindow.py", line 169, in setupUi
    self.txtSummarySentence = textEditView(self.tabSummaryPage1)
  File "/Users/pawel/dev/github/manuskript/bin/../manuskript/ui/views/textEditView.py", line 79, in __init__
    self._dict = enchant.Dict(self.currentDict if self.currentDict else enchant.get_default_language())
  File "/Users/pawel/.pyenv/versions/3.5.3/Python.framework/Versions/3.5/lib/python3.5/site-packages/enchant/__init__.py", line 555, in __init__
    raise Error(err)
enchant.errors.Error: No tag specified and default language could not be determined.

Brief investigation indicates that this is because PyEnchant cannot detect default language. In fact, when running a simple script:

import enchant;
print(enchant.list_dicts())
default = enchant.get_default_language()
print(default)
enchant.Dict(default)

The result is:

[('de_DE', <Enchant: Myspell Provider>), ('en_AU', <Enchant: Myspell Provider>), ('en_GB', <Enchant: Myspell Provider>), ('en_US', <Enchant: Myspell Provider>), ('fr_FR', <Enchant: Myspell Provider>)]
None
Traceback (most recent call last):
  File "package/dependency_test.py", line 14, in <module>
    enchant.Dict(default)
  File "/Users/pawel/.pyenv/versions/3.5.3/Python.framework/Versions/3.5/lib/python3.5/site-packages/enchant/__init__.py", line 555, in __init__
    raise Error(err)
enchant.errors.Error: No tag specified and default language could not be determined.
@katafrakt katafrakt changed the title No tag specified and default language could not be determined Manuskript does not start with PyEnchant on MacOS Nov 4, 2017
@gedakc
Copy link
Collaborator

gedakc commented Nov 4, 2017

Thanks @katafrakt for providing extra details with this report, especially the sample code and output.

This problem looks like something we should at least be able to work around. It is also similar to issue #130 which caused a crash when the locale environment variables LANG and LANGUAGE were not set in Linux.

Is there a way in OS X to access the language setting directly instead of using enchant.get_default_language()?

@gedakc gedakc added the bug label Nov 4, 2017
@olivierkes
Copy link
Owner

Is this in the package you made, or even running from source?

The simplest fix would be to use the first of enchant.list_dicts() if enchant.get_default_language() is None. But if we can use the system's local to determine the default dict it would be best.

Can you run that simple script and see if that works?

from PyQt5.QtCore import QLocale
print(QLocale.system().name())  # Should return something like: en_US

@olivierkes olivierkes added this to the 0.6.0 milestone Nov 4, 2017
@katafrakt
Copy link
Contributor Author

katafrakt commented Nov 4, 2017

It's in both: the package with PyEnchant included and from source. I also tried running after setting LANG or LANGUAGE env variables to en_US, but it did not change anything. Apparently it's working differently in MacOS (again, I underline that I'm not expert in MacOS, I just have to use it for work, normally I prefer Linux).

Your script returns "en_US", as you expected:

Python 3.5.3 (default, Oct 12 2017, 22:59:41)
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from PyQt5.QtCore import QLocale
>>> print(QLocale.system().name())
en_US

So I took liberty to edit textEditView.py and change lines 78-79 to:

try:
   defaultLanguage = enchant.get_default_language() if enchant.get_default_language() else QLocale.system().name()
   self._dict = enchant.Dict(self.currentDict if self.currentDict else defaultLanguage)

After that, Manuskript starts normally.

@olivierkes
Copy link
Owner

Great, do you want to make a pull request? Or do you want me to make the change?

But before that, I'm just thinking: what would happen if QLocale.system().name() is not listed in enchant.list_dicts()? Could you try to run manuskript with your modified code, but after setting LANG or LANGUAGE env variables to something that is not in enchant.list_dicts()? I guess it would call the enchant.errors.DictNotFoundError that will be caught next line, and then spellcheck would be disabled.

If that's the case, it's a bug, and it might be better to select randomly a dict in enchant.list_dicts(), that the user can then change.

@katafrakt
Copy link
Contributor Author

katafrakt commented Nov 6, 2017

@olivierkes LANGUAGE env variable is ignored, however if I set LANG to something outside enchant.list_dicts(), the application crashes with following stacktrace:

Debug: Web rendering engine used: QWebEngineView
Running manuskript version 0.5.0.
Note: No translator found or loaded for locale fi_FI.
Traceback (most recent call last):
  File "bin/manuskript", line 13, in <module>
    main.run()
  File "/Users/pawel/dev/github/manuskript/bin/../manuskript/main.py", line 64, in run
    launch()
  File "/Users/pawel/dev/github/manuskript/bin/../manuskript/main.py", line 68, in launch
    from .mainWindow import MainWindow
  File "/Users/pawel/dev/github/manuskript/bin/../manuskript/mainWindow.py", line 15, in <module>
    from manuskript import loadSave
  File "/Users/pawel/dev/github/manuskript/bin/../manuskript/loadSave.py", line 10, in <module>
    import manuskript.load_save.version_1 as v1
  File "/Users/pawel/dev/github/manuskript/bin/../manuskript/load_save/version_1.py", line 26, in <module>
    from manuskript.models.outlineModel import outlineItem
  File "/Users/pawel/dev/github/manuskript/bin/../manuskript/models/outlineModel.py", line 20, in <module>
    locale.setlocale(locale.LC_ALL, '')
  File "/Users/pawel/.pyenv/versions/3.5.3/Python.framework/Versions/3.5/lib/python3.5/locale.py", line 594, in setlocale
    return _setlocale(category, locale)
locale.Error: unsupported locale setting

So probably it should be secured against it too. I can try to work on a pull request later today or tomorrow.

EDIT: After re-reading the trace, I think it's a different problem than just spellcheck.

@olivierkes
Copy link
Owner

olivierkes commented Nov 6, 2017

@katafrakt It's a different problem indeed, and this one is fixed (at least ignored) with commit 0a0649a.
Thanks for reporting !

So now how does pyEnchant behave?

@gedakc
Copy link
Collaborator

gedakc commented Nov 8, 2017

FYI: I think that issue 130 - Crashing when creating a new project is similar to this issue as it has to do with a missing locale.

@olivierkes
Copy link
Owner

It is similar, but the error message is different:

  • here, locale.Error: unsupported locale setting, when importing locale and calling locale.setlocale(locale.LC_ALL, '').
  • In the other case, UnicodeDecodeError: 'locale' codec can't decode byte 0xe2 in position 0: Invalid or incomplete multibyte or wide character, when using locale.

Maybe #130 does behave differently with previous commit ?

@gedakc
Copy link
Collaborator

gedakc commented Nov 8, 2017

The error message is indeed different. Fortunately there is an easy workaround to #130 -- set LANG to a valid locale.

@katafrakt
Copy link
Contributor Author

@olivierkes Now it behaves like you predicted:

I guess it would call the enchant.errors.DictNotFoundError that will be caught next line, and then spellcheck would be disabled.

So I think I know more or less everything to create a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants