export_single Namespace Reference

Functions

def get_git_root ()
 
def process_files (fname, strip_comments=True)
 
def export_single (modulename, strip_comments=True, outname=None)
 

Variables

 parser = argparse.ArgumentParser(description="Export single file algorithms.")
 
 type
 
 str
 
 required
 
 True
 
 help
 
 False
 
 dest
 
 action
 
 strip_comments
 
 args = parser.parse_args()
 

Function Documentation

◆ export_single()

def export_single.export_single (   modulename,
  strip_comments = True,
  outname = None 
)

Definition at line 38 of file export_single.py.

38 def export_single(modulename, strip_comments=True, outname=None):
39  if outname is None:
40  outname = f"{modulename}_single.f90"
41 
42  prj_srcs = get_git_root() / "src"
43  os.chdir(prj_srcs) # Needed for fortdepend
44 
45  gaussjacobiquad = fortdepend.FortranProject()
46  concat_files = gaussjacobiquad.get_all_used_files(modulename)
47  print(f"Concatenating in reverse order {concat_files}")
48 
49  exp_dat = []
50 
51  for fname in reversed(concat_files):
52  processed_content = process_files(prj_srcs / fname, strip_comments)
53  exp_dat.append(processed_content)
54 
55  with Path(get_git_root() / "dist" / outname).open("w") as f_out:
56  f_out.write("".join(exp_dat))
57 
58 
def get_git_root()
def export_single(modulename, strip_comments=True, outname=None)
def process_files(fname, strip_comments=True)

◆ get_git_root()

def export_single.get_git_root ( )

Definition at line 14 of file export_single.py.

14 def get_git_root():
15  try:
16  git_root = (
17  subprocess.check_output(["git", "rev-parse", "--show-toplevel"])
18  .strip()
19  .decode("utf-8")
20  )
21  return Path(git_root)
22  except subprocess.CalledProcessError:
23  print("This directory is not part of a Git repository.")
24  return None
25 
26 

◆ process_files()

def export_single.process_files (   fname,
  strip_comments = True 
)

Definition at line 27 of file export_single.py.

27 def process_files(fname, strip_comments=True):
28  with open(fname, "r") as f:
29  content = f.read()
30  # Remove everything between ! BEGIN_HEADER and ! END_HEADER
31  content = re.sub(r"! BEGIN_HEADER.*?! END_HEADER\n", "", content, flags=re.DOTALL)
32  # Optionally, remove lines starting with !
33  if strip_comments:
34  content = re.sub(r"(!.*?$)|(\s*!.*?$)", "", content, flags=re.MULTILINE)
35  return content
36 
37 

Variable Documentation

◆ action

export_single.action

Definition at line 70 of file export_single.py.

◆ args

export_single.args = parser.parse_args()

Definition at line 81 of file export_single.py.

◆ dest

export_single.dest

Definition at line 69 of file export_single.py.

◆ False

export_single.False

Definition at line 65 of file export_single.py.

◆ help

export_single.help

Definition at line 62 of file export_single.py.

◆ parser

export_single.parser = argparse.ArgumentParser(description="Export single file algorithms.")

Definition at line 60 of file export_single.py.

◆ required

export_single.required

Definition at line 62 of file export_single.py.

◆ str

export_single.str

Definition at line 62 of file export_single.py.

◆ strip_comments

export_single.strip_comments

Definition at line 79 of file export_single.py.

◆ True

export_single.True

Definition at line 62 of file export_single.py.

◆ type

export_single.type

Definition at line 62 of file export_single.py.