-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from jalvesz/dev
update main from dev
- Loading branch information
Showing
31 changed files
with
7,418 additions
and
844 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,97 @@ | ||
import os | ||
import subprocess | ||
import fypp | ||
import argparse | ||
from joblib import Parallel, delayed | ||
|
||
def apply_command(with_qp, with_xqp, with_hp): | ||
# Get a list of all files in the folder | ||
# Filter files based on the provided extension | ||
folder = '.\src' | ||
lfiles = os.listdir(folder) | ||
files = [folder+os.sep+file for file in lfiles if file.endswith(".fypp")] | ||
|
||
args = [] | ||
if with_qp: | ||
args.append("-DWITH_QP=True") | ||
if with_xqp: | ||
args.append("-DWITH_XQP=True") | ||
if with_hp: | ||
args.append("-DWITH_HP=True") | ||
C_PREPROCESSED = ( | ||
|
||
) | ||
|
||
def pre_process_toml(kargs): | ||
"""Pre process mannifest | ||
fpm.toml mannifest file can be edited to account for custom keywords | ||
Parameters | ||
---------- | ||
kargs : str | ||
collection of command line arguments. | ||
""" | ||
from tomlkit import table, dumps | ||
data = table() | ||
data.add("name", "fsparse") | ||
data.add("version", str(kargs.vmajor)+ | ||
"."+str(kargs.vminor)+ | ||
"."+str(kargs.vpatch) ) | ||
data.add("license", "MIT") | ||
data.add("author", "José Alves") | ||
data.add("maintainer", "[email protected]") | ||
data.add("copyright", "Copyright 2023, Jose Alves") | ||
|
||
dev_dependencies = table() | ||
dev_dependencies.add("test-drive", {"git" : "https://github.com/fortran-lang/test-drive", | ||
"tag" : "v0.4.0"}) | ||
data.add("dev-dependencies", dev_dependencies) | ||
|
||
preprocess = table() | ||
preprocess.add("cpp", {} ) | ||
preprocess['cpp'].add("suffixes", [".f90"] ) | ||
# preprocess['cpp'].add("macros", [] ) | ||
data.add("preprocess", preprocess) | ||
|
||
with open("fpm.toml", "w") as f: | ||
f.write(dumps(data)) | ||
|
||
def pre_process_fypp(kargs): | ||
"""Pre process fypp files | ||
Parameters | ||
---------- | ||
kargs : str | ||
collection of command line arguments. | ||
""" | ||
kwd = [] | ||
if kargs.with_qp: | ||
kwd.append("-DWITH_QP=True") | ||
if kargs.with_xqp: | ||
kwd.append("-DWITH_XDP=True") | ||
|
||
optparser = fypp.get_option_parser() | ||
options, leftover = optparser.parse_args(args=args) | ||
options, leftover = optparser.parse_args(args=kwd) | ||
options.includes = ['include'] #folder with include files for fypp | ||
# options.line_numbering = True | ||
tool = fypp.Fypp(options) | ||
# Apply the command line to each file | ||
for file in files: | ||
|
||
# Define the folders to search for *.fypp files | ||
folders = ['src', 'test'] | ||
# Process all folders | ||
fypp_files = [os.path.join(root, file) for folder in folders | ||
for root, _, files in os.walk(folder) | ||
for file in files if file.endswith(".fypp")] | ||
|
||
def process_f(file): | ||
source_file = file | ||
target_file = file.removesuffix('fypp')+'f90' | ||
basename = os.path.splitext(source_file)[0] | ||
sfx = 'f90' # if os.path.basename(basename) not in C_PREPROCESSED else 'F90' | ||
target_file = basename + '.' + sfx | ||
tool.process_file(source_file, target_file) | ||
|
||
Parallel(n_jobs=kargs.njob)(delayed(process_f)(f) for f in fypp_files) | ||
|
||
return | ||
|
||
if __name__ == "__main__": | ||
parser = argparse.ArgumentParser(description='Preprocess FSPARSE source files.') | ||
# fypp arguments | ||
parser.add_argument("--vmajor", type=int, default=0, help="Project Version Major") | ||
parser.add_argument("--vminor", type=int, default=1, help="Project Version Minor") | ||
parser.add_argument("--vpatch", type=int, default=1, help="Project Version Patch") | ||
|
||
parser.add_argument("--njob", type=int, default=4, help="number of parallel jobs") | ||
parser.add_argument("--with_qp", action="store_true", help="Include WITH_QP in the command") | ||
parser.add_argument("--with_xqp", action="store_true", help="Include WITH_XQP in the command") | ||
parser.add_argument("--with_hp", action="store_true", help="Include WITH_HP in the command") | ||
|
||
args = parser.parse_args() | ||
apply_command(args.with_qp, args.with_xqp, args.with_hp) | ||
|
||
pre_process_toml(args) | ||
pre_process_fypp(args) |
Oops, something went wrong.