1212import os
1313import sys
1414import configparser
15+ import enum
1516
16- from src import api
17+ from enum import Enum
18+ from typing import Dict , Callable
19+ from src .api import errmsg
1720
1821# The options container
19- from . import options
20- from . import global_
2122
22- from .options import ANYTYPE , Action
23+ from src .api import options
24+ from src .api import global_
25+
26+ from src .api .options import ANYTYPE , Action
2327
2428
2529# ------------------------------------------------------
2630# Common setup and configuration for all tools
2731# ------------------------------------------------------
28- class ConfigSections :
32+ @enum .unique
33+ class ConfigSections (str , Enum ):
2934 ZXBC = 'zxbc'
3035 ZXBASM = 'zxbasm'
3136 ZXBPP = 'zxbpp'
3237
3338
34- class OPTION :
39+ @enum .unique
40+ class OPTION (str , Enum ):
3541 OUTPUT_FILENAME = 'output_filename'
3642 INPUT_FILENAME = 'input_filename'
3743 STDERR_FILENAME = 'stderr_filename'
@@ -96,23 +102,23 @@ def load_config_from_file(filename: str, section: str, options_: options.Options
96102 cfg = configparser .ConfigParser ()
97103 cfg .read (filename , encoding = 'utf-8' )
98104 except (configparser .DuplicateSectionError , configparser .DuplicateOptionError ):
99- api . errmsg .msg_output (f"Invalid config file '{ filename } ': it has duplicated fields" )
105+ errmsg .msg_output (f"Invalid config file '{ filename } ': it has duplicated fields" )
100106 if stop_on_error :
101107 sys .exit (1 )
102108 return False
103109 except FileNotFoundError :
104- api . errmsg .msg_output (f"Config file '{ filename } ' not found" )
110+ errmsg .msg_output (f"Config file '{ filename } ' not found" )
105111 if stop_on_error :
106112 sys .exit (1 )
107113 return False
108114
109115 if section not in cfg .sections ():
110- api . errmsg .msg_output (f"Section '{ section } ' not found in config file '{ filename } '" )
116+ errmsg .msg_output (f"Section '{ section } ' not found in config file '{ filename } '" )
111117 if stop_on_error :
112118 sys .exit (1 )
113119 return False
114120
115- parsing = {
121+ parsing : Dict [ type , Callable ] = {
116122 int : cfg .getint ,
117123 float : cfg .getfloat ,
118124 bool : cfg .getboolean
@@ -137,7 +143,7 @@ def save_config_into_file(filename: str, section: str, options_: options.Options
137143 try :
138144 cfg .read (filename , encoding = 'utf-8' )
139145 except (configparser .DuplicateSectionError , configparser .DuplicateOptionError ):
140- api . errmsg .msg_output (f"Invalid config file '{ filename } ': it has duplicated fields" )
146+ errmsg .msg_output (f"Invalid config file '{ filename } ': it has duplicated fields" )
141147 if stop_on_error :
142148 sys .exit (1 )
143149 return False
@@ -157,7 +163,7 @@ def save_config_into_file(filename: str, section: str, options_: options.Options
157163 with open (filename , 'wt' , encoding = 'utf-8' ) as f :
158164 cfg .write (f )
159165 except IOError :
160- api . errmsg .msg_output (f"Can't write config file '{ filename } '" )
166+ errmsg .msg_output (f"Can't write config file '{ filename } '" )
161167 if stop_on_error :
162168 sys .exit (1 )
163169 return False
@@ -189,10 +195,10 @@ def init():
189195 OPTIONS (Action .ADD , name = OPTION .MEMORY_MAP , type = str , default = None , ignore_none = True )
190196 OPTIONS (Action .ADD , name = OPTION .FORCE_ASM_BRACKET , type = bool , default = False , ignore_none = True )
191197
192- OPTIONS (Action .ADD , name = OPTION .USE_BASIC_LOADER , type = bool , default = False ) # Whether to use a loader
198+ OPTIONS (Action .ADD , name = OPTION .USE_BASIC_LOADER , type = bool , default = False , ignore_none = True )
193199
194200 # Whether to add autostart code (needs basic loader = true)
195- OPTIONS (Action .ADD , name = OPTION .AUTORUN , type = bool , default = False )
201+ OPTIONS (Action .ADD , name = OPTION .AUTORUN , type = bool , default = False , ignore_none = True )
196202 OPTIONS (Action .ADD , name = OPTION .OUTPUT_FILE_TYPE , type = str , default = 'bin' ) # bin, tap, tzx etc...
197203 OPTIONS (Action .ADD , name = OPTION .INCLUDE_PATH , type = str , default = '' ) # Include path, like '/var/lib:/var/include'
198204
0 commit comments