Debian Codegraph @

cylc/flow/__init__.py

raw
1 # THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE.
2 # Copyright (C) NIWA & British Crown (Met Office) & Contributors.
3 #
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17 """Set up the cylc environment."""
18
19 import logging
20 import os
21
22 CYLC_LOG = 'cylc'
23
24 LOG = logging.getLogger(CYLC_LOG)
25 # Start with a null handler
26 LOG.addHandler(logging.NullHandler())
27
28 LOG_LEVELS = {
29 "DEBUG": logging.DEBUG,
30 "INFO": logging.INFO,
31 "NORMAL": logging.INFO,
32 "WARNING": logging.WARNING,
33 "ERROR": logging.ERROR,
34 "CRITICAL": logging.CRITICAL,
35 }
36
37
38 class LoggerAdaptor(logging.LoggerAdapter):
39 """Adds a prefix to log messages."""
40 def process(self, msg, kwargs):
41 ret = f"[{self.extra['prefix']}] {msg}" if self.extra else msg
42 return ret, kwargs
43
44
45 def environ_init():
46 """Initialise cylc environment."""
47 # Python output buffering delays appearance of stdout and stderr
48 # when output is not directed to a terminal (this occurred when
49 # running pre-5.0 cylc via the posix nohup command; is it still the
50 # case in post-5.0 daemon-mode cylc?)
51 os.environ['PYTHONUNBUFFERED'] = 'true'
52
53
54 environ_init()
55
56 __version__ = '8.6.6'
57
58
59 def iter_entry_points(entry_point_name):
60 """Iterate over Cylc entry points."""
61 from importlib.metadata import entry_points
62 yield from (
63 entry_point
64 # for entry_point in entry_points()[entry_point_name]
65 for entry_point in entry_points().select(group=entry_point_name)
66 )