1
1
import os
2
- import shutil
3
2
import fypp
4
3
import argparse
5
4
from joblib import Parallel , delayed
6
5
7
- def copy_folder_with_filter (source_folder , destination_folder , filter_list = None , filter_suffix = None ):
8
- # Create destination folder if it doesn't exist
9
- if not os .path .exists (destination_folder ):
10
- os .makedirs (destination_folder )
11
-
12
- # Iterate over the files and folders in the source folder
13
- for item in os .listdir (source_folder ):
14
- source_item = os .path .join (source_folder , item )
15
- destination_item = os .path .join (destination_folder , item )
16
-
17
- # If it's a folder, recursively copy it
18
- if os .path .isdir (source_item ):
19
- copy_folder_with_filter (source_item , destination_item , filter_list , filter_suffix )
20
- else :
21
- # If filter_list is provided, check if the filename is in the list to avoid it
22
- should_copy = False if filter_list and item in filter_list else True
23
- should_copy = False if filter_suffix and item .endswith (filter_suffix ) else should_copy
24
- if should_copy :
25
- shutil .copy2 (source_item , destination_item )
26
-
27
6
def pre_process_toml (args ):
28
7
"""
29
8
Pre-process the fpm.toml
@@ -93,7 +72,7 @@ def pre_process_fypp(args):
93
72
kwd .append ("-DPROJECT_VERSION_PATCH=" + str (args .vpatch ))
94
73
if args .with_qp :
95
74
kwd .append ("-DWITH_QP=True" )
96
- if args .with_xqp :
75
+ if args .with_xdp :
97
76
kwd .append ("-DWITH_XDP=True" )
98
77
99
78
optparser = fypp .get_option_parser ()
@@ -103,25 +82,13 @@ def pre_process_fypp(args):
103
82
tool = fypp .Fypp (options )
104
83
105
84
# Check destination folder for preprocessing. if not 'stdlib-fpm', it is assumed to be the root folder.
106
- in_place = False if args .destdir == 'stdlib-fpm' else True
107
- src = 'src' if in_place else 'stdlib-fpm' + os .sep + 'src'
108
- test = 'test' if in_place else 'stdlib-fpm' + os .sep + 'test'
109
- example = 'example' if in_place else 'stdlib-fpm' + os .sep + 'example'
110
- if not in_place :
111
- copy_folder_with_filter ('src' , src ,
112
- filter_list = ['CMakeLists.txt' ,"f18estop.f90" ])
113
- copy_folder_with_filter ('test' , test ,
114
- filter_list = ['CMakeLists.txt' ,"test_always_fail.f90" ,
115
- "test_always_skip.f90" ,"test_hash_functions.f90" ],
116
- filter_suffix = 'manual' )
117
- copy_folder_with_filter ('example' ,example ,
118
- filter_list = ['CMakeLists.txt' ])
119
- shutil .copy2 ('ci' + os .sep + 'fpm.toml' , 'stdlib-fpm' + os .sep + 'fpm.toml' )
120
- shutil .copy2 ('VERSION' , 'stdlib-fpm' + os .sep + 'VERSION' )
121
- shutil .copy2 ('LICENSE' , 'stdlib-fpm' + os .sep + 'LICENSE' )
85
+ if not os .path .exists ('src' + os .sep + 'temp' ):
86
+ os .makedirs ('src' + os .sep + 'temp' )
87
+ if not os .path .exists ('test' + os .sep + 'temp' ):
88
+ os .makedirs ('test' + os .sep + 'temp' )
122
89
123
90
# Define the folders to search for *.fypp files
124
- folders = [src , test ]
91
+ folders = [' src' , ' test' ]
125
92
# Process all folders
126
93
fypp_files = [os .path .join (root , file ) for folder in folders
127
94
for root , _ , files in os .walk (folder )
@@ -130,13 +97,12 @@ def pre_process_fypp(args):
130
97
def process_f (file ):
131
98
source_file = file
132
99
root = os .path .dirname (file )
100
+ if not os .path .exists (root + os .sep + 'temp' ):
101
+ os .makedirs (root + os .sep + 'temp' )
133
102
basename = os .path .splitext (os .path .basename (source_file ))[0 ]
134
103
sfx = 'f90' if basename not in C_PREPROCESSED else 'F90'
135
- target_file = root + os .sep + basename + '.' + sfx
104
+ target_file = root + os . sep + 'temp' + os .sep + basename + '.' + sfx
136
105
tool .process_file (source_file , target_file )
137
- # if folder different from root
138
- if not in_place :
139
- os .remove (source_file )
140
106
141
107
Parallel (n_jobs = args .njob )(delayed (process_f )(f ) for f in fypp_files )
142
108
@@ -179,7 +145,7 @@ def fpm_build(args,unknown):
179
145
parser .add_argument ("--njob" , type = int , default = 4 , help = "Number of parallel jobs for preprocessing" )
180
146
parser .add_argument ("--maxrank" ,type = int , default = 7 , help = "Set the maximum allowed rank for arrays" )
181
147
parser .add_argument ("--with_qp" ,type = bool , default = False , help = "Include WITH_QP in the command" )
182
- parser .add_argument ("--with_xqp " ,type = bool , default = False , help = "Include WITH_XDP in the command" )
148
+ parser .add_argument ("--with_xdp " ,type = bool , default = False , help = "Include WITH_XDP in the command" )
183
149
184
150
parser .add_argument ('--destdir' , action = 'store' , type = str , default = 'stdlib-fpm' , help = 'destination directory for the fypp preprocessing.' )
185
151
# external libraries arguments
@@ -189,15 +155,15 @@ def fpm_build(args,unknown):
189
155
args , unknown = parser .parse_known_args ()
190
156
#==========================================
191
157
# read current manifest
158
+ with open ('VERSION' , 'r' ) as file :
159
+ version = file .read ().split ("." )
160
+ vmajor , vminor , vpatch = [int (value ) for value in version ]
192
161
import tomlkit
193
- with open ('ci' + os . sep + ' fpm.toml' , 'r' ) as file :
162
+ with open ('fpm.toml' , 'r' ) as file :
194
163
manifest = tomlkit .parse (file .read ())
195
- version = manifest ['version' ].split ("." )
196
- if version != ['VERSION' ]:
197
- vmajor , vminor , vpatch = [int (value ) for value in version ]
198
164
#==========================================
199
165
# pre process the fpm manifest
200
- #pre_process_toml(args)
166
+ # pre_process_toml(args)
201
167
#==========================================
202
168
# pre process the meta programming fypp files
203
169
pre_process_fypp (args )
0 commit comments