MCPcopy Create free account
hub / github.com/numpy/numpy / _needs_build

Function _needs_build

numpy/distutils/ccompiler.py:39–86  ·  view source on GitHub ↗

Check if an objects needs to be rebuild based on its dependencies Parameters ---------- obj : str object file Returns ------- bool

(obj, cc_args, extra_postargs, pp_opts)

Source from the content-addressed store, hash-verified

37
38
39def _needs_build(obj, cc_args, extra_postargs, pp_opts):
40 """
41 Check if an objects needs to be rebuild based on its dependencies
42
43 Parameters
44 ----------
45 obj : str
46 object file
47
48 Returns
49 -------
50 bool
51 """
52 # defined in unixcompiler.py
53 dep_file = obj + '.d'
54 if not os.path.exists(dep_file):
55 return True
56
57 # dep_file is a makefile containing 'object: dependencies'
58 # formatted like posix shell (spaces escaped, \ line continuations)
59 # the last line contains the compiler commandline arguments as some
60 # projects may compile an extension multiple times with different
61 # arguments
62 with open(dep_file) as f:
63 lines = f.readlines()
64
65 cmdline =_commandline_dep_string(cc_args, extra_postargs, pp_opts)
66 last_cmdline = lines[-1]
67 if last_cmdline != cmdline:
68 return True
69
70 contents = ''.join(lines[:-1])
71 deps = [x for x in shlex.split(contents, posix=True)
72 if x != "\n" and not x.endswith(":")]
73
74 try:
75 t_obj = os.stat(obj).st_mtime
76
77 # check if any of the dependencies is newer than the object
78 # the dependencies includes the source used to create the object
79 for f in deps:
80 if os.stat(f).st_mtime > t_obj:
81 return True
82 except OSError:
83 # no object counts as newer (shouldn't happen if dep_file exists)
84 return True
85
86 return False
87
88
89def replace_method(klass, method_name, func):

Callers 1

single_compileFunction · 0.85

Calls 6

_commandline_dep_stringFunction · 0.90
openFunction · 0.85
endswithMethod · 0.80
existsMethod · 0.45
joinMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected