def test_newer(self):
tmpdir = self.mkdtemp()
new_file = os.path.join(tmpdir, 'new')
old_file = os.path.abspath(__file__)
# Raise DistutilsFileError if 'new_file' does not exist.
self.assertRaises(DistutilsFileError, newer, new_file, old_file)
# Return true if 'new_file' exists and is more recently modified than
# 'old_file', or if 'new_file' exists and 'old_file' doesn't.
self.write_file(new_file)
self.assertTrue(newer(new_file, 'I_dont_exist'))
self.assertTrue(newer(new_file, old_file))
# Return false if both exist and 'old_file' is the same age or younger
# than 'new_file'.
self.assertFalse(newer(old_file, new_file))
python类newer()的实例源码
def BuildTypelib():
from distutils.dep_util import newer
this_dir = os.path.dirname(__file__)
idl = os.path.abspath(os.path.join(this_dir, "pippo.idl"))
tlb=os.path.splitext(idl)[0] + '.tlb'
if newer(idl, tlb):
print "Compiling %s" % (idl,)
rc = os.system ('midl "%s"' % (idl,))
if rc:
raise RuntimeError("Compiling MIDL failed!")
# Can't work out how to prevent MIDL from generating the stubs.
# just nuke them
for fname in "dlldata.c pippo_i.c pippo_p.c pippo.h".split():
os.remove(os.path.join(this_dir, fname))
print "Registering %s" % (tlb,)
tli=pythoncom.LoadTypeLib(tlb)
pythoncom.RegisterTypeLib(tli,tlb)
def BuildTypelib():
from distutils.dep_util import newer
this_dir = os.path.dirname(__file__)
idl = os.path.abspath(os.path.join(this_dir, "pippo.idl"))
tlb=os.path.splitext(idl)[0] + '.tlb'
if newer(idl, tlb):
print "Compiling %s" % (idl,)
rc = os.system ('midl "%s"' % (idl,))
if rc:
raise RuntimeError("Compiling MIDL failed!")
# Can't work out how to prevent MIDL from generating the stubs.
# just nuke them
for fname in "dlldata.c pippo_i.c pippo_p.c pippo.h".split():
os.remove(os.path.join(this_dir, fname))
print "Registering %s" % (tlb,)
tli=pythoncom.LoadTypeLib(tlb)
pythoncom.RegisterTypeLib(tli,tlb)
def test_newer(self):
tmpdir = self.mkdtemp()
new_file = os.path.join(tmpdir, 'new')
old_file = os.path.abspath(__file__)
# Raise DistutilsFileError if 'new_file' does not exist.
self.assertRaises(DistutilsFileError, newer, new_file, old_file)
# Return true if 'new_file' exists and is more recently modified than
# 'old_file', or if 'new_file' exists and 'old_file' doesn't.
self.write_file(new_file)
self.assertTrue(newer(new_file, 'I_dont_exist'))
self.assertTrue(newer(new_file, old_file))
# Return false if both exist and 'old_file' is the same age or younger
# than 'new_file'.
self.assertFalse(newer(old_file, new_file))
def test_newer(self):
tmpdir = self.mkdtemp()
new_file = os.path.join(tmpdir, 'new')
old_file = os.path.abspath(__file__)
# Raise DistutilsFileError if 'new_file' does not exist.
self.assertRaises(DistutilsFileError, newer, new_file, old_file)
# Return true if 'new_file' exists and is more recently modified than
# 'old_file', or if 'new_file' exists and 'old_file' doesn't.
self.write_file(new_file)
self.assertTrue(newer(new_file, 'I_dont_exist'))
self.assertTrue(newer(new_file, old_file))
# Return false if both exist and 'old_file' is the same age or younger
# than 'new_file'.
self.assertFalse(newer(old_file, new_file))
def test_newer(self):
tmpdir = self.mkdtemp()
new_file = os.path.join(tmpdir, 'new')
old_file = os.path.abspath(__file__)
# Raise DistutilsFileError if 'new_file' does not exist.
self.assertRaises(DistutilsFileError, newer, new_file, old_file)
# Return true if 'new_file' exists and is more recently modified than
# 'old_file', or if 'new_file' exists and 'old_file' doesn't.
self.write_file(new_file)
self.assertTrue(newer(new_file, 'I_dont_exist'))
self.assertTrue(newer(new_file, old_file))
# Return false if both exist and 'old_file' is the same age or younger
# than 'new_file'.
self.assertFalse(newer(old_file, new_file))
def BuildTypelib():
from distutils.dep_util import newer
this_dir = os.path.dirname(__file__)
idl = os.path.abspath(os.path.join(this_dir, "pippo.idl"))
tlb=os.path.splitext(idl)[0] + '.tlb'
if newer(idl, tlb):
print "Compiling %s" % (idl,)
rc = os.system ('midl "%s"' % (idl,))
if rc:
raise RuntimeError("Compiling MIDL failed!")
# Can't work out how to prevent MIDL from generating the stubs.
# just nuke them
for fname in "dlldata.c pippo_i.c pippo_p.c pippo.h".split():
os.remove(os.path.join(this_dir, fname))
print "Registering %s" % (tlb,)
tli=pythoncom.LoadTypeLib(tlb)
pythoncom.RegisterTypeLib(tli,tlb)
def BuildTypelib():
from distutils.dep_util import newer
this_dir = os.path.dirname(__file__)
idl = os.path.abspath(os.path.join(this_dir, "pippo.idl"))
tlb=os.path.splitext(idl)[0] + '.tlb'
if newer(idl, tlb):
print("Compiling %s" % (idl,))
rc = os.system ('midl "%s"' % (idl,))
if rc:
raise RuntimeError("Compiling MIDL failed!")
# Can't work out how to prevent MIDL from generating the stubs.
# just nuke them
for fname in "dlldata.c pippo_i.c pippo_p.c pippo.h".split():
os.remove(os.path.join(this_dir, fname))
print("Registering %s" % (tlb,))
tli=pythoncom.LoadTypeLib(tlb)
pythoncom.RegisterTypeLib(tli,tlb)
def test_newer(self):
tmpdir = self.mkdtemp()
new_file = os.path.join(tmpdir, 'new')
old_file = os.path.abspath(__file__)
# Raise DistutilsFileError if 'new_file' does not exist.
self.assertRaises(DistutilsFileError, newer, new_file, old_file)
# Return true if 'new_file' exists and is more recently modified than
# 'old_file', or if 'new_file' exists and 'old_file' doesn't.
self.write_file(new_file)
self.assertTrue(newer(new_file, 'I_dont_exist'))
self.assertTrue(newer(new_file, old_file))
# Return false if both exist and 'old_file' is the same age or younger
# than 'new_file'.
self.assertFalse(newer(old_file, new_file))
def test_newer(self):
tmpdir = self.mkdtemp()
new_file = os.path.join(tmpdir, 'new')
old_file = os.path.abspath(__file__)
# Raise DistutilsFileError if 'new_file' does not exist.
self.assertRaises(DistutilsFileError, newer, new_file, old_file)
# Return true if 'new_file' exists and is more recently modified than
# 'old_file', or if 'new_file' exists and 'old_file' doesn't.
self.write_file(new_file)
self.assertTrue(newer(new_file, 'I_dont_exist'))
self.assertTrue(newer(new_file, old_file))
# Return false if both exist and 'old_file' is the same age or younger
# than 'new_file'.
self.assertFalse(newer(old_file, new_file))
def preprocess(self, source, output_file=None, macros=None,
include_dirs=None, extra_preargs=None, extra_postargs=None):
fixed_args = self._fix_compile_args(None, macros, include_dirs)
ignore, macros, include_dirs = fixed_args
pp_opts = gen_preprocess_options(macros, include_dirs)
pp_args = self.preprocessor + pp_opts
if output_file:
pp_args.extend(['-o', output_file])
if extra_preargs:
pp_args[:0] = extra_preargs
if extra_postargs:
pp_args.extend(extra_postargs)
pp_args.append(source)
# We need to preprocess: either we're being forced to, or we're
# generating output to stdout, or there's a target output file and
# the source file is newer than the target (or the target doesn't
# exist).
if self.force or output_file is None or newer(source, output_file):
if output_file:
self.mkpath(os.path.dirname(output_file))
try:
self.spawn(pp_args)
except DistutilsExecError as msg:
raise CompileError(msg)
def test_newer(self):
tmpdir = self.mkdtemp()
new_file = os.path.join(tmpdir, 'new')
old_file = os.path.abspath(__file__)
# Raise DistutilsFileError if 'new_file' does not exist.
self.assertRaises(DistutilsFileError, newer, new_file, old_file)
# Return true if 'new_file' exists and is more recently modified than
# 'old_file', or if 'new_file' exists and 'old_file' doesn't.
self.write_file(new_file)
self.assertTrue(newer(new_file, 'I_dont_exist'))
self.assertTrue(newer(new_file, old_file))
# Return false if both exist and 'old_file' is the same age or younger
# than 'new_file'.
self.assertFalse(newer(old_file, new_file))
def test_newer(self):
tmpdir = self.mkdtemp()
new_file = os.path.join(tmpdir, 'new')
old_file = os.path.abspath(__file__)
# Raise DistutilsFileError if 'new_file' does not exist.
self.assertRaises(DistutilsFileError, newer, new_file, old_file)
# Return true if 'new_file' exists and is more recently modified than
# 'old_file', or if 'new_file' exists and 'old_file' doesn't.
self.write_file(new_file)
self.assertTrue(newer(new_file, 'I_dont_exist'))
self.assertTrue(newer(new_file, old_file))
# Return false if both exist and 'old_file' is the same age or younger
# than 'new_file'.
self.assertFalse(newer(old_file, new_file))
def preprocess(self, source, output_file=None, macros=None,
include_dirs=None, extra_preargs=None, extra_postargs=None):
fixed_args = self._fix_compile_args(None, macros, include_dirs)
ignore, macros, include_dirs = fixed_args
pp_opts = gen_preprocess_options(macros, include_dirs)
pp_args = self.preprocessor + pp_opts
if output_file:
pp_args.extend(['-o', output_file])
if extra_preargs:
pp_args[:0] = extra_preargs
if extra_postargs:
pp_args.extend(extra_postargs)
pp_args.append(source)
# We need to preprocess: either we're being forced to, or we're
# generating output to stdout, or there's a target output file and
# the source file is newer than the target (or the target doesn't
# exist).
if self.force or output_file is None or newer(source, output_file):
if output_file:
self.mkpath(os.path.dirname(output_file))
try:
self.spawn(pp_args)
except DistutilsExecError as msg:
raise CompileError(msg)
def preprocess (self,
source,
output_file=None,
macros=None,
include_dirs=None,
extra_preargs=None,
extra_postargs=None):
(_, macros, include_dirs) = \
self._fix_compile_args(None, macros, include_dirs)
pp_opts = gen_preprocess_options(macros, include_dirs)
pp_args = ['cpp32.exe'] + pp_opts
if output_file is not None:
pp_args.append('-o' + output_file)
if extra_preargs:
pp_args[:0] = extra_preargs
if extra_postargs:
pp_args.extend(extra_postargs)
pp_args.append(source)
# We need to preprocess: either we're being forced to, or the
# source file is newer than the target (or the target doesn't
# exist).
if self.force or output_file is None or newer(source, output_file):
if output_file:
self.mkpath(os.path.dirname(output_file))
try:
self.spawn(pp_args)
except DistutilsExecError, msg:
print msg
raise CompileError, msg
# preprocess()
def preprocess(self, source,
output_file=None, macros=None, include_dirs=None,
extra_preargs=None, extra_postargs=None):
ignore, macros, include_dirs = \
self._fix_compile_args(None, macros, include_dirs)
pp_opts = gen_preprocess_options(macros, include_dirs)
pp_args = self.preprocessor + pp_opts
if output_file:
pp_args.extend(['-o', output_file])
if extra_preargs:
pp_args[:0] = extra_preargs
if extra_postargs:
pp_args.extend(extra_postargs)
pp_args.append(source)
# We need to preprocess: either we're being forced to, or we're
# generating output to stdout, or there's a target output file and
# the source file is newer than the target (or the target doesn't
# exist).
if self.force or output_file is None or newer(source, output_file):
if output_file:
self.mkpath(os.path.dirname(output_file))
try:
self.spawn(pp_args)
except DistutilsExecError, msg:
raise CompileError, msg
def preprocess (self,
source,
output_file=None,
macros=None,
include_dirs=None,
extra_preargs=None,
extra_postargs=None):
(_, macros, include_dirs) = \
self._fix_compile_args(None, macros, include_dirs)
pp_opts = gen_preprocess_options(macros, include_dirs)
pp_args = ['cpp32.exe'] + pp_opts
if output_file is not None:
pp_args.append('-o' + output_file)
if extra_preargs:
pp_args[:0] = extra_preargs
if extra_postargs:
pp_args.extend(extra_postargs)
pp_args.append(source)
# We need to preprocess: either we're being forced to, or the
# source file is newer than the target (or the target doesn't
# exist).
if self.force or output_file is None or newer(source, output_file):
if output_file:
self.mkpath(os.path.dirname(output_file))
try:
self.spawn(pp_args)
except DistutilsExecError, msg:
print msg
raise CompileError, msg
# preprocess()
def test_newer_group(self):
tmpdir = self.mkdtemp()
sources = os.path.join(tmpdir, 'sources')
os.mkdir(sources)
one = os.path.join(sources, 'one')
two = os.path.join(sources, 'two')
three = os.path.join(sources, 'three')
old_file = os.path.abspath(__file__)
# return true if 'old_file' is out-of-date with respect to any file
# listed in 'sources'.
self.write_file(one)
self.write_file(two)
self.write_file(three)
self.assertTrue(newer_group([one, two, three], old_file))
self.assertFalse(newer_group([one, two, old_file], three))
# missing handling
os.remove(one)
self.assertRaises(OSError, newer_group, [one, two, old_file], three)
self.assertFalse(newer_group([one, two, old_file], three,
missing='ignore'))
self.assertTrue(newer_group([one, two, old_file], three,
missing='newer'))
def preprocess(self, source,
output_file=None, macros=None, include_dirs=None,
extra_preargs=None, extra_postargs=None):
ignore, macros, include_dirs = \
self._fix_compile_args(None, macros, include_dirs)
pp_opts = gen_preprocess_options(macros, include_dirs)
pp_args = self.preprocessor + pp_opts
if output_file:
pp_args.extend(['-o', output_file])
if extra_preargs:
pp_args[:0] = extra_preargs
if extra_postargs:
pp_args.extend(extra_postargs)
pp_args.append(source)
# We need to preprocess: either we're being forced to, or we're
# generating output to stdout, or there's a target output file and
# the source file is newer than the target (or the target doesn't
# exist).
if self.force or output_file is None or newer(source, output_file):
if output_file:
self.mkpath(os.path.dirname(output_file))
try:
self.spawn(pp_args)
except DistutilsExecError, msg:
raise CompileError, msg
def configuration(parent_package='', top_path=None):
config = Configuration('f2py', parent_package, top_path)
config.add_data_dir('tests')
config.add_data_files('src/fortranobject.c',
'src/fortranobject.h',
)
config.make_svn_version_py()
def generate_f2py_py(build_dir):
f2py_exe = 'f2py' + os.path.basename(sys.executable)[6:]
if f2py_exe[-4:] == '.exe':
f2py_exe = f2py_exe[:-4] + '.py'
if 'bdist_wininst' in sys.argv and f2py_exe[-3:] != '.py':
f2py_exe = f2py_exe + '.py'
target = os.path.join(build_dir, f2py_exe)
if newer(__file__, target):
log.info('Creating %s', target)
f = open(target, 'w')
f.write(_get_f2py_shebang() + '\n')
mainloc = os.path.join(os.path.dirname(__file__), "__main__.py")
with open(mainloc) as mf:
f.write(mf.read())
f.close()
return target
config.add_scripts(generate_f2py_py)
log.info('F2PY Version %s', config.get_version())
return config
def configuration(parent_package='', top_path=None):
config = Configuration('f2py', parent_package, top_path)
config.add_data_dir('tests')
config.add_data_files('src/fortranobject.c',
'src/fortranobject.h',
)
config.make_svn_version_py()
def generate_f2py_py(build_dir):
f2py_exe = 'f2py' + os.path.basename(sys.executable)[6:]
if f2py_exe[-4:] == '.exe':
f2py_exe = f2py_exe[:-4] + '.py'
if 'bdist_wininst' in sys.argv and f2py_exe[-3:] != '.py':
f2py_exe = f2py_exe + '.py'
target = os.path.join(build_dir, f2py_exe)
if newer(__file__, target):
log.info('Creating %s', target)
f = open(target, 'w')
f.write(_get_f2py_shebang() + '\n')
mainloc = os.path.join(os.path.dirname(__file__), "__main__.py")
with open(mainloc) as mf:
f.write(mf.read())
f.close()
return target
config.add_scripts(generate_f2py_py)
log.info('F2PY Version %s', config.get_version())
return config
def write_version():
if newer(VERSION_FILE, PY_VERSION_FILE):
with open(PY_VERSION_FILE, "w") as f:
f.write("# GENERATED BY setup.py\n")
f.write("version = '%s'\n" % (get_version_string()))
# On Darwin, UnixCCompiler uses "-L" for runtime lib paths
def preprocess (self,
source,
output_file=None,
macros=None,
include_dirs=None,
extra_preargs=None,
extra_postargs=None):
(_, macros, include_dirs) = \
self._fix_compile_args(None, macros, include_dirs)
pp_opts = gen_preprocess_options(macros, include_dirs)
pp_args = ['cpp32.exe'] + pp_opts
if output_file is not None:
pp_args.append('-o' + output_file)
if extra_preargs:
pp_args[:0] = extra_preargs
if extra_postargs:
pp_args.extend(extra_postargs)
pp_args.append(source)
# We need to preprocess: either we're being forced to, or the
# source file is newer than the target (or the target doesn't
# exist).
if self.force or output_file is None or newer(source, output_file):
if output_file:
self.mkpath(os.path.dirname(output_file))
try:
self.spawn(pp_args)
except DistutilsExecError, msg:
print msg
raise CompileError, msg
# preprocess()
def test_newer_group(self):
tmpdir = self.mkdtemp()
sources = os.path.join(tmpdir, 'sources')
os.mkdir(sources)
one = os.path.join(sources, 'one')
two = os.path.join(sources, 'two')
three = os.path.join(sources, 'three')
old_file = os.path.abspath(__file__)
# return true if 'old_file' is out-of-date with respect to any file
# listed in 'sources'.
self.write_file(one)
self.write_file(two)
self.write_file(three)
self.assertTrue(newer_group([one, two, three], old_file))
self.assertFalse(newer_group([one, two, old_file], three))
# missing handling
os.remove(one)
self.assertRaises(OSError, newer_group, [one, two, old_file], three)
self.assertFalse(newer_group([one, two, old_file], three,
missing='ignore'))
self.assertTrue(newer_group([one, two, old_file], three,
missing='newer'))
def preprocess(self, source,
output_file=None, macros=None, include_dirs=None,
extra_preargs=None, extra_postargs=None):
ignore, macros, include_dirs = \
self._fix_compile_args(None, macros, include_dirs)
pp_opts = gen_preprocess_options(macros, include_dirs)
pp_args = self.preprocessor + pp_opts
if output_file:
pp_args.extend(['-o', output_file])
if extra_preargs:
pp_args[:0] = extra_preargs
if extra_postargs:
pp_args.extend(extra_postargs)
pp_args.append(source)
# We need to preprocess: either we're being forced to, or we're
# generating output to stdout, or there's a target output file and
# the source file is newer than the target (or the target doesn't
# exist).
if self.force or output_file is None or newer(source, output_file):
if output_file:
self.mkpath(os.path.dirname(output_file))
try:
self.spawn(pp_args)
except DistutilsExecError, msg:
raise CompileError, msg
def preprocess (self,
source,
output_file=None,
macros=None,
include_dirs=None,
extra_preargs=None,
extra_postargs=None):
(_, macros, include_dirs) = \
self._fix_compile_args(None, macros, include_dirs)
pp_opts = gen_preprocess_options(macros, include_dirs)
pp_args = ['cpp32.exe'] + pp_opts
if output_file is not None:
pp_args.append('-o' + output_file)
if extra_preargs:
pp_args[:0] = extra_preargs
if extra_postargs:
pp_args.extend(extra_postargs)
pp_args.append(source)
# We need to preprocess: either we're being forced to, or the
# source file is newer than the target (or the target doesn't
# exist).
if self.force or output_file is None or newer(source, output_file):
if output_file:
self.mkpath(os.path.dirname(output_file))
try:
self.spawn(pp_args)
except DistutilsExecError, msg:
print msg
raise CompileError, msg
# preprocess()
def test_newer_group(self):
tmpdir = self.mkdtemp()
sources = os.path.join(tmpdir, 'sources')
os.mkdir(sources)
one = os.path.join(sources, 'one')
two = os.path.join(sources, 'two')
three = os.path.join(sources, 'three')
old_file = os.path.abspath(__file__)
# return true if 'old_file' is out-of-date with respect to any file
# listed in 'sources'.
self.write_file(one)
self.write_file(two)
self.write_file(three)
self.assertTrue(newer_group([one, two, three], old_file))
self.assertFalse(newer_group([one, two, old_file], three))
# missing handling
os.remove(one)
self.assertRaises(OSError, newer_group, [one, two, old_file], three)
self.assertFalse(newer_group([one, two, old_file], three,
missing='ignore'))
self.assertTrue(newer_group([one, two, old_file], three,
missing='newer'))
def preprocess(self, source,
output_file=None, macros=None, include_dirs=None,
extra_preargs=None, extra_postargs=None):
ignore, macros, include_dirs = \
self._fix_compile_args(None, macros, include_dirs)
pp_opts = gen_preprocess_options(macros, include_dirs)
pp_args = self.preprocessor + pp_opts
if output_file:
pp_args.extend(['-o', output_file])
if extra_preargs:
pp_args[:0] = extra_preargs
if extra_postargs:
pp_args.extend(extra_postargs)
pp_args.append(source)
# We need to preprocess: either we're being forced to, or we're
# generating output to stdout, or there's a target output file and
# the source file is newer than the target (or the target doesn't
# exist).
if self.force or output_file is None or newer(source, output_file):
if output_file:
self.mkpath(os.path.dirname(output_file))
try:
self.spawn(pp_args)
except DistutilsExecError, msg:
raise CompileError, msg
def preprocess (self,
source,
output_file=None,
macros=None,
include_dirs=None,
extra_preargs=None,
extra_postargs=None):
(_, macros, include_dirs) = \
self._fix_compile_args(None, macros, include_dirs)
pp_opts = gen_preprocess_options(macros, include_dirs)
pp_args = ['cpp32.exe'] + pp_opts
if output_file is not None:
pp_args.append('-o' + output_file)
if extra_preargs:
pp_args[:0] = extra_preargs
if extra_postargs:
pp_args.extend(extra_postargs)
pp_args.append(source)
# We need to preprocess: either we're being forced to, or the
# source file is newer than the target (or the target doesn't
# exist).
if self.force or output_file is None or newer(source, output_file):
if output_file:
self.mkpath(os.path.dirname(output_file))
try:
self.spawn(pp_args)
except DistutilsExecError, msg:
print msg
raise CompileError, msg
# preprocess()
def test_newer_group(self):
tmpdir = self.mkdtemp()
sources = os.path.join(tmpdir, 'sources')
os.mkdir(sources)
one = os.path.join(sources, 'one')
two = os.path.join(sources, 'two')
three = os.path.join(sources, 'three')
old_file = os.path.abspath(__file__)
# return true if 'old_file' is out-of-date with respect to any file
# listed in 'sources'.
self.write_file(one)
self.write_file(two)
self.write_file(three)
self.assertTrue(newer_group([one, two, three], old_file))
self.assertFalse(newer_group([one, two, old_file], three))
# missing handling
os.remove(one)
self.assertRaises(OSError, newer_group, [one, two, old_file], three)
self.assertFalse(newer_group([one, two, old_file], three,
missing='ignore'))
self.assertTrue(newer_group([one, two, old_file], three,
missing='newer'))