
import glob

dependencies = {}

for src in glob.iglob('*.F90'):
    module = src.strip('.F90')
    d = set()
    for line in open(src, 'r'):
        words = line.split()
        if words and words[0].lower() == 'use':
            name = words[1].strip(',')
            if name in ['mpi','hdf5','h5lt']:
                continue
            if name.startswith('xml_data_'):
                name = name.replace('xml_data_', 'templates/')
            d.add(name)
    if d:
        d = list(d)
        d.sort()
        dependencies[module] = d


keys = dependencies.keys()
keys.sort()
for module in keys:
    for dep in dependencies[module]:
        print("{0}.o: {1}.o".format(module, dep))
    print('')


import glob
import re

dependencies = {}

for src in glob.iglob('*.F90'):
    module = src.strip('.F90')
    deps = set()
    d = re.findall(r'\n\s*use\s+(\w+)',
                   open(src,'r').read())
    for name in d:
        if name in ['mpi','hdf5','h5lt']:
            continue
        if name.startswith('xml_data_'):
            name = name.replace('xml_data_', 'templates/')
        deps.add(name)
    if deps:
        dependencies[module] = sorted(list(deps))


keys = dependencies.keys()
keys.sort()
for module in keys:
    for dep in dependencies[module]:
        print("{0}.o: {1}.o".format(module, dep))
    print('')

Fix potential bug in build dependencies script. If you gave it ' use module,only: ...' before it would not work.
Fix potential bug in build dependencies script. If you gave it ' use module,only: ...' before it would not work.

  
  import glob
+ import re
  
  dependencies = {}
  
  for src in glob.iglob('*.F90'):
      module = src.strip('.F90')
-     d = set()
+     deps = set()
+     d = re.findall(r'\n\s*use\s+(\w+)',
+                    open(src,'r').read())
+     for name in d:
-     for line in open(src, 'r'):
-         words = line.split()
-         if words and words[0].lower() == 'use':
-             name = words[1].strip(',')
-             if name in ['mpi','hdf5','h5lt']:
+         if name in ['mpi','hdf5','h5lt']:
-                 continue
+             continue
-             if name.startswith('xml_data_'):
+         if name.startswith('xml_data_'):
-                 name = name.replace('xml_data_', 'templates/')
+             name = name.replace('xml_data_', 'templates/')
-             d.add(name)
+         deps.add(name)
-     if d:
+     if deps:
-         d = list(d)
-         d.sort()
-         dependencies[module] = d
+         dependencies[module] = sorted(list(deps))
  
  
  keys = dependencies.keys()
  keys.sort()
  for module in keys:
      for dep in dependencies[module]:
          print("{0}.o: {1}.o".format(module, dep))
      print('')
  
Fix potential bug in build dependencies script. If you gave it ' use module,only: ...' before it would not work.
## Code Before:

import glob

dependencies = {}

for src in glob.iglob('*.F90'):
    module = src.strip('.F90')
    d = set()
    for line in open(src, 'r'):
        words = line.split()
        if words and words[0].lower() == 'use':
            name = words[1].strip(',')
            if name in ['mpi','hdf5','h5lt']:
                continue
            if name.startswith('xml_data_'):
                name = name.replace('xml_data_', 'templates/')
            d.add(name)
    if d:
        d = list(d)
        d.sort()
        dependencies[module] = d


keys = dependencies.keys()
keys.sort()
for module in keys:
    for dep in dependencies[module]:
        print("{0}.o: {1}.o".format(module, dep))
    print('')

## Instruction:
Fix potential bug in build dependencies script. If you gave it ' use module,only: ...' before it would not work.
## Code After:

import glob
import re

dependencies = {}

for src in glob.iglob('*.F90'):
    module = src.strip('.F90')
    deps = set()
    d = re.findall(r'\n\s*use\s+(\w+)',
                   open(src,'r').read())
    for name in d:
        if name in ['mpi','hdf5','h5lt']:
            continue
        if name.startswith('xml_data_'):
            name = name.replace('xml_data_', 'templates/')
        deps.add(name)
    if deps:
        dependencies[module] = sorted(list(deps))


keys = dependencies.keys()
keys.sort()
for module in keys:
    for dep in dependencies[module]:
        print("{0}.o: {1}.o".format(module, dep))
    print('')
