11#!/usr/bin/env python3
22# -*- mode: python; py-indent-offset: 4; py-continuation-offset: 4 -*-
3-
4- import os
3+ from pathlib import Path
54from pprint import pprint
6-
75import setprogramoptions
86
9-
10-
11- def find_config_ini (filename = "config.ini" , rootpath = "." ):
12- """
13- Recursively searches for a particular file among the subdirectory structure.
14- If we find it, then we return the full relative path to `pwd` to that file.
15-
16- The _first_ match will be returned.
17-
18- Args:
19- filename (str): The _filename_ of the file we're searching for. Default: 'config.ini'
20- rootpath (str): The _root_ path where we will begin our search from. Default: '.'
21-
22- Returns:
23- String containing the path to the file if it was found. If a matching filename is not
24- found then `None` is returned.
25-
26- """
27- output = None
28- for dirpath , dirnames , filename_list in os .walk (rootpath ):
29- if filename in filename_list :
30- output = os .path .join (dirpath , filename )
31- break
32- if output is None :
33- raise FileNotFoundError ("Unable to find {} in {}" .format (filename , os .getcwd ())) # pragma: no cover
34- return output
35-
36-
7+ def print_separator (label ):
8+ print ("" )
9+ print (f"{ label } " )
10+ print ("-" * len (label ))
11+ return
3712
3813def test_setprogramoptions (filename = "config.ini" ):
39- print ("filename : {}" .format (filename ))
40- print ("" )
14+ print (f"filename: { filename } " )
15+
16+ section_name = "TEST_VAR_EXPANSION_UPDATE_01"
17+ print (f"section_name = { section_name } " )
4118
4219 parser = setprogramoptions .SetProgramOptionsCMake (filename = filename )
4320 parser .debug_level = 0
4421 parser .exception_control_level = 4
4522 parser .exception_control_compact_warnings = True
4623
47- section_name = "TEST_VAR_EXPANSION_UPDATE_01"
48-
49- parse_section ( parser , section_name )
24+ data = parser . configparserenhanceddata [ section_name ]
25+ print_separator ( f"parser.configparserenhanceddata[ { section_name } ]" )
26+ pprint ( data , width = 120 )
5027
51- print ("" )
52- print ("parser.options" )
53- print ("--------------" )
28+ print_separator ("Show parser.options" )
5429 pprint (parser .options , width = 200 , sort_dicts = False )
5530
31+ print_separator ("Bash Output" )
32+ print ("Note: The _second_ assignment to `CMAKE_CXX_FLAGS` is skipped by a BASH generator" )
33+ print (" without a `FORCE` option since by definition all CMake `-D` options on a " )
34+ print (" BASH command line are both CACHE and FORCE. Within a CMake source fragment" )
35+ print (" changing an existing CACHE var requires a FORCE option to be set so we should" )
36+ print (" skip the second assignment to maintain consistency between the bash and cmake" )
37+ print (" fragment generators with respect to the CMakeCache.txt file that would be" )
38+ print (" generated." )
39+ print (" The `WARNING` message below is terse since it's in compact form -- disable" )
40+ print (" the `exception_control_compact_warnings` flag to get the full warning message." )
5641 print ("" )
57- print ("Bash Output" )
58- print ("-----------" )
5942 option_list = parser .gen_option_list (section_name , generator = "bash" )
43+ print ("" )
6044 print (" \\ \n " .join (option_list ))
6145
62- print ("" )
63- print ("CMake Fragment" )
64- print ("--------------" )
46+ print_separator ("CMake Fragment" )
6547 option_list = parser .gen_option_list (section_name , generator = "cmake_fragment" )
6648 if len (option_list ) > 0 :
6749 print ("\n " .join (option_list ))
@@ -72,42 +54,17 @@ def test_setprogramoptions(filename="config.ini"):
7254 return 0
7355
7456
75-
76- def parse_section (parser , section ):
77-
78- data = parser .configparserenhanceddata [section ]
79-
80- print ("\n Data" )
81- print ("----" )
82- pprint (data , width = 120 )
83-
84- # Print the loginfo from the last search (change if to True to enable)
85- if (False ):
86- print ("\n LogInfo" )
87- print ("-------" )
88- #parser._loginfo_print(pretty=True)
89-
90- # Filter out just the entry and exits for handlers
91- handler_list = [
92- (d ['type' ], d ['name' ]) for d in parser ._loginfo if d ['type' ] in ['handler-entry' , 'handler-exit' ]
93- ]
94- pprint (handler_list , width = 120 )
95-
96- return data
97-
98-
99-
10057def main ():
10158 """
10259 main app
10360 """
104- fname_ini = "example-03.ini"
105- fpath_ini = find_config_ini (filename = fname_ini )
106- test_setprogramoptions (filename = fpath_ini )
61+ print (80 * "-" )
62+ print (f"- { Path (__file__ ).name } " )
63+ print (80 * "-" )
64+ test_setprogramoptions (filename = "example-03.ini" )
10765 return 0
10866
10967
110-
11168if __name__ == "__main__" :
11269 main ()
11370 print ("Done." )
0 commit comments