Mercurial > libervia-desktop-kivy
comparison libervia/desktop_kivy/core/kivy_hack.py @ 495:59bdf78bd1d9
installation: update to use hatch following change in backend and other frontends:
- `setup.py` and `requirements.txt` have been removed in favor of `pyproject.toml`
- changed versionning mechanism to use a version directly in
`libervia/desktop_kivy/__init__.py` handled by Hatch
- remove the log hack from `kivy_hack` as there is now an environment variable to disable
the logging hijacking
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 28 Aug 2023 18:29:18 +0200 |
parents | b3cedbee561d |
children |
comparison
equal
deleted
inserted
replaced
494:a4a5565e7026 | 495:59bdf78bd1d9 |
---|---|
1 #!/usr//bin/env python2 | 1 #!/usr//bin/env python3 |
2 | |
3 | 2 |
4 #Libervia Desktop-Kivy | 3 #Libervia Desktop-Kivy |
5 # Copyright (C) 2016-2021 Jérôme Poisson (goffi@goffi.org) | 4 # Copyright (C) 2016-2021 Jérôme Poisson (goffi@goffi.org) |
6 | 5 |
7 # This program is free software: you can redistribute it and/or modify | 6 # This program is free software: you can redistribute it and/or modify |
15 # GNU Affero General Public License for more details. | 14 # GNU Affero General Public License for more details. |
16 | 15 |
17 # You should have received a copy of the GNU Affero General Public License | 16 # You should have received a copy of the GNU Affero General Public License |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 17 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | 18 |
20 CONF_KIVY_LEVEL = 'log_kivy_level' | 19 from .constants import Const as C |
20 from libervia.backend.core import log_config | |
21 import os | |
22 import sys | |
21 | 23 |
22 | 24 |
23 def do_hack(): | 25 def do_hack(): |
24 """work around Kivy hijacking of logs and arguments""" | 26 """work around Kivy hijacking of logs and arguments""" |
25 # we remove args so kivy doesn't use them | 27 # we remove args so kivy doesn't use them |
26 # this is need to avoid kivy breaking QuickApp args handling | 28 # this is need to avoid kivy breaking QuickApp args handling |
27 import sys | |
28 ori_argv = sys.argv[:] | 29 ori_argv = sys.argv[:] |
29 sys.argv = sys.argv[:1] | 30 sys.argv = sys.argv[:1] |
30 from .constants import Const as C | |
31 from libervia.backend.core import log_config | |
32 log_config.libervia_configure(C.LOG_BACKEND_STANDARD, C) | 31 log_config.libervia_configure(C.LOG_BACKEND_STANDARD, C) |
33 | 32 |
34 from . import config | 33 os.environ["KIVY_LOG_MODE"] = "PYTHON" |
35 kivy_level = config.config_get(C.CONFIG_SECTION, CONF_KIVY_LEVEL, 'follow').upper() | |
36 | 34 |
37 # kivy handles its own loggers, we don't want that! | |
38 import logging | |
39 root_logger = logging.root | |
40 kivy_logger = logging.getLogger('kivy') | |
41 ori_addHandler = kivy_logger.addHandler | |
42 kivy_logger.addHandler = lambda __: None | |
43 ori_setLevel = kivy_logger.setLevel | |
44 if kivy_level == 'FOLLOW': | |
45 # level is following SàT level | |
46 kivy_logger.setLevel = lambda level: None | |
47 elif kivy_level == 'KIVY': | |
48 # level will be set by Kivy according to its own conf | |
49 pass | |
50 elif kivy_level in C.LOG_LEVELS: | |
51 kivy_logger.setLevel(kivy_level) | |
52 kivy_logger.setLevel = lambda level: None | |
53 else: | |
54 raise ValueError("Unknown value for {name}: {value}".format(name=CONF_KIVY_LEVEL, value=kivy_level)) | |
55 | |
56 # during import kivy set its logging stuff | |
57 import kivy | 35 import kivy |
58 kivy # to avoid pyflakes warning | 36 assert kivy # to avoid pyflakes warning |
59 | |
60 # we want to separate kivy logs from other logs | |
61 logging.root = root_logger | |
62 from kivy import logger | |
63 sys.stderr = logger.previous_stderr | |
64 | |
65 # we restore original methods | |
66 kivy_logger.addHandler = ori_addHandler | |
67 kivy_logger.setLevel = ori_setLevel | |
68 | 37 |
69 # we restore original arguments | 38 # we restore original arguments |
70 sys.argv = ori_argv | 39 sys.argv = ori_argv |