File tree Expand file tree Collapse file tree 2 files changed +22
-40
lines changed
Expand file tree Collapse file tree 2 files changed +22
-40
lines changed Original file line number Diff line number Diff line change 99to issue warnings normally and raise StagpyError.
1010"""
1111
12- from __future__ import annotations
13-
14- import os
15- import signal
16- import sys
17- import typing
18-
19- if typing .TYPE_CHECKING :
20- from typing import Any , NoReturn
21-
22-
23- DEBUG = os .getenv ("STAGPY_DEBUG" ) is not None
24-
25-
26- def sigint_handler (* _ : Any ) -> NoReturn :
27- """Handler of SIGINT signal.
28-
29- It is set when you use StagPy as a command line tool to handle gracefully
30- keyboard interruption.
31- """
32- print ("\n So long, and thanks for all the fish." )
33- sys .exit ()
34-
35-
36- if DEBUG :
37- print (
38- "StagPy runs in DEBUG mode because the environment variable" ,
39- 'STAGPY_DEBUG is set to "True"' ,
40- sep = "\n " ,
41- end = "\n \n " ,
42- )
43- else :
44- _PREV_INT = signal .signal (signal .SIGINT , sigint_handler )
45-
4612try :
4713 from ._version import version as __version__
4814except ImportError :
4915 __version__ = "unknown"
50-
51- if not DEBUG :
52- signal .signal (signal .SIGINT , _PREV_INT )
Original file line number Diff line number Diff line change 11"""The stagpy module is callable."""
22
3+ from __future__ import annotations
4+
5+ import os
36import signal
47import sys
58import warnings
9+ from typing import Any , NoReturn
10+
11+
12+ def sigint_handler (* _ : Any ) -> NoReturn :
13+ """Handler of SIGINT signal.
614
7- from . import DEBUG , sigint_handler
15+ It is set when you use StagPy as a command line tool to handle gracefully
16+ keyboard interruption.
17+ """
18+ print ("\n So long, and thanks for all the fish." )
19+ sys .exit ()
820
921
1022def main () -> None :
1123 """Implement StagPy entry point."""
12- if not DEBUG :
24+ debug = os .getenv ("STAGPY_DEBUG" ) is not None
25+ if debug :
26+ print (
27+ "env variable 'STAGPY_DEBUG' is set: StagPy runs in DEBUG mode" ,
28+ end = "\n \n " ,
29+ )
30+ else :
1331 signal .signal (signal .SIGINT , sigint_handler )
1432 warnings .simplefilter ("ignore" )
33+
1534 from . import args , config , error
1635
1736 conf = config .Config .default_ ()
@@ -21,7 +40,7 @@ def main() -> None:
2140 try :
2241 args .parse_args (conf )(conf )
2342 except error .StagpyError as err :
24- if DEBUG :
43+ if debug :
2544 raise
2645 errtype = type (err ).__name__
2746 print (
You can’t perform that action at this time.
0 commit comments