id
int32
0
252k
repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
51
19.8k
code_tokens
sequence
docstring
stringlengths
3
17.3k
docstring_tokens
sequence
sha
stringlengths
40
40
url
stringlengths
87
242
251,800
nchopin/particles
book/mle/malikpitt_interpolation.py
interpoled_resampling
def interpoled_resampling(W, x): """Resampling based on an interpolated CDF, as described in Malik and Pitt. Parameters ---------- W: (N,) array weights x: (N,) array particles Returns ------- xrs: (N,) array the resampled particles """ N = W.shape[0] idx = np.argsort(x) xs = x[idx] ws = W[idx] cs = np.cumsum(avg_n_nplusone(ws)) u = random.rand(N) xrs = np.empty(N) where = np.searchsorted(cs, u) # costs O(N log(N)) but algorithm has O(N log(N)) complexity anyway for n in range(N): m = where[n] if m==0: xrs[n] = xs[0] elif m==N: xrs[n] = xs[-1] else: xrs[n] = interpol(cs[m-1], cs[m], xs[m-1], xs[m], u[n]) return xrs
python
def interpoled_resampling(W, x): N = W.shape[0] idx = np.argsort(x) xs = x[idx] ws = W[idx] cs = np.cumsum(avg_n_nplusone(ws)) u = random.rand(N) xrs = np.empty(N) where = np.searchsorted(cs, u) # costs O(N log(N)) but algorithm has O(N log(N)) complexity anyway for n in range(N): m = where[n] if m==0: xrs[n] = xs[0] elif m==N: xrs[n] = xs[-1] else: xrs[n] = interpol(cs[m-1], cs[m], xs[m-1], xs[m], u[n]) return xrs
[ "def", "interpoled_resampling", "(", "W", ",", "x", ")", ":", "N", "=", "W", ".", "shape", "[", "0", "]", "idx", "=", "np", ".", "argsort", "(", "x", ")", "xs", "=", "x", "[", "idx", "]", "ws", "=", "W", "[", "idx", "]", "cs", "=", "np", ".", "cumsum", "(", "avg_n_nplusone", "(", "ws", ")", ")", "u", "=", "random", ".", "rand", "(", "N", ")", "xrs", "=", "np", ".", "empty", "(", "N", ")", "where", "=", "np", ".", "searchsorted", "(", "cs", ",", "u", ")", "# costs O(N log(N)) but algorithm has O(N log(N)) complexity anyway", "for", "n", "in", "range", "(", "N", ")", ":", "m", "=", "where", "[", "n", "]", "if", "m", "==", "0", ":", "xrs", "[", "n", "]", "=", "xs", "[", "0", "]", "elif", "m", "==", "N", ":", "xrs", "[", "n", "]", "=", "xs", "[", "-", "1", "]", "else", ":", "xrs", "[", "n", "]", "=", "interpol", "(", "cs", "[", "m", "-", "1", "]", ",", "cs", "[", "m", "]", ",", "xs", "[", "m", "-", "1", "]", ",", "xs", "[", "m", "]", ",", "u", "[", "n", "]", ")", "return", "xrs" ]
Resampling based on an interpolated CDF, as described in Malik and Pitt. Parameters ---------- W: (N,) array weights x: (N,) array particles Returns ------- xrs: (N,) array the resampled particles
[ "Resampling", "based", "on", "an", "interpolated", "CDF", "as", "described", "in", "Malik", "and", "Pitt", "." ]
3faa97a1073db45c5889eef3e015dd76ef350b52
https://github.com/nchopin/particles/blob/3faa97a1073db45c5889eef3e015dd76ef350b52/book/mle/malikpitt_interpolation.py#L26-L59
251,801
Fortran-FOSS-Programmers/ford
ford/sourceform.py
sort_items
def sort_items(self,items,args=False): """ Sort the `self`'s contents, as contained in the list `items` as specified in `self`'s meta-data. """ if self.settings['sort'].lower() == 'src': return def alpha(i): return i.name def permission(i): if args: if i.intent == 'in': return 'b' if i.intent == 'inout': return 'c' if i.intent == 'out': return 'd' if i.intent == '': return 'e' perm = getattr(i, 'permission', '') if perm == 'public': return 'b' if perm == 'protected': return 'c' if perm == 'private': return 'd' return 'a' def permission_alpha(i): return permission(i) + '-' + i.name def itype(i): if i.obj == 'variable': retstr = i.vartype if retstr == 'class': retstr = 'type' if i.kind: retstr = retstr + '-' + str(i.kind) if i.strlen: retstr = retstr + '-' + str(i.strlen) if i.proto: retstr = retstr + '-' + i.proto[0] return retstr elif i.obj == 'proc': if i.proctype != 'Function': return i.proctype.lower() else: return i.proctype.lower() + '-' + itype(i.retvar) else: return i.obj def itype_alpha(i): return itype(i) + '-' + i.name if self.settings['sort'].lower() == 'alpha': items.sort(key=alpha) elif self.settings['sort'].lower() == 'permission': items.sort(key=permission) elif self.settings['sort'].lower() == 'permission-alpha': items.sort(key=permission_alpha) elif self.settings['sort'].lower() == 'type': items.sort(key=itype) elif self.settings['sort'].lower() == 'type-alpha': items.sort(key=itype_alpha)
python
def sort_items(self,items,args=False): if self.settings['sort'].lower() == 'src': return def alpha(i): return i.name def permission(i): if args: if i.intent == 'in': return 'b' if i.intent == 'inout': return 'c' if i.intent == 'out': return 'd' if i.intent == '': return 'e' perm = getattr(i, 'permission', '') if perm == 'public': return 'b' if perm == 'protected': return 'c' if perm == 'private': return 'd' return 'a' def permission_alpha(i): return permission(i) + '-' + i.name def itype(i): if i.obj == 'variable': retstr = i.vartype if retstr == 'class': retstr = 'type' if i.kind: retstr = retstr + '-' + str(i.kind) if i.strlen: retstr = retstr + '-' + str(i.strlen) if i.proto: retstr = retstr + '-' + i.proto[0] return retstr elif i.obj == 'proc': if i.proctype != 'Function': return i.proctype.lower() else: return i.proctype.lower() + '-' + itype(i.retvar) else: return i.obj def itype_alpha(i): return itype(i) + '-' + i.name if self.settings['sort'].lower() == 'alpha': items.sort(key=alpha) elif self.settings['sort'].lower() == 'permission': items.sort(key=permission) elif self.settings['sort'].lower() == 'permission-alpha': items.sort(key=permission_alpha) elif self.settings['sort'].lower() == 'type': items.sort(key=itype) elif self.settings['sort'].lower() == 'type-alpha': items.sort(key=itype_alpha)
[ "def", "sort_items", "(", "self", ",", "items", ",", "args", "=", "False", ")", ":", "if", "self", ".", "settings", "[", "'sort'", "]", ".", "lower", "(", ")", "==", "'src'", ":", "return", "def", "alpha", "(", "i", ")", ":", "return", "i", ".", "name", "def", "permission", "(", "i", ")", ":", "if", "args", ":", "if", "i", ".", "intent", "==", "'in'", ":", "return", "'b'", "if", "i", ".", "intent", "==", "'inout'", ":", "return", "'c'", "if", "i", ".", "intent", "==", "'out'", ":", "return", "'d'", "if", "i", ".", "intent", "==", "''", ":", "return", "'e'", "perm", "=", "getattr", "(", "i", ",", "'permission'", ",", "''", ")", "if", "perm", "==", "'public'", ":", "return", "'b'", "if", "perm", "==", "'protected'", ":", "return", "'c'", "if", "perm", "==", "'private'", ":", "return", "'d'", "return", "'a'", "def", "permission_alpha", "(", "i", ")", ":", "return", "permission", "(", "i", ")", "+", "'-'", "+", "i", ".", "name", "def", "itype", "(", "i", ")", ":", "if", "i", ".", "obj", "==", "'variable'", ":", "retstr", "=", "i", ".", "vartype", "if", "retstr", "==", "'class'", ":", "retstr", "=", "'type'", "if", "i", ".", "kind", ":", "retstr", "=", "retstr", "+", "'-'", "+", "str", "(", "i", ".", "kind", ")", "if", "i", ".", "strlen", ":", "retstr", "=", "retstr", "+", "'-'", "+", "str", "(", "i", ".", "strlen", ")", "if", "i", ".", "proto", ":", "retstr", "=", "retstr", "+", "'-'", "+", "i", ".", "proto", "[", "0", "]", "return", "retstr", "elif", "i", ".", "obj", "==", "'proc'", ":", "if", "i", ".", "proctype", "!=", "'Function'", ":", "return", "i", ".", "proctype", ".", "lower", "(", ")", "else", ":", "return", "i", ".", "proctype", ".", "lower", "(", ")", "+", "'-'", "+", "itype", "(", "i", ".", "retvar", ")", "else", ":", "return", "i", ".", "obj", "def", "itype_alpha", "(", "i", ")", ":", "return", "itype", "(", "i", ")", "+", "'-'", "+", "i", ".", "name", "if", "self", ".", "settings", "[", "'sort'", "]", ".", "lower", "(", ")", "==", "'alpha'", ":", "items", ".", "sort", "(", "key", "=", "alpha", ")", "elif", "self", ".", "settings", "[", "'sort'", "]", ".", "lower", "(", ")", "==", "'permission'", ":", "items", ".", "sort", "(", "key", "=", "permission", ")", "elif", "self", ".", "settings", "[", "'sort'", "]", ".", "lower", "(", ")", "==", "'permission-alpha'", ":", "items", ".", "sort", "(", "key", "=", "permission_alpha", ")", "elif", "self", ".", "settings", "[", "'sort'", "]", ".", "lower", "(", ")", "==", "'type'", ":", "items", ".", "sort", "(", "key", "=", "itype", ")", "elif", "self", ".", "settings", "[", "'sort'", "]", ".", "lower", "(", ")", "==", "'type-alpha'", ":", "items", ".", "sort", "(", "key", "=", "itype_alpha", ")" ]
Sort the `self`'s contents, as contained in the list `items` as specified in `self`'s meta-data.
[ "Sort", "the", "self", "s", "contents", "as", "contained", "in", "the", "list", "items", "as", "specified", "in", "self", "s", "meta", "-", "data", "." ]
d46a44eae20d99205292c31785f936fbed47070f
https://github.com/Fortran-FOSS-Programmers/ford/blob/d46a44eae20d99205292c31785f936fbed47070f/ford/sourceform.py#L2402-L2451
251,802
Fortran-FOSS-Programmers/ford
ford/sourceform.py
FortranBase.contents_size
def contents_size(self): ''' Returns the number of different categories to be shown in the contents side-bar in the HTML documentation. ''' count = 0 if hasattr(self,'variables'): count += 1 if hasattr(self,'types'): count += 1 if hasattr(self,'modules'): count += 1 if hasattr(self,'submodules'): count += 1 if hasattr(self,'subroutines'): count += 1 if hasattr(self,'modprocedures'): count += 1 if hasattr(self,'functions'): count += 1 if hasattr(self,'interfaces'): count += 1 if hasattr(self,'absinterfaces'): count += 1 if hasattr(self,'programs'): count += 1 if hasattr(self,'boundprocs'): count += 1 if hasattr(self,'finalprocs'): count += 1 if hasattr(self,'enums'): count += 1 if hasattr(self,'procedure'): count += 1 if hasattr(self,'constructor'): count += 1 if hasattr(self,'modfunctions'): count += 1 if hasattr(self,'modsubroutines'): count += 1 if hasattr(self,'modprocs'): count += 1 if getattr(self,'src',None): count += 1 return count
python
def contents_size(self): ''' Returns the number of different categories to be shown in the contents side-bar in the HTML documentation. ''' count = 0 if hasattr(self,'variables'): count += 1 if hasattr(self,'types'): count += 1 if hasattr(self,'modules'): count += 1 if hasattr(self,'submodules'): count += 1 if hasattr(self,'subroutines'): count += 1 if hasattr(self,'modprocedures'): count += 1 if hasattr(self,'functions'): count += 1 if hasattr(self,'interfaces'): count += 1 if hasattr(self,'absinterfaces'): count += 1 if hasattr(self,'programs'): count += 1 if hasattr(self,'boundprocs'): count += 1 if hasattr(self,'finalprocs'): count += 1 if hasattr(self,'enums'): count += 1 if hasattr(self,'procedure'): count += 1 if hasattr(self,'constructor'): count += 1 if hasattr(self,'modfunctions'): count += 1 if hasattr(self,'modsubroutines'): count += 1 if hasattr(self,'modprocs'): count += 1 if getattr(self,'src',None): count += 1 return count
[ "def", "contents_size", "(", "self", ")", ":", "count", "=", "0", "if", "hasattr", "(", "self", ",", "'variables'", ")", ":", "count", "+=", "1", "if", "hasattr", "(", "self", ",", "'types'", ")", ":", "count", "+=", "1", "if", "hasattr", "(", "self", ",", "'modules'", ")", ":", "count", "+=", "1", "if", "hasattr", "(", "self", ",", "'submodules'", ")", ":", "count", "+=", "1", "if", "hasattr", "(", "self", ",", "'subroutines'", ")", ":", "count", "+=", "1", "if", "hasattr", "(", "self", ",", "'modprocedures'", ")", ":", "count", "+=", "1", "if", "hasattr", "(", "self", ",", "'functions'", ")", ":", "count", "+=", "1", "if", "hasattr", "(", "self", ",", "'interfaces'", ")", ":", "count", "+=", "1", "if", "hasattr", "(", "self", ",", "'absinterfaces'", ")", ":", "count", "+=", "1", "if", "hasattr", "(", "self", ",", "'programs'", ")", ":", "count", "+=", "1", "if", "hasattr", "(", "self", ",", "'boundprocs'", ")", ":", "count", "+=", "1", "if", "hasattr", "(", "self", ",", "'finalprocs'", ")", ":", "count", "+=", "1", "if", "hasattr", "(", "self", ",", "'enums'", ")", ":", "count", "+=", "1", "if", "hasattr", "(", "self", ",", "'procedure'", ")", ":", "count", "+=", "1", "if", "hasattr", "(", "self", ",", "'constructor'", ")", ":", "count", "+=", "1", "if", "hasattr", "(", "self", ",", "'modfunctions'", ")", ":", "count", "+=", "1", "if", "hasattr", "(", "self", ",", "'modsubroutines'", ")", ":", "count", "+=", "1", "if", "hasattr", "(", "self", ",", "'modprocs'", ")", ":", "count", "+=", "1", "if", "getattr", "(", "self", ",", "'src'", ",", "None", ")", ":", "count", "+=", "1", "return", "count" ]
Returns the number of different categories to be shown in the contents side-bar in the HTML documentation.
[ "Returns", "the", "number", "of", "different", "categories", "to", "be", "shown", "in", "the", "contents", "side", "-", "bar", "in", "the", "HTML", "documentation", "." ]
d46a44eae20d99205292c31785f936fbed47070f
https://github.com/Fortran-FOSS-Programmers/ford/blob/d46a44eae20d99205292c31785f936fbed47070f/ford/sourceform.py#L267-L292
251,803
Fortran-FOSS-Programmers/ford
ford/sourceform.py
FortranBase.sort
def sort(self): ''' Sorts components of the object. ''' if hasattr(self,'variables'): sort_items(self,self.variables) if hasattr(self,'modules'): sort_items(self,self.modules) if hasattr(self,'submodules'): sort_items(self,self.submodules) if hasattr(self,'common'): sort_items(self,self.common) if hasattr(self,'subroutines'): sort_items(self,self.subroutines) if hasattr(self,'modprocedures'): sort_items(self,self.modprocedures) if hasattr(self,'functions'): sort_items(self,self.functions) if hasattr(self,'interfaces'): sort_items(self,self.interfaces) if hasattr(self,'absinterfaces'): sort_items(self,self.absinterfaces) if hasattr(self,'types'): sort_items(self,self.types) if hasattr(self,'programs'): sort_items(self,self.programs) if hasattr(self,'blockdata'): sort_items(self,self.blockdata) if hasattr(self,'boundprocs'): sort_items(self,self.boundprocs) if hasattr(self,'finalprocs'): sort_items(self,self.finalprocs) if hasattr(self,'args'): #sort_items(self.args,args=True) pass
python
def sort(self): ''' Sorts components of the object. ''' if hasattr(self,'variables'): sort_items(self,self.variables) if hasattr(self,'modules'): sort_items(self,self.modules) if hasattr(self,'submodules'): sort_items(self,self.submodules) if hasattr(self,'common'): sort_items(self,self.common) if hasattr(self,'subroutines'): sort_items(self,self.subroutines) if hasattr(self,'modprocedures'): sort_items(self,self.modprocedures) if hasattr(self,'functions'): sort_items(self,self.functions) if hasattr(self,'interfaces'): sort_items(self,self.interfaces) if hasattr(self,'absinterfaces'): sort_items(self,self.absinterfaces) if hasattr(self,'types'): sort_items(self,self.types) if hasattr(self,'programs'): sort_items(self,self.programs) if hasattr(self,'blockdata'): sort_items(self,self.blockdata) if hasattr(self,'boundprocs'): sort_items(self,self.boundprocs) if hasattr(self,'finalprocs'): sort_items(self,self.finalprocs) if hasattr(self,'args'): #sort_items(self.args,args=True) pass
[ "def", "sort", "(", "self", ")", ":", "if", "hasattr", "(", "self", ",", "'variables'", ")", ":", "sort_items", "(", "self", ",", "self", ".", "variables", ")", "if", "hasattr", "(", "self", ",", "'modules'", ")", ":", "sort_items", "(", "self", ",", "self", ".", "modules", ")", "if", "hasattr", "(", "self", ",", "'submodules'", ")", ":", "sort_items", "(", "self", ",", "self", ".", "submodules", ")", "if", "hasattr", "(", "self", ",", "'common'", ")", ":", "sort_items", "(", "self", ",", "self", ".", "common", ")", "if", "hasattr", "(", "self", ",", "'subroutines'", ")", ":", "sort_items", "(", "self", ",", "self", ".", "subroutines", ")", "if", "hasattr", "(", "self", ",", "'modprocedures'", ")", ":", "sort_items", "(", "self", ",", "self", ".", "modprocedures", ")", "if", "hasattr", "(", "self", ",", "'functions'", ")", ":", "sort_items", "(", "self", ",", "self", ".", "functions", ")", "if", "hasattr", "(", "self", ",", "'interfaces'", ")", ":", "sort_items", "(", "self", ",", "self", ".", "interfaces", ")", "if", "hasattr", "(", "self", ",", "'absinterfaces'", ")", ":", "sort_items", "(", "self", ",", "self", ".", "absinterfaces", ")", "if", "hasattr", "(", "self", ",", "'types'", ")", ":", "sort_items", "(", "self", ",", "self", ".", "types", ")", "if", "hasattr", "(", "self", ",", "'programs'", ")", ":", "sort_items", "(", "self", ",", "self", ".", "programs", ")", "if", "hasattr", "(", "self", ",", "'blockdata'", ")", ":", "sort_items", "(", "self", ",", "self", ".", "blockdata", ")", "if", "hasattr", "(", "self", ",", "'boundprocs'", ")", ":", "sort_items", "(", "self", ",", "self", ".", "boundprocs", ")", "if", "hasattr", "(", "self", ",", "'finalprocs'", ")", ":", "sort_items", "(", "self", ",", "self", ".", "finalprocs", ")", "if", "hasattr", "(", "self", ",", "'args'", ")", ":", "#sort_items(self.args,args=True)", "pass" ]
Sorts components of the object.
[ "Sorts", "components", "of", "the", "object", "." ]
d46a44eae20d99205292c31785f936fbed47070f
https://github.com/Fortran-FOSS-Programmers/ford/blob/d46a44eae20d99205292c31785f936fbed47070f/ford/sourceform.py#L417-L451
251,804
Fortran-FOSS-Programmers/ford
ford/sourceform.py
FortranBase.make_links
def make_links(self, project): """ Process intra-site links to documentation of other parts of the program. """ self.doc = ford.utils.sub_links(self.doc,project) if 'summary' in self.meta: self.meta['summary'] = ford.utils.sub_links(self.meta['summary'],project) # Create links in the project for item in self.iterator('variables', 'types', 'enums', 'modules', 'submodules', 'subroutines', 'functions', 'interfaces', 'absinterfaces', 'programs', 'boundprocs', 'args', 'bindings'): if isinstance(item, FortranBase): item.make_links(project) if hasattr(self, 'retvar'): if self.retvar: if isinstance(self.retvar, FortranBase): self.retvar.make_links(project) if hasattr(self, 'procedure'): if isinstance(self.procedure, FortranBase): self.procedure.make_links(project)
python
def make_links(self, project): self.doc = ford.utils.sub_links(self.doc,project) if 'summary' in self.meta: self.meta['summary'] = ford.utils.sub_links(self.meta['summary'],project) # Create links in the project for item in self.iterator('variables', 'types', 'enums', 'modules', 'submodules', 'subroutines', 'functions', 'interfaces', 'absinterfaces', 'programs', 'boundprocs', 'args', 'bindings'): if isinstance(item, FortranBase): item.make_links(project) if hasattr(self, 'retvar'): if self.retvar: if isinstance(self.retvar, FortranBase): self.retvar.make_links(project) if hasattr(self, 'procedure'): if isinstance(self.procedure, FortranBase): self.procedure.make_links(project)
[ "def", "make_links", "(", "self", ",", "project", ")", ":", "self", ".", "doc", "=", "ford", ".", "utils", ".", "sub_links", "(", "self", ".", "doc", ",", "project", ")", "if", "'summary'", "in", "self", ".", "meta", ":", "self", ".", "meta", "[", "'summary'", "]", "=", "ford", ".", "utils", ".", "sub_links", "(", "self", ".", "meta", "[", "'summary'", "]", ",", "project", ")", "# Create links in the project", "for", "item", "in", "self", ".", "iterator", "(", "'variables'", ",", "'types'", ",", "'enums'", ",", "'modules'", ",", "'submodules'", ",", "'subroutines'", ",", "'functions'", ",", "'interfaces'", ",", "'absinterfaces'", ",", "'programs'", ",", "'boundprocs'", ",", "'args'", ",", "'bindings'", ")", ":", "if", "isinstance", "(", "item", ",", "FortranBase", ")", ":", "item", ".", "make_links", "(", "project", ")", "if", "hasattr", "(", "self", ",", "'retvar'", ")", ":", "if", "self", ".", "retvar", ":", "if", "isinstance", "(", "self", ".", "retvar", ",", "FortranBase", ")", ":", "self", ".", "retvar", ".", "make_links", "(", "project", ")", "if", "hasattr", "(", "self", ",", "'procedure'", ")", ":", "if", "isinstance", "(", "self", ".", "procedure", ",", "FortranBase", ")", ":", "self", ".", "procedure", ".", "make_links", "(", "project", ")" ]
Process intra-site links to documentation of other parts of the program.
[ "Process", "intra", "-", "site", "links", "to", "documentation", "of", "other", "parts", "of", "the", "program", "." ]
d46a44eae20d99205292c31785f936fbed47070f
https://github.com/Fortran-FOSS-Programmers/ford/blob/d46a44eae20d99205292c31785f936fbed47070f/ford/sourceform.py#L454-L475
251,805
Fortran-FOSS-Programmers/ford
ford/sourceform.py
FortranBase.iterator
def iterator(self, *argv): """ Iterator returning any list of elements via attribute lookup in `self` This iterator retains the order of the arguments """ for arg in argv: if hasattr(self, arg): for item in getattr(self, arg): yield item
python
def iterator(self, *argv): for arg in argv: if hasattr(self, arg): for item in getattr(self, arg): yield item
[ "def", "iterator", "(", "self", ",", "*", "argv", ")", ":", "for", "arg", "in", "argv", ":", "if", "hasattr", "(", "self", ",", "arg", ")", ":", "for", "item", "in", "getattr", "(", "self", ",", "arg", ")", ":", "yield", "item" ]
Iterator returning any list of elements via attribute lookup in `self` This iterator retains the order of the arguments
[ "Iterator", "returning", "any", "list", "of", "elements", "via", "attribute", "lookup", "in", "self" ]
d46a44eae20d99205292c31785f936fbed47070f
https://github.com/Fortran-FOSS-Programmers/ford/blob/d46a44eae20d99205292c31785f936fbed47070f/ford/sourceform.py#L486-L493
251,806
Fortran-FOSS-Programmers/ford
ford/sourceform.py
FortranModule.get_used_entities
def get_used_entities(self,use_specs): """ Returns the entities which are imported by a use statement. These are contained in dicts. """ if len(use_specs.strip()) == 0: return (self.pub_procs, self.pub_absints, self.pub_types, self.pub_vars) only = bool(self.ONLY_RE.match(use_specs)) use_specs = self.ONLY_RE.sub('',use_specs) ulist = self.SPLIT_RE.split(use_specs) ulist[-1] = ulist[-1].strip() uspecs = {} for item in ulist: match = self.RENAME_RE.search(item) if match: uspecs[match.group(1).lower()] = match.group(2) else: uspecs[item.lower()] = item ret_procs = {} ret_absints = {} ret_types = {} ret_vars = {} for name, obj in self.pub_procs.items(): name = name.lower() if only: if name in uspecs: ret_procs[name] = obj else: ret_procs[name] = obj for name, obj in self.pub_absints.items(): name = name.lower() if only: if name in uspecs: ret_absints[name] = obj else: ret_absints[name] = obj for name, obj in self.pub_types.items(): name = name.lower() if only: if name in uspecs: ret_types[name] = obj else: ret_types[name] = obj for name, obj in self.pub_vars.items(): name = name.lower() if only: if name in uspecs: ret_vars[name] = obj else: ret_vars[name] = obj return (ret_procs,ret_absints,ret_types,ret_vars)
python
def get_used_entities(self,use_specs): if len(use_specs.strip()) == 0: return (self.pub_procs, self.pub_absints, self.pub_types, self.pub_vars) only = bool(self.ONLY_RE.match(use_specs)) use_specs = self.ONLY_RE.sub('',use_specs) ulist = self.SPLIT_RE.split(use_specs) ulist[-1] = ulist[-1].strip() uspecs = {} for item in ulist: match = self.RENAME_RE.search(item) if match: uspecs[match.group(1).lower()] = match.group(2) else: uspecs[item.lower()] = item ret_procs = {} ret_absints = {} ret_types = {} ret_vars = {} for name, obj in self.pub_procs.items(): name = name.lower() if only: if name in uspecs: ret_procs[name] = obj else: ret_procs[name] = obj for name, obj in self.pub_absints.items(): name = name.lower() if only: if name in uspecs: ret_absints[name] = obj else: ret_absints[name] = obj for name, obj in self.pub_types.items(): name = name.lower() if only: if name in uspecs: ret_types[name] = obj else: ret_types[name] = obj for name, obj in self.pub_vars.items(): name = name.lower() if only: if name in uspecs: ret_vars[name] = obj else: ret_vars[name] = obj return (ret_procs,ret_absints,ret_types,ret_vars)
[ "def", "get_used_entities", "(", "self", ",", "use_specs", ")", ":", "if", "len", "(", "use_specs", ".", "strip", "(", ")", ")", "==", "0", ":", "return", "(", "self", ".", "pub_procs", ",", "self", ".", "pub_absints", ",", "self", ".", "pub_types", ",", "self", ".", "pub_vars", ")", "only", "=", "bool", "(", "self", ".", "ONLY_RE", ".", "match", "(", "use_specs", ")", ")", "use_specs", "=", "self", ".", "ONLY_RE", ".", "sub", "(", "''", ",", "use_specs", ")", "ulist", "=", "self", ".", "SPLIT_RE", ".", "split", "(", "use_specs", ")", "ulist", "[", "-", "1", "]", "=", "ulist", "[", "-", "1", "]", ".", "strip", "(", ")", "uspecs", "=", "{", "}", "for", "item", "in", "ulist", ":", "match", "=", "self", ".", "RENAME_RE", ".", "search", "(", "item", ")", "if", "match", ":", "uspecs", "[", "match", ".", "group", "(", "1", ")", ".", "lower", "(", ")", "]", "=", "match", ".", "group", "(", "2", ")", "else", ":", "uspecs", "[", "item", ".", "lower", "(", ")", "]", "=", "item", "ret_procs", "=", "{", "}", "ret_absints", "=", "{", "}", "ret_types", "=", "{", "}", "ret_vars", "=", "{", "}", "for", "name", ",", "obj", "in", "self", ".", "pub_procs", ".", "items", "(", ")", ":", "name", "=", "name", ".", "lower", "(", ")", "if", "only", ":", "if", "name", "in", "uspecs", ":", "ret_procs", "[", "name", "]", "=", "obj", "else", ":", "ret_procs", "[", "name", "]", "=", "obj", "for", "name", ",", "obj", "in", "self", ".", "pub_absints", ".", "items", "(", ")", ":", "name", "=", "name", ".", "lower", "(", ")", "if", "only", ":", "if", "name", "in", "uspecs", ":", "ret_absints", "[", "name", "]", "=", "obj", "else", ":", "ret_absints", "[", "name", "]", "=", "obj", "for", "name", ",", "obj", "in", "self", ".", "pub_types", ".", "items", "(", ")", ":", "name", "=", "name", ".", "lower", "(", ")", "if", "only", ":", "if", "name", "in", "uspecs", ":", "ret_types", "[", "name", "]", "=", "obj", "else", ":", "ret_types", "[", "name", "]", "=", "obj", "for", "name", ",", "obj", "in", "self", ".", "pub_vars", ".", "items", "(", ")", ":", "name", "=", "name", ".", "lower", "(", ")", "if", "only", ":", "if", "name", "in", "uspecs", ":", "ret_vars", "[", "name", "]", "=", "obj", "else", ":", "ret_vars", "[", "name", "]", "=", "obj", "return", "(", "ret_procs", ",", "ret_absints", ",", "ret_types", ",", "ret_vars", ")" ]
Returns the entities which are imported by a use statement. These are contained in dicts.
[ "Returns", "the", "entities", "which", "are", "imported", "by", "a", "use", "statement", ".", "These", "are", "contained", "in", "dicts", "." ]
d46a44eae20d99205292c31785f936fbed47070f
https://github.com/Fortran-FOSS-Programmers/ford/blob/d46a44eae20d99205292c31785f936fbed47070f/ford/sourceform.py#L1138-L1188
251,807
Fortran-FOSS-Programmers/ford
ford/sourceform.py
NameSelector.get_name
def get_name(self,item): """ Return the name for this item registered with this NameSelector. If no name has previously been registered, then generate a new one. """ if not isinstance(item,ford.sourceform.FortranBase): raise Exception('{} is not of a type derived from FortranBase'.format(str(item))) if item in self._items: return self._items[item] else: if item.get_dir() not in self._counts: self._counts[item.get_dir()] = {} if item.name in self._counts[item.get_dir()]: num = self._counts[item.get_dir()][item.name] + 1 else: num = 1 self._counts[item.get_dir()][item.name] = num name = item.name.lower().replace('<','lt') # name is already lower name = name.replace('>','gt') name = name.replace('/','SLASH') if name == '': name = '__unnamed__' if num > 1: name = name + '~' + str(num) self._items[item] = name return name
python
def get_name(self,item): if not isinstance(item,ford.sourceform.FortranBase): raise Exception('{} is not of a type derived from FortranBase'.format(str(item))) if item in self._items: return self._items[item] else: if item.get_dir() not in self._counts: self._counts[item.get_dir()] = {} if item.name in self._counts[item.get_dir()]: num = self._counts[item.get_dir()][item.name] + 1 else: num = 1 self._counts[item.get_dir()][item.name] = num name = item.name.lower().replace('<','lt') # name is already lower name = name.replace('>','gt') name = name.replace('/','SLASH') if name == '': name = '__unnamed__' if num > 1: name = name + '~' + str(num) self._items[item] = name return name
[ "def", "get_name", "(", "self", ",", "item", ")", ":", "if", "not", "isinstance", "(", "item", ",", "ford", ".", "sourceform", ".", "FortranBase", ")", ":", "raise", "Exception", "(", "'{} is not of a type derived from FortranBase'", ".", "format", "(", "str", "(", "item", ")", ")", ")", "if", "item", "in", "self", ".", "_items", ":", "return", "self", ".", "_items", "[", "item", "]", "else", ":", "if", "item", ".", "get_dir", "(", ")", "not", "in", "self", ".", "_counts", ":", "self", ".", "_counts", "[", "item", ".", "get_dir", "(", ")", "]", "=", "{", "}", "if", "item", ".", "name", "in", "self", ".", "_counts", "[", "item", ".", "get_dir", "(", ")", "]", ":", "num", "=", "self", ".", "_counts", "[", "item", ".", "get_dir", "(", ")", "]", "[", "item", ".", "name", "]", "+", "1", "else", ":", "num", "=", "1", "self", ".", "_counts", "[", "item", ".", "get_dir", "(", ")", "]", "[", "item", ".", "name", "]", "=", "num", "name", "=", "item", ".", "name", ".", "lower", "(", ")", ".", "replace", "(", "'<'", ",", "'lt'", ")", "# name is already lower", "name", "=", "name", ".", "replace", "(", "'>'", ",", "'gt'", ")", "name", "=", "name", ".", "replace", "(", "'/'", ",", "'SLASH'", ")", "if", "name", "==", "''", ":", "name", "=", "'__unnamed__'", "if", "num", ">", "1", ":", "name", "=", "name", "+", "'~'", "+", "str", "(", "num", ")", "self", ".", "_items", "[", "item", "]", "=", "name", "return", "name" ]
Return the name for this item registered with this NameSelector. If no name has previously been registered, then generate a new one.
[ "Return", "the", "name", "for", "this", "item", "registered", "with", "this", "NameSelector", ".", "If", "no", "name", "has", "previously", "been", "registered", "then", "generate", "a", "new", "one", "." ]
d46a44eae20d99205292c31785f936fbed47070f
https://github.com/Fortran-FOSS-Programmers/ford/blob/d46a44eae20d99205292c31785f936fbed47070f/ford/sourceform.py#L2466-L2493
251,808
Fortran-FOSS-Programmers/ford
ford/__init__.py
main
def main(proj_data,proj_docs,md): """ Main driver of FORD. """ if proj_data['relative']: proj_data['project_url'] = '.' # Parse the files in your project project = ford.fortran_project.Project(proj_data) if len(project.files) < 1: print("Error: No source files with appropriate extension found in specified directory.") sys.exit(1) # Convert the documentation from Markdown to HTML. Make sure to properly # handle LateX and metadata. if proj_data['relative']: project.markdown(md,'..') else: project.markdown(md,proj_data['project_url']) project.correlate() if proj_data['relative']: project.make_links('..') else: project.make_links(proj_data['project_url']) # Convert summaries and descriptions to HTML if proj_data['relative']: ford.sourceform.set_base_url('.') if 'summary' in proj_data: proj_data['summary'] = md.convert(proj_data['summary']) proj_data['summary'] = ford.utils.sub_links(ford.utils.sub_macros(ford.utils.sub_notes(proj_data['summary']),proj_data['project_url']),project) if 'author_description' in proj_data: proj_data['author_description'] = md.convert(proj_data['author_description']) proj_data['author_description'] = ford.utils.sub_links(ford.utils.sub_macros(ford.utils.sub_notes(proj_data['author_description']),proj_data['project_url']),project) proj_docs_ = ford.utils.sub_links(ford.utils.sub_macros(ford.utils.sub_notes(proj_docs),proj_data['project_url']),project) # Process any pages if 'page_dir' in proj_data: page_tree = ford.pagetree.get_page_tree(os.path.normpath(proj_data['page_dir']),md) print() else: page_tree = None proj_data['pages'] = page_tree # Produce the documentation using Jinja2. Output it to the desired location # and copy any files that are needed (CSS, JS, images, fonts, source files, # etc.) docs = ford.output.Documentation(proj_data,proj_docs_,project,page_tree) docs.writeout() print('') return 0
python
def main(proj_data,proj_docs,md): if proj_data['relative']: proj_data['project_url'] = '.' # Parse the files in your project project = ford.fortran_project.Project(proj_data) if len(project.files) < 1: print("Error: No source files with appropriate extension found in specified directory.") sys.exit(1) # Convert the documentation from Markdown to HTML. Make sure to properly # handle LateX and metadata. if proj_data['relative']: project.markdown(md,'..') else: project.markdown(md,proj_data['project_url']) project.correlate() if proj_data['relative']: project.make_links('..') else: project.make_links(proj_data['project_url']) # Convert summaries and descriptions to HTML if proj_data['relative']: ford.sourceform.set_base_url('.') if 'summary' in proj_data: proj_data['summary'] = md.convert(proj_data['summary']) proj_data['summary'] = ford.utils.sub_links(ford.utils.sub_macros(ford.utils.sub_notes(proj_data['summary']),proj_data['project_url']),project) if 'author_description' in proj_data: proj_data['author_description'] = md.convert(proj_data['author_description']) proj_data['author_description'] = ford.utils.sub_links(ford.utils.sub_macros(ford.utils.sub_notes(proj_data['author_description']),proj_data['project_url']),project) proj_docs_ = ford.utils.sub_links(ford.utils.sub_macros(ford.utils.sub_notes(proj_docs),proj_data['project_url']),project) # Process any pages if 'page_dir' in proj_data: page_tree = ford.pagetree.get_page_tree(os.path.normpath(proj_data['page_dir']),md) print() else: page_tree = None proj_data['pages'] = page_tree # Produce the documentation using Jinja2. Output it to the desired location # and copy any files that are needed (CSS, JS, images, fonts, source files, # etc.) docs = ford.output.Documentation(proj_data,proj_docs_,project,page_tree) docs.writeout() print('') return 0
[ "def", "main", "(", "proj_data", ",", "proj_docs", ",", "md", ")", ":", "if", "proj_data", "[", "'relative'", "]", ":", "proj_data", "[", "'project_url'", "]", "=", "'.'", "# Parse the files in your project", "project", "=", "ford", ".", "fortran_project", ".", "Project", "(", "proj_data", ")", "if", "len", "(", "project", ".", "files", ")", "<", "1", ":", "print", "(", "\"Error: No source files with appropriate extension found in specified directory.\"", ")", "sys", ".", "exit", "(", "1", ")", "# Convert the documentation from Markdown to HTML. Make sure to properly", "# handle LateX and metadata.", "if", "proj_data", "[", "'relative'", "]", ":", "project", ".", "markdown", "(", "md", ",", "'..'", ")", "else", ":", "project", ".", "markdown", "(", "md", ",", "proj_data", "[", "'project_url'", "]", ")", "project", ".", "correlate", "(", ")", "if", "proj_data", "[", "'relative'", "]", ":", "project", ".", "make_links", "(", "'..'", ")", "else", ":", "project", ".", "make_links", "(", "proj_data", "[", "'project_url'", "]", ")", "# Convert summaries and descriptions to HTML", "if", "proj_data", "[", "'relative'", "]", ":", "ford", ".", "sourceform", ".", "set_base_url", "(", "'.'", ")", "if", "'summary'", "in", "proj_data", ":", "proj_data", "[", "'summary'", "]", "=", "md", ".", "convert", "(", "proj_data", "[", "'summary'", "]", ")", "proj_data", "[", "'summary'", "]", "=", "ford", ".", "utils", ".", "sub_links", "(", "ford", ".", "utils", ".", "sub_macros", "(", "ford", ".", "utils", ".", "sub_notes", "(", "proj_data", "[", "'summary'", "]", ")", ",", "proj_data", "[", "'project_url'", "]", ")", ",", "project", ")", "if", "'author_description'", "in", "proj_data", ":", "proj_data", "[", "'author_description'", "]", "=", "md", ".", "convert", "(", "proj_data", "[", "'author_description'", "]", ")", "proj_data", "[", "'author_description'", "]", "=", "ford", ".", "utils", ".", "sub_links", "(", "ford", ".", "utils", ".", "sub_macros", "(", "ford", ".", "utils", ".", "sub_notes", "(", "proj_data", "[", "'author_description'", "]", ")", ",", "proj_data", "[", "'project_url'", "]", ")", ",", "project", ")", "proj_docs_", "=", "ford", ".", "utils", ".", "sub_links", "(", "ford", ".", "utils", ".", "sub_macros", "(", "ford", ".", "utils", ".", "sub_notes", "(", "proj_docs", ")", ",", "proj_data", "[", "'project_url'", "]", ")", ",", "project", ")", "# Process any pages", "if", "'page_dir'", "in", "proj_data", ":", "page_tree", "=", "ford", ".", "pagetree", ".", "get_page_tree", "(", "os", ".", "path", ".", "normpath", "(", "proj_data", "[", "'page_dir'", "]", ")", ",", "md", ")", "print", "(", ")", "else", ":", "page_tree", "=", "None", "proj_data", "[", "'pages'", "]", "=", "page_tree", "# Produce the documentation using Jinja2. Output it to the desired location", "# and copy any files that are needed (CSS, JS, images, fonts, source files,", "# etc.)", "docs", "=", "ford", ".", "output", ".", "Documentation", "(", "proj_data", ",", "proj_docs_", ",", "project", ",", "page_tree", ")", "docs", ".", "writeout", "(", ")", "print", "(", "''", ")", "return", "0" ]
Main driver of FORD.
[ "Main", "driver", "of", "FORD", "." ]
d46a44eae20d99205292c31785f936fbed47070f
https://github.com/Fortran-FOSS-Programmers/ford/blob/d46a44eae20d99205292c31785f936fbed47070f/ford/__init__.py#L337-L382
251,809
Fortran-FOSS-Programmers/ford
ford/fixed2free2.py
convertToFree
def convertToFree(stream, length_limit=True): """Convert stream from fixed source form to free source form.""" linestack = [] for line in stream: convline = FortranLine(line, length_limit) if convline.is_regular: if convline.isContinuation and linestack: linestack[0].continueLine() for l in linestack: yield str(l) linestack = [] linestack.append(convline) for l in linestack: yield str(l)
python
def convertToFree(stream, length_limit=True): linestack = [] for line in stream: convline = FortranLine(line, length_limit) if convline.is_regular: if convline.isContinuation and linestack: linestack[0].continueLine() for l in linestack: yield str(l) linestack = [] linestack.append(convline) for l in linestack: yield str(l)
[ "def", "convertToFree", "(", "stream", ",", "length_limit", "=", "True", ")", ":", "linestack", "=", "[", "]", "for", "line", "in", "stream", ":", "convline", "=", "FortranLine", "(", "line", ",", "length_limit", ")", "if", "convline", ".", "is_regular", ":", "if", "convline", ".", "isContinuation", "and", "linestack", ":", "linestack", "[", "0", "]", ".", "continueLine", "(", ")", "for", "l", "in", "linestack", ":", "yield", "str", "(", "l", ")", "linestack", "=", "[", "]", "linestack", ".", "append", "(", "convline", ")", "for", "l", "in", "linestack", ":", "yield", "str", "(", "l", ")" ]
Convert stream from fixed source form to free source form.
[ "Convert", "stream", "from", "fixed", "source", "form", "to", "free", "source", "form", "." ]
d46a44eae20d99205292c31785f936fbed47070f
https://github.com/Fortran-FOSS-Programmers/ford/blob/d46a44eae20d99205292c31785f936fbed47070f/ford/fixed2free2.py#L110-L127
251,810
Fortran-FOSS-Programmers/ford
ford/fixed2free2.py
FortranLine.continueLine
def continueLine(self): """Insert line continuation symbol at end of line.""" if not (self.isLong and self.is_regular): self.line_conv = self.line_conv.rstrip() + " &\n" else: temp = self.line_conv[:72].rstrip() + " &" self.line_conv = temp.ljust(72) + self.excess_line
python
def continueLine(self): if not (self.isLong and self.is_regular): self.line_conv = self.line_conv.rstrip() + " &\n" else: temp = self.line_conv[:72].rstrip() + " &" self.line_conv = temp.ljust(72) + self.excess_line
[ "def", "continueLine", "(", "self", ")", ":", "if", "not", "(", "self", ".", "isLong", "and", "self", ".", "is_regular", ")", ":", "self", ".", "line_conv", "=", "self", ".", "line_conv", ".", "rstrip", "(", ")", "+", "\" &\\n\"", "else", ":", "temp", "=", "self", ".", "line_conv", "[", ":", "72", "]", ".", "rstrip", "(", ")", "+", "\" &\"", "self", ".", "line_conv", "=", "temp", ".", "ljust", "(", "72", ")", "+", "self", ".", "excess_line" ]
Insert line continuation symbol at end of line.
[ "Insert", "line", "continuation", "symbol", "at", "end", "of", "line", "." ]
d46a44eae20d99205292c31785f936fbed47070f
https://github.com/Fortran-FOSS-Programmers/ford/blob/d46a44eae20d99205292c31785f936fbed47070f/ford/fixed2free2.py#L52-L59
251,811
Fortran-FOSS-Programmers/ford
ford/fortran_project.py
id_mods
def id_mods(obj,modlist,intrinsic_mods={},submodlist=[]): """ Match USE statements up with the right modules """ for i in range(len(obj.uses)): for candidate in modlist: if obj.uses[i][0].lower() == candidate.name.lower(): obj.uses[i] = [candidate, obj.uses[i][1]] break else: if obj.uses[i][0].lower() in intrinsic_mods: obj.uses[i] = [intrinsic_mods[obj.uses[i][0].lower()], obj.uses[i][1]] continue if getattr(obj,'ancestor',None): for submod in submodlist: if obj.ancestor.lower() == submod.name.lower(): obj.ancestor = submod break if hasattr(obj,'ancestor_mod'): for mod in modlist: if obj.ancestor_mod.lower() == mod.name.lower(): obj.ancestor_mod = mod break for modproc in getattr(obj,'modprocedures',[]): id_mods(modproc,modlist,intrinsic_mods) for func in getattr(obj,'functions',[]): id_mods(func,modlist,intrinsic_mods) for subroutine in getattr(obj,'subroutines',[]): id_mods(subroutine,modlist,intrinsic_mods)
python
def id_mods(obj,modlist,intrinsic_mods={},submodlist=[]): for i in range(len(obj.uses)): for candidate in modlist: if obj.uses[i][0].lower() == candidate.name.lower(): obj.uses[i] = [candidate, obj.uses[i][1]] break else: if obj.uses[i][0].lower() in intrinsic_mods: obj.uses[i] = [intrinsic_mods[obj.uses[i][0].lower()], obj.uses[i][1]] continue if getattr(obj,'ancestor',None): for submod in submodlist: if obj.ancestor.lower() == submod.name.lower(): obj.ancestor = submod break if hasattr(obj,'ancestor_mod'): for mod in modlist: if obj.ancestor_mod.lower() == mod.name.lower(): obj.ancestor_mod = mod break for modproc in getattr(obj,'modprocedures',[]): id_mods(modproc,modlist,intrinsic_mods) for func in getattr(obj,'functions',[]): id_mods(func,modlist,intrinsic_mods) for subroutine in getattr(obj,'subroutines',[]): id_mods(subroutine,modlist,intrinsic_mods)
[ "def", "id_mods", "(", "obj", ",", "modlist", ",", "intrinsic_mods", "=", "{", "}", ",", "submodlist", "=", "[", "]", ")", ":", "for", "i", "in", "range", "(", "len", "(", "obj", ".", "uses", ")", ")", ":", "for", "candidate", "in", "modlist", ":", "if", "obj", ".", "uses", "[", "i", "]", "[", "0", "]", ".", "lower", "(", ")", "==", "candidate", ".", "name", ".", "lower", "(", ")", ":", "obj", ".", "uses", "[", "i", "]", "=", "[", "candidate", ",", "obj", ".", "uses", "[", "i", "]", "[", "1", "]", "]", "break", "else", ":", "if", "obj", ".", "uses", "[", "i", "]", "[", "0", "]", ".", "lower", "(", ")", "in", "intrinsic_mods", ":", "obj", ".", "uses", "[", "i", "]", "=", "[", "intrinsic_mods", "[", "obj", ".", "uses", "[", "i", "]", "[", "0", "]", ".", "lower", "(", ")", "]", ",", "obj", ".", "uses", "[", "i", "]", "[", "1", "]", "]", "continue", "if", "getattr", "(", "obj", ",", "'ancestor'", ",", "None", ")", ":", "for", "submod", "in", "submodlist", ":", "if", "obj", ".", "ancestor", ".", "lower", "(", ")", "==", "submod", ".", "name", ".", "lower", "(", ")", ":", "obj", ".", "ancestor", "=", "submod", "break", "if", "hasattr", "(", "obj", ",", "'ancestor_mod'", ")", ":", "for", "mod", "in", "modlist", ":", "if", "obj", ".", "ancestor_mod", ".", "lower", "(", ")", "==", "mod", ".", "name", ".", "lower", "(", ")", ":", "obj", ".", "ancestor_mod", "=", "mod", "break", "for", "modproc", "in", "getattr", "(", "obj", ",", "'modprocedures'", ",", "[", "]", ")", ":", "id_mods", "(", "modproc", ",", "modlist", ",", "intrinsic_mods", ")", "for", "func", "in", "getattr", "(", "obj", ",", "'functions'", ",", "[", "]", ")", ":", "id_mods", "(", "func", ",", "modlist", ",", "intrinsic_mods", ")", "for", "subroutine", "in", "getattr", "(", "obj", ",", "'subroutines'", ",", "[", "]", ")", ":", "id_mods", "(", "subroutine", ",", "modlist", ",", "intrinsic_mods", ")" ]
Match USE statements up with the right modules
[ "Match", "USE", "statements", "up", "with", "the", "right", "modules" ]
d46a44eae20d99205292c31785f936fbed47070f
https://github.com/Fortran-FOSS-Programmers/ford/blob/d46a44eae20d99205292c31785f936fbed47070f/ford/fortran_project.py#L338-L366
251,812
Fortran-FOSS-Programmers/ford
ford/fortran_project.py
Project.allfiles
def allfiles(self): """ Instead of duplicating files, it is much more efficient to create the itterator on the fly """ for f in self.files: yield f for f in self.extra_files: yield f
python
def allfiles(self): for f in self.files: yield f for f in self.extra_files: yield f
[ "def", "allfiles", "(", "self", ")", ":", "for", "f", "in", "self", ".", "files", ":", "yield", "f", "for", "f", "in", "self", ".", "extra_files", ":", "yield", "f" ]
Instead of duplicating files, it is much more efficient to create the itterator on the fly
[ "Instead", "of", "duplicating", "files", "it", "is", "much", "more", "efficient", "to", "create", "the", "itterator", "on", "the", "fly" ]
d46a44eae20d99205292c31785f936fbed47070f
https://github.com/Fortran-FOSS-Programmers/ford/blob/d46a44eae20d99205292c31785f936fbed47070f/ford/fortran_project.py#L124-L129
251,813
Fortran-FOSS-Programmers/ford
ford/fortran_project.py
Project.make_links
def make_links(self,base_url='..'): """ Substitute intrasite links to documentation for other parts of the program. """ ford.sourceform.set_base_url(base_url) for src in self.allfiles: src.make_links(self)
python
def make_links(self,base_url='..'): ford.sourceform.set_base_url(base_url) for src in self.allfiles: src.make_links(self)
[ "def", "make_links", "(", "self", ",", "base_url", "=", "'..'", ")", ":", "ford", ".", "sourceform", ".", "set_base_url", "(", "base_url", ")", "for", "src", "in", "self", ".", "allfiles", ":", "src", ".", "make_links", "(", "self", ")" ]
Substitute intrasite links to documentation for other parts of the program.
[ "Substitute", "intrasite", "links", "to", "documentation", "for", "other", "parts", "of", "the", "program", "." ]
d46a44eae20d99205292c31785f936fbed47070f
https://github.com/Fortran-FOSS-Programmers/ford/blob/d46a44eae20d99205292c31785f936fbed47070f/ford/fortran_project.py#L305-L312
251,814
Fortran-FOSS-Programmers/ford
ford/utils.py
sub_notes
def sub_notes(docs): """ Substitutes the special controls for notes, warnings, todos, and bugs with the corresponding div. """ def substitute(match): ret = "</p><div class=\"alert alert-{}\" role=\"alert\"><h4>{}</h4>" \ "<p>{}</p></div>".format(NOTE_TYPE[match.group(1).lower()], match.group(1).capitalize(), match.group(2)) if len(match.groups()) >= 4 and not match.group(4): ret += '\n<p>' return ret for regex in NOTE_RE: docs = regex.sub(substitute,docs) return docs
python
def sub_notes(docs): def substitute(match): ret = "</p><div class=\"alert alert-{}\" role=\"alert\"><h4>{}</h4>" \ "<p>{}</p></div>".format(NOTE_TYPE[match.group(1).lower()], match.group(1).capitalize(), match.group(2)) if len(match.groups()) >= 4 and not match.group(4): ret += '\n<p>' return ret for regex in NOTE_RE: docs = regex.sub(substitute,docs) return docs
[ "def", "sub_notes", "(", "docs", ")", ":", "def", "substitute", "(", "match", ")", ":", "ret", "=", "\"</p><div class=\\\"alert alert-{}\\\" role=\\\"alert\\\"><h4>{}</h4>\"", "\"<p>{}</p></div>\"", ".", "format", "(", "NOTE_TYPE", "[", "match", ".", "group", "(", "1", ")", ".", "lower", "(", ")", "]", ",", "match", ".", "group", "(", "1", ")", ".", "capitalize", "(", ")", ",", "match", ".", "group", "(", "2", ")", ")", "if", "len", "(", "match", ".", "groups", "(", ")", ")", ">=", "4", "and", "not", "match", ".", "group", "(", "4", ")", ":", "ret", "+=", "'\\n<p>'", "return", "ret", "for", "regex", "in", "NOTE_RE", ":", "docs", "=", "regex", ".", "sub", "(", "substitute", ",", "docs", ")", "return", "docs" ]
Substitutes the special controls for notes, warnings, todos, and bugs with the corresponding div.
[ "Substitutes", "the", "special", "controls", "for", "notes", "warnings", "todos", "and", "bugs", "with", "the", "corresponding", "div", "." ]
d46a44eae20d99205292c31785f936fbed47070f
https://github.com/Fortran-FOSS-Programmers/ford/blob/d46a44eae20d99205292c31785f936fbed47070f/ford/utils.py#L42-L55
251,815
Fortran-FOSS-Programmers/ford
ford/utils.py
paren_split
def paren_split(sep,string): """ Splits the string into pieces divided by sep, when sep is outside of parentheses. """ if len(sep) != 1: raise Exception("Separation string must be one character long") retlist = [] level = 0 blevel = 0 left = 0 for i in range(len(string)): if string[i] == "(": level += 1 elif string[i] == ")": level -= 1 elif string[i] == "[": blevel += 1 elif string[i] == "]": blevel -= 1 elif string[i] == sep and level == 0 and blevel == 0: retlist.append(string[left:i]) left = i+1 retlist.append(string[left:]) return retlist
python
def paren_split(sep,string): if len(sep) != 1: raise Exception("Separation string must be one character long") retlist = [] level = 0 blevel = 0 left = 0 for i in range(len(string)): if string[i] == "(": level += 1 elif string[i] == ")": level -= 1 elif string[i] == "[": blevel += 1 elif string[i] == "]": blevel -= 1 elif string[i] == sep and level == 0 and blevel == 0: retlist.append(string[left:i]) left = i+1 retlist.append(string[left:]) return retlist
[ "def", "paren_split", "(", "sep", ",", "string", ")", ":", "if", "len", "(", "sep", ")", "!=", "1", ":", "raise", "Exception", "(", "\"Separation string must be one character long\"", ")", "retlist", "=", "[", "]", "level", "=", "0", "blevel", "=", "0", "left", "=", "0", "for", "i", "in", "range", "(", "len", "(", "string", ")", ")", ":", "if", "string", "[", "i", "]", "==", "\"(\"", ":", "level", "+=", "1", "elif", "string", "[", "i", "]", "==", "\")\"", ":", "level", "-=", "1", "elif", "string", "[", "i", "]", "==", "\"[\"", ":", "blevel", "+=", "1", "elif", "string", "[", "i", "]", "==", "\"]\"", ":", "blevel", "-=", "1", "elif", "string", "[", "i", "]", "==", "sep", "and", "level", "==", "0", "and", "blevel", "==", "0", ":", "retlist", ".", "append", "(", "string", "[", "left", ":", "i", "]", ")", "left", "=", "i", "+", "1", "retlist", ".", "append", "(", "string", "[", "left", ":", "]", ")", "return", "retlist" ]
Splits the string into pieces divided by sep, when sep is outside of parentheses.
[ "Splits", "the", "string", "into", "pieces", "divided", "by", "sep", "when", "sep", "is", "outside", "of", "parentheses", "." ]
d46a44eae20d99205292c31785f936fbed47070f
https://github.com/Fortran-FOSS-Programmers/ford/blob/d46a44eae20d99205292c31785f936fbed47070f/ford/utils.py#L88-L106
251,816
Fortran-FOSS-Programmers/ford
ford/utils.py
quote_split
def quote_split(sep,string): """ Splits the strings into pieces divided by sep, when sep in not inside quotes. """ if len(sep) != 1: raise Exception("Separation string must be one character long") retlist = [] squote = False dquote = False left = 0 i = 0 while i < len(string): if string[i] == '"' and not dquote: if not squote: squote = True elif (i+1) < len(string) and string[i+1] == '"': i += 1 else: squote = False elif string[i] == "'" and not squote: if not dquote: dquote = True elif (i+1) < len(string) and string[i+1] == "'": i += 1 else: dquote = False elif string[i] == sep and not dquote and not squote: retlist.append(string[left:i]) left = i + 1 i += 1 retlist.append(string[left:]) return retlist
python
def quote_split(sep,string): if len(sep) != 1: raise Exception("Separation string must be one character long") retlist = [] squote = False dquote = False left = 0 i = 0 while i < len(string): if string[i] == '"' and not dquote: if not squote: squote = True elif (i+1) < len(string) and string[i+1] == '"': i += 1 else: squote = False elif string[i] == "'" and not squote: if not dquote: dquote = True elif (i+1) < len(string) and string[i+1] == "'": i += 1 else: dquote = False elif string[i] == sep and not dquote and not squote: retlist.append(string[left:i]) left = i + 1 i += 1 retlist.append(string[left:]) return retlist
[ "def", "quote_split", "(", "sep", ",", "string", ")", ":", "if", "len", "(", "sep", ")", "!=", "1", ":", "raise", "Exception", "(", "\"Separation string must be one character long\"", ")", "retlist", "=", "[", "]", "squote", "=", "False", "dquote", "=", "False", "left", "=", "0", "i", "=", "0", "while", "i", "<", "len", "(", "string", ")", ":", "if", "string", "[", "i", "]", "==", "'\"'", "and", "not", "dquote", ":", "if", "not", "squote", ":", "squote", "=", "True", "elif", "(", "i", "+", "1", ")", "<", "len", "(", "string", ")", "and", "string", "[", "i", "+", "1", "]", "==", "'\"'", ":", "i", "+=", "1", "else", ":", "squote", "=", "False", "elif", "string", "[", "i", "]", "==", "\"'\"", "and", "not", "squote", ":", "if", "not", "dquote", ":", "dquote", "=", "True", "elif", "(", "i", "+", "1", ")", "<", "len", "(", "string", ")", "and", "string", "[", "i", "+", "1", "]", "==", "\"'\"", ":", "i", "+=", "1", "else", ":", "dquote", "=", "False", "elif", "string", "[", "i", "]", "==", "sep", "and", "not", "dquote", "and", "not", "squote", ":", "retlist", ".", "append", "(", "string", "[", "left", ":", "i", "]", ")", "left", "=", "i", "+", "1", "i", "+=", "1", "retlist", ".", "append", "(", "string", "[", "left", ":", "]", ")", "return", "retlist" ]
Splits the strings into pieces divided by sep, when sep in not inside quotes.
[ "Splits", "the", "strings", "into", "pieces", "divided", "by", "sep", "when", "sep", "in", "not", "inside", "quotes", "." ]
d46a44eae20d99205292c31785f936fbed47070f
https://github.com/Fortran-FOSS-Programmers/ford/blob/d46a44eae20d99205292c31785f936fbed47070f/ford/utils.py#L110-L140
251,817
Fortran-FOSS-Programmers/ford
ford/utils.py
split_path
def split_path(path): ''' Splits the argument into its constituent directories and returns them as a list. ''' def recurse_path(path,retlist): if len(retlist) > 100: fullpath = os.path.join(*([ path, ] + retlist)) print("Directory '{}' contains too many levels".format(fullpath)) exit(1) head, tail = os.path.split(path) if len(tail) > 0: retlist.insert(0,tail) recurse_path(head,retlist) elif len(head) > 1: recurse_path(head,retlist) else: return retlist = [] path = os.path.realpath(os.path.normpath(path)) drive, path = os.path.splitdrive(path) if len(drive) > 0: retlist.append(drive) recurse_path(path,retlist) return retlist
python
def split_path(path): ''' Splits the argument into its constituent directories and returns them as a list. ''' def recurse_path(path,retlist): if len(retlist) > 100: fullpath = os.path.join(*([ path, ] + retlist)) print("Directory '{}' contains too many levels".format(fullpath)) exit(1) head, tail = os.path.split(path) if len(tail) > 0: retlist.insert(0,tail) recurse_path(head,retlist) elif len(head) > 1: recurse_path(head,retlist) else: return retlist = [] path = os.path.realpath(os.path.normpath(path)) drive, path = os.path.splitdrive(path) if len(drive) > 0: retlist.append(drive) recurse_path(path,retlist) return retlist
[ "def", "split_path", "(", "path", ")", ":", "def", "recurse_path", "(", "path", ",", "retlist", ")", ":", "if", "len", "(", "retlist", ")", ">", "100", ":", "fullpath", "=", "os", ".", "path", ".", "join", "(", "*", "(", "[", "path", ",", "]", "+", "retlist", ")", ")", "print", "(", "\"Directory '{}' contains too many levels\"", ".", "format", "(", "fullpath", ")", ")", "exit", "(", "1", ")", "head", ",", "tail", "=", "os", ".", "path", ".", "split", "(", "path", ")", "if", "len", "(", "tail", ")", ">", "0", ":", "retlist", ".", "insert", "(", "0", ",", "tail", ")", "recurse_path", "(", "head", ",", "retlist", ")", "elif", "len", "(", "head", ")", ">", "1", ":", "recurse_path", "(", "head", ",", "retlist", ")", "else", ":", "return", "retlist", "=", "[", "]", "path", "=", "os", ".", "path", ".", "realpath", "(", "os", ".", "path", ".", "normpath", "(", "path", ")", ")", "drive", ",", "path", "=", "os", ".", "path", ".", "splitdrive", "(", "path", ")", "if", "len", "(", "drive", ")", ">", "0", ":", "retlist", ".", "append", "(", "drive", ")", "recurse_path", "(", "path", ",", "retlist", ")", "return", "retlist" ]
Splits the argument into its constituent directories and returns them as a list.
[ "Splits", "the", "argument", "into", "its", "constituent", "directories", "and", "returns", "them", "as", "a", "list", "." ]
d46a44eae20d99205292c31785f936fbed47070f
https://github.com/Fortran-FOSS-Programmers/ford/blob/d46a44eae20d99205292c31785f936fbed47070f/ford/utils.py#L143-L167
251,818
Fortran-FOSS-Programmers/ford
ford/utils.py
sub_macros
def sub_macros(string,base_url): ''' Replaces macros in documentation with their appropriate values. These macros are used for things like providing URLs. ''' macros = { '|url|': base_url, '|media|': os.path.join(base_url,'media'), '|page|': os.path.join(base_url,'page') } for key, val in macros.items(): string = string.replace(key,val) return string
python
def sub_macros(string,base_url): ''' Replaces macros in documentation with their appropriate values. These macros are used for things like providing URLs. ''' macros = { '|url|': base_url, '|media|': os.path.join(base_url,'media'), '|page|': os.path.join(base_url,'page') } for key, val in macros.items(): string = string.replace(key,val) return string
[ "def", "sub_macros", "(", "string", ",", "base_url", ")", ":", "macros", "=", "{", "'|url|'", ":", "base_url", ",", "'|media|'", ":", "os", ".", "path", ".", "join", "(", "base_url", ",", "'media'", ")", ",", "'|page|'", ":", "os", ".", "path", ".", "join", "(", "base_url", ",", "'page'", ")", "}", "for", "key", ",", "val", "in", "macros", ".", "items", "(", ")", ":", "string", "=", "string", ".", "replace", "(", "key", ",", "val", ")", "return", "string" ]
Replaces macros in documentation with their appropriate values. These macros are used for things like providing URLs.
[ "Replaces", "macros", "in", "documentation", "with", "their", "appropriate", "values", ".", "These", "macros", "are", "used", "for", "things", "like", "providing", "URLs", "." ]
d46a44eae20d99205292c31785f936fbed47070f
https://github.com/Fortran-FOSS-Programmers/ford/blob/d46a44eae20d99205292c31785f936fbed47070f/ford/utils.py#L279-L290
251,819
Fortran-FOSS-Programmers/ford
ford/output.py
copytree
def copytree(src, dst): """Replaces shutil.copytree to avoid problems on certain file systems. shutil.copytree() and shutil.copystat() invoke os.setxattr(), which seems to fail when called for directories on at least one NFS file system. The current routine is a simple replacement, which should be good enough for Ford. """ def touch(path): now = time.time() try: # assume it's there os.utime(path, (now, now)) except os.error: # if it isn't, try creating the directory, # a file with that name os.makedirs(os.path.dirname(path)) open(path, "w").close() os.utime(path, (now, now)) for root, dirs, files in os.walk(src): relsrcdir = os.path.relpath(root, src) dstdir = os.path.join(dst, relsrcdir) if not os.path.exists(dstdir): try: os.makedirs(dstdir) except OSError as ex: if ex.errno != errno.EEXIST: raise for ff in files: shutil.copy(os.path.join(root, ff), os.path.join(dstdir, ff)) touch(os.path.join(dstdir, ff))
python
def copytree(src, dst): def touch(path): now = time.time() try: # assume it's there os.utime(path, (now, now)) except os.error: # if it isn't, try creating the directory, # a file with that name os.makedirs(os.path.dirname(path)) open(path, "w").close() os.utime(path, (now, now)) for root, dirs, files in os.walk(src): relsrcdir = os.path.relpath(root, src) dstdir = os.path.join(dst, relsrcdir) if not os.path.exists(dstdir): try: os.makedirs(dstdir) except OSError as ex: if ex.errno != errno.EEXIST: raise for ff in files: shutil.copy(os.path.join(root, ff), os.path.join(dstdir, ff)) touch(os.path.join(dstdir, ff))
[ "def", "copytree", "(", "src", ",", "dst", ")", ":", "def", "touch", "(", "path", ")", ":", "now", "=", "time", ".", "time", "(", ")", "try", ":", "# assume it's there", "os", ".", "utime", "(", "path", ",", "(", "now", ",", "now", ")", ")", "except", "os", ".", "error", ":", "# if it isn't, try creating the directory,", "# a file with that name", "os", ".", "makedirs", "(", "os", ".", "path", ".", "dirname", "(", "path", ")", ")", "open", "(", "path", ",", "\"w\"", ")", ".", "close", "(", ")", "os", ".", "utime", "(", "path", ",", "(", "now", ",", "now", ")", ")", "for", "root", ",", "dirs", ",", "files", "in", "os", ".", "walk", "(", "src", ")", ":", "relsrcdir", "=", "os", ".", "path", ".", "relpath", "(", "root", ",", "src", ")", "dstdir", "=", "os", ".", "path", ".", "join", "(", "dst", ",", "relsrcdir", ")", "if", "not", "os", ".", "path", ".", "exists", "(", "dstdir", ")", ":", "try", ":", "os", ".", "makedirs", "(", "dstdir", ")", "except", "OSError", "as", "ex", ":", "if", "ex", ".", "errno", "!=", "errno", ".", "EEXIST", ":", "raise", "for", "ff", "in", "files", ":", "shutil", ".", "copy", "(", "os", ".", "path", ".", "join", "(", "root", ",", "ff", ")", ",", "os", ".", "path", ".", "join", "(", "dstdir", ",", "ff", ")", ")", "touch", "(", "os", ".", "path", ".", "join", "(", "dstdir", ",", "ff", ")", ")" ]
Replaces shutil.copytree to avoid problems on certain file systems. shutil.copytree() and shutil.copystat() invoke os.setxattr(), which seems to fail when called for directories on at least one NFS file system. The current routine is a simple replacement, which should be good enough for Ford.
[ "Replaces", "shutil", ".", "copytree", "to", "avoid", "problems", "on", "certain", "file", "systems", "." ]
d46a44eae20d99205292c31785f936fbed47070f
https://github.com/Fortran-FOSS-Programmers/ford/blob/d46a44eae20d99205292c31785f936fbed47070f/ford/output.py#L520-L551