@@ -77,6 +77,17 @@ def filter_keys(
7777 return output
7878
7979
80+ def hasherr (k : str , v : str , sec : str ) -> None :
81+ raise YoExc (
82+ f"There is a '#' character in the config entry within section \\ [{ sec } ]:\n "
83+ f" { k } = { v } \n "
84+ "Ini-style configs do not allow comments except on their own line, you\n "
85+ "cannot include a comment after a config value. If this was intended,\n "
86+ "you can bypass this error by setting 'allow_hash_in_config_value = true'\n "
87+ "in the \\ [yo] section."
88+ )
89+
90+
8091@dataclasses .dataclass
8192class YoRegion :
8293 name : str
@@ -95,6 +106,12 @@ def from_config_section(
95106 )
96107 return YoRegion (** d )
97108
109+ def check_hasherr (self ) -> None :
110+ for k in ("vcn_id" , "subnet_id" , "subnet_compartment_id" ):
111+ v = getattr (self , k )
112+ if isinstance (v , str ) and "#" in v :
113+ hasherr (k , v , "regions." + self .name )
114+
98115
99116@dataclasses .dataclass
100117class YoConfig :
@@ -121,6 +138,7 @@ class YoConfig:
121138 check_for_update_every : t .Optional [int ] = 6
122139 creator_tags : t .List [str ] = dataclasses .field (default_factory = list )
123140 list_columns : str = "Name,Shape,Mem,CPU,State,Created"
141+ allow_hash_in_config_value : bool = False
124142
125143 @property
126144 def vcn_id (self ) -> str :
@@ -186,6 +204,7 @@ def from_config_section(
186204 cls , conf : configparser .SectionProxy , regions : t .Dict [str , YoRegion ]
187205 ) -> "YoConfig" :
188206 d = dict (** conf )
207+
189208 d ["regions" ] = regions
190209 region_conf = filter_keys (
191210 d , ("vcn_id" , "subnet_id" , "subnet_compartment_id" )
@@ -204,10 +223,21 @@ def from_config_section(
204223 "silence_automatic_tag_warning" ,
205224 "exact_name" ,
206225 "resource_filtering" ,
226+ "allow_hash_in_config_value" ,
207227 ]
208228 for b in bools :
209229 if b in d :
210230 d [b ] = conf .getboolean (b )
231+
232+ allow_hash = d .get ("allow_hash_in_config_value" , False )
233+ if not allow_hash :
234+ for k , v in d .items ():
235+ if isinstance (v , str ) and "#" in v :
236+ hasherr (k , v , "yo" )
237+ # Region configs are loaded before [yo], so check them once
238+ # we know whether we should be raising an error.
239+ for v in regions .values ():
240+ v .check_hasherr ()
211241 if "check_for_update_every" in d :
212242 d ["check_for_update_every" ] = int (d ["check_for_update_every" ])
213243 # OCI stores email addresses as lower case. While most people write
0 commit comments