Skip to content

Commit 233222f

Browse files
committed
Rename config module to setup. Split ssp_setup.py into separate modules.
`ssp_setup.py` split to: - `logging.py`: logging setup - `exit.py`: exit function - `outdir.py`: functions to handle output directory
1 parent 5b5a0fa commit 233222f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+216
-179
lines changed

sourcespec2/config/__init__.py renamed to sourcespec2/setup/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@
1111
"""
1212
from .config import config # noqa
1313
from .configure_cli import configure_cli # noqa
14-
from .library_versions import library_versions # noqa
14+
from .logging import setup_logging # noqa
15+
from .exit import ssp_exit # noqa
16+
from .outdir import ( # noqa
17+
get_outdir_path, save_config, move_outdir, remove_old_outdir
18+
)
File renamed without changes.

sourcespec2/config/configure_cli.py renamed to sourcespec2/setup/configure_cli.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@
2626
from .configobj.validate import Validator
2727
from ..ssp_update_db import update_db_file
2828

29+
# define ipshell(), if possible
30+
# note: ANSI colors do not work on Windows standard terminal
31+
if sys.stdout.isatty() and sys.platform != 'win32':
32+
try:
33+
from IPython.terminal.embed import InteractiveShellEmbed
34+
from traitlets.config import MultipleInstanceError
35+
IPSHELL = InteractiveShellEmbed.instance()
36+
except (ImportError, MultipleInstanceError):
37+
IPSHELL = None
38+
else:
39+
IPSHELL = None
40+
2941

3042
def _write_sample_config(configspec, progname):
3143
"""

sourcespec2/setup/exit.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# -*- coding: utf-8 -*-
2+
# SPDX-License-Identifier: CECILL-2.1
3+
"""
4+
An exit function for SourceSpec.
5+
6+
:copyright:
7+
2012 Claudio Satriano <satriano@ipgp.fr>
8+
9+
2013-2014 Claudio Satriano <satriano@ipgp.fr>,
10+
Emanuela Matrullo <matrullo@geologie.ens.fr>,
11+
Agnes Chounet <chounet@ipgp.fr>
12+
13+
2015-2024 Claudio Satriano <satriano@ipgp.fr>
14+
:license:
15+
CeCILL Free Software License Agreement v2.1
16+
(http://www.cecill.info/licences.en.html)
17+
"""
18+
import sys
19+
import logging
20+
import signal
21+
logger = logging.getLogger(__name__.rsplit('.', maxsplit=1)[-1])
22+
23+
24+
def ssp_exit(retval=0, abort=False):
25+
"""Exit the program."""
26+
# ssp_exit might have already been called if multiprocessing
27+
if ssp_exit.SSP_EXIT_CALLED:
28+
return
29+
ssp_exit.SSP_EXIT_CALLED = True
30+
if abort:
31+
print('\nAborting.')
32+
if logger is not None:
33+
logger.debug('source_spec ABORTED')
34+
elif logger is not None:
35+
logger.debug('source_spec END')
36+
logging.shutdown()
37+
sys.exit(retval)
38+
39+
40+
ssp_exit.SSP_EXIT_CALLED = False
41+
42+
43+
def _sigint_handler(sig, frame):
44+
"""Handle SIGINT signal."""
45+
# pylint: disable=unused-argument
46+
ssp_exit(1, abort=True)
47+
48+
49+
signal.signal(signal.SIGINT, _sigint_handler)

0 commit comments

Comments
 (0)