Mercurial > repos > shellac > guppy_basecaller
comparison env/lib/python3.7/site-packages/gxformat2/linting.py @ 0:26e78fe6e8c4 draft
"planemo upload commit c699937486c35866861690329de38ec1a5d9f783"
author | shellac |
---|---|
date | Sat, 02 May 2020 07:14:21 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:26e78fe6e8c4 |
---|---|
1 """Generic utilities for linting. | |
2 | |
3 Largely derived in large part from galaxy.tool_util.lint. | |
4 """ | |
5 LEVEL_ALL = "all" | |
6 LEVEL_WARN = "warn" | |
7 LEVEL_ERROR = "error" | |
8 DEFAULT_TRAINING_LINT = None | |
9 | |
10 | |
11 class LintContext(object): | |
12 """Track running status (state) of linting.""" | |
13 | |
14 def __init__(self, level=LEVEL_WARN, training_topic=DEFAULT_TRAINING_LINT): | |
15 """Create LintContext with specified 'level' (currently unused).""" | |
16 self.level = level | |
17 self.training_topic = training_topic | |
18 self.found_errors = False | |
19 self.found_warns = False | |
20 | |
21 # self.valid_messages = [] | |
22 # self.info_messages = [] | |
23 self.warn_messages = [] | |
24 self.error_messages = [] | |
25 | |
26 def __handle_message(self, message_list, message, *args, **kwds): | |
27 if kwds or args: | |
28 message = message.format(*args, **kwds) | |
29 message_list.append(message) | |
30 | |
31 # def valid(self, message, *args, **kwds): | |
32 # self.__handle_message(self.valid_messages, message, *args, **kwds) | |
33 | |
34 # def info(self, message, *args, **kwds): | |
35 # self.__handle_message(self.info_messages, message, *args, **kwds) | |
36 | |
37 def error(self, message, *args, **kwds): | |
38 """Track a linting error - a serious problem with the artifact preventing execution.""" | |
39 self.__handle_message(self.error_messages, message, *args, **kwds) | |
40 | |
41 def warn(self, message, *args, **kwds): | |
42 """Track a linting warning - a deviation from best practices.""" | |
43 self.__handle_message(self.warn_messages, message, *args, **kwds) | |
44 | |
45 def print_messages(self): | |
46 """Print error messages and update state at the end of linting.""" | |
47 for message in self.error_messages: | |
48 self.found_errors = True | |
49 print(".. ERROR: %s" % message) | |
50 | |
51 if self.level != LEVEL_ERROR: | |
52 for message in self.warn_messages: | |
53 self.found_warns = True | |
54 print(".. WARNING: %s" % message) | |
55 | |
56 if self.level == LEVEL_ALL: | |
57 for message in self.info_messages: | |
58 print(".. INFO: %s" % message) | |
59 for message in self.valid_messages: | |
60 print(".. CHECK: %s" % message) |