diff options
| author | Tarek Ziad? <tarek@ziade.org> | 2010-02-22 18:06:26 -0500 |
|---|---|---|
| committer | Tarek Ziad? <tarek@ziade.org> | 2010-02-22 18:06:26 -0500 |
| commit | 7783b45b2e45dd5d227a24949352ccf82f75ecc8 (patch) | |
| tree | 6d66236afff55f5d7b785cbbe0199176d70b1986 /src | |
| parent | a27379fa66a5a7695e9849146403a8c767126544 (diff) | |
| download | disutils2-7783b45b2e45dd5d227a24949352ccf82f75ecc8.tar.gz | |
removed dep_util
Diffstat (limited to 'src')
| -rw-r--r-- | src/distutils2/cmd.py | 2 | ||||
| -rw-r--r-- | src/distutils2/command/build_ext.py | 2 | ||||
| -rw-r--r-- | src/distutils2/command/build_scripts.py | 3 | ||||
| -rw-r--r-- | src/distutils2/command/sdist.py | 10 | ||||
| -rw-r--r-- | src/distutils2/compiler/__init__.py | 2 | ||||
| -rw-r--r-- | src/distutils2/compiler/ccompiler.py | 7 | ||||
| -rw-r--r-- | src/distutils2/compiler/unixccompiler.py | 2 | ||||
| -rw-r--r-- | src/distutils2/dep_util.py | 88 | ||||
| -rw-r--r-- | src/distutils2/file_util.py | 2 | ||||
| -rw-r--r-- | src/distutils2/tests/test_dep_util.py | 80 | ||||
| -rw-r--r-- | src/distutils2/util.py | 61 |
11 files changed, 75 insertions, 184 deletions
diff --git a/src/distutils2/cmd.py b/src/distutils2/cmd.py index 7fc09b6..4bcba4b 100644 --- a/src/distutils2/cmd.py +++ b/src/distutils2/cmd.py @@ -8,7 +8,7 @@ __revision__ = "$Id: cmd.py 75192 2009-10-02 23:49:48Z tarek.ziade $" import sys, os, re from distutils2.errors import DistutilsOptionError -from distutils2 import util, file_util, dep_util +from distutils2 import util, file_util from distutils2 import log # XXX see if we want to backport this diff --git a/src/distutils2/command/build_ext.py b/src/distutils2/command/build_ext.py index 126c6f8..ae11330 100644 --- a/src/distutils2/command/build_ext.py +++ b/src/distutils2/command/build_ext.py @@ -13,7 +13,7 @@ from distutils2.util import get_platform from distutils2.core import Command from distutils2.errors import * from distutils2.compiler.ccompiler import customize_compiler -from distutils2.dep_util import newer_group +from distutils2.util import newer_group from distutils2.extension import Extension from distutils2 import log try: diff --git a/src/distutils2/command/build_scripts.py b/src/distutils2/command/build_scripts.py index 7a95827..ad1c234 100644 --- a/src/distutils2/command/build_scripts.py +++ b/src/distutils2/command/build_scripts.py @@ -7,8 +7,7 @@ __revision__ = "$Id: build_scripts.py 77704 2010-01-23 09:23:15Z tarek.ziade $" import os, re from stat import ST_MODE from distutils2.core import Command -from distutils2.dep_util import newer -from distutils2.util import convert_path +from distutils2.util import convert_path, newer from distutils2 import log try: import sysconfig diff --git a/src/distutils2/command/sdist.py b/src/distutils2/command/sdist.py index 31a8ae6..9a3ee7f 100644 --- a/src/distutils2/command/sdist.py +++ b/src/distutils2/command/sdist.py @@ -16,13 +16,13 @@ except ImportError: from distutils2._backport.shutil import get_archive_formats from distutils2.core import Command -from distutils2 import dep_util, file_util +from distutils2 import file_util from distutils2.text_file import TextFile from distutils2.errors import (DistutilsPlatformError, DistutilsOptionError, DistutilsTemplateError) from distutils2.filelist import FileList from distutils2 import log -from distutils2.util import convert_path +from distutils2.util import convert_path, newer def show_formats(): """Print all possible values for the 'formats' option (used by @@ -195,7 +195,7 @@ class sdist(Command): # manifest; if so, we'll regenerate the manifest. template_exists = os.path.isfile(self.template) if template_exists: - template_newer = dep_util.newer(self.template, self.manifest) + template_newer = newer(self.template, self.manifest) # The contents of the manifest file almost certainly depend on the # setup script as well as the manifest template -- so if the setup @@ -206,8 +206,8 @@ class sdist(Command): # can't regenerate the manifest, so we don't.) self.debug_print("checking if %s newer than %s" % (self.distribution.script_name, self.manifest)) - setup_newer = dep_util.newer(self.distribution.script_name, - self.manifest) + setup_newer = newer(self.distribution.script_name, + self.manifest) # cases: # 1) no manifest, template exists: generate manifest diff --git a/src/distutils2/compiler/__init__.py b/src/distutils2/compiler/__init__.py index e69de29..139597f 100644 --- a/src/distutils2/compiler/__init__.py +++ b/src/distutils2/compiler/__init__.py @@ -0,0 +1,2 @@ + + diff --git a/src/distutils2/compiler/ccompiler.py b/src/distutils2/compiler/ccompiler.py index 7e6e662..ecf11e3 100644 --- a/src/distutils2/compiler/ccompiler.py +++ b/src/distutils2/compiler/ccompiler.py @@ -13,8 +13,7 @@ from distutils2.errors import (CompileError, LinkError, UnknownFileError, DistutilsPlatformError, DistutilsModuleError) from distutils2.spawn import spawn from distutils2.file_util import move_file -from distutils2.dep_util import newer_group -from distutils2.util import split_quoted, execute +from distutils2.util import split_quoted, execute, newer_group from distutils2 import log try: @@ -523,9 +522,9 @@ class CCompiler: return 1 else: if self.dry_run: - newer = newer_group (objects, output_file, missing='newer') + newer = newer_group(objects, output_file, missing='newer') else: - newer = newer_group (objects, output_file) + newer = newer_group(objects, output_file) return newer def detect_language(self, sources): diff --git a/src/distutils2/compiler/unixccompiler.py b/src/distutils2/compiler/unixccompiler.py index bcf336e..18276f7 100644 --- a/src/distutils2/compiler/unixccompiler.py +++ b/src/distutils2/compiler/unixccompiler.py @@ -18,7 +18,7 @@ __revision__ = "$Id: unixccompiler.py 77704 2010-01-23 09:23:15Z tarek.ziade $" import os, sys from types import StringType, NoneType -from distutils2.dep_util import newer +from distutils2.util import newer from distutils2.compiler.ccompiler import \ CCompiler, gen_preprocess_options, gen_lib_options from distutils2.errors import \ diff --git a/src/distutils2/dep_util.py b/src/distutils2/dep_util.py deleted file mode 100644 index a1667f8..0000000 --- a/src/distutils2/dep_util.py +++ /dev/null @@ -1,88 +0,0 @@ -"""distutils.dep_util - -Utility functions for simple, timestamp-based dependency of files -and groups of files; also, function based entirely on such -timestamp dependency analysis.""" - -__revision__ = "$Id: dep_util.py 76746 2009-12-10 15:29:03Z tarek.ziade $" - -import os -from distutils2.errors import DistutilsFileError - -def newer(source, target): - """Tells if the target is newer than the source. - - Return true if 'source' exists and is more recently modified than - 'target', or if 'source' exists and 'target' doesn't. - - Return false if both exist and 'target' is the same age or younger - than 'source'. Raise DistutilsFileError if 'source' does not exist. - - Note that this test is not very accurate: files created in the same second - will have the same "age". - """ - if not os.path.exists(source): - raise DistutilsFileError("file '%s' does not exist" % - os.path.abspath(source)) - if not os.path.exists(target): - return True - - return os.stat(source).st_mtime > os.stat(target).st_mtime - -def newer_pairwise(sources, targets): - """Walk two filename lists in parallel, testing if each source is newer - than its corresponding target. Return a pair of lists (sources, - targets) where source is newer than target, according to the semantics - of 'newer()'. - """ - if len(sources) != len(targets): - raise ValueError, "'sources' and 'targets' must be same length" - - # build a pair of lists (sources, targets) where source is newer - n_sources = [] - n_targets = [] - for source, target in zip(sources, targets): - if newer(source, target): - n_sources.append(source) - n_targets.append(target) - - return n_sources, n_targets - -def newer_group(sources, target, missing='error'): - """Return true if 'target' is out-of-date with respect to any file - listed in 'sources'. - - In other words, if 'target' exists and is newer - than every file in 'sources', return false; otherwise return true. - 'missing' controls what we do when a source file is missing; the - default ("error") is to blow up with an OSError from inside 'stat()'; - if it is "ignore", we silently drop any missing source files; if it is - "newer", any missing source files make us assume that 'target' is - out-of-date (this is handy in "dry-run" mode: it'll make you pretend to - carry out commands that wouldn't work because inputs are missing, but - that doesn't matter because you're not actually going to run the - commands). - """ - # If the target doesn't even exist, then it's definitely out-of-date. - if not os.path.exists(target): - return True - - # Otherwise we have to find out the hard way: if *any* source file - # is more recent than 'target', then 'target' is out-of-date and - # we can immediately return true. If we fall through to the end - # of the loop, then 'target' is up-to-date and we return false. - target_mtime = os.stat(target).st_mtime - - for source in sources: - if not os.path.exists(source): - if missing == 'error': # blow up when we stat() the file - pass - elif missing == 'ignore': # missing source dropped from - continue # target's dependency list - elif missing == 'newer': # missing source means target is - return True # out-of-date - - if os.stat(source).st_mtime > target_mtime: - return True - - return False diff --git a/src/distutils2/file_util.py b/src/distutils2/file_util.py index 83b5606..54c96f3 100644 --- a/src/distutils2/file_util.py +++ b/src/distutils2/file_util.py @@ -101,7 +101,7 @@ def copy_file(src, dst, preserve_mode=1, preserve_times=1, update=0, # changing it (ie. it's not already a hard/soft link to src OR # (not update) and (src newer than dst). - from distutils2.dep_util import newer + from distutils2.util import newer from stat import ST_ATIME, ST_MTIME, ST_MODE, S_IMODE if not os.path.isfile(src): diff --git a/src/distutils2/tests/test_dep_util.py b/src/distutils2/tests/test_dep_util.py deleted file mode 100644 index 366ee55..0000000 --- a/src/distutils2/tests/test_dep_util.py +++ /dev/null @@ -1,80 +0,0 @@ -"""Tests for distutils.dep_util.""" -import unittest2 -import os -import time - -from distutils2.dep_util import newer, newer_pairwise, newer_group -from distutils2.errors import DistutilsFileError -from distutils2.tests import support - -class DepUtilTestCase(support.TempdirManager, unittest2.TestCase): - - 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_pairwise(self): - tmpdir = self.mkdtemp() - sources = os.path.join(tmpdir, 'sources') - targets = os.path.join(tmpdir, 'targets') - os.mkdir(sources) - os.mkdir(targets) - one = os.path.join(sources, 'one') - two = os.path.join(sources, 'two') - three = os.path.abspath(__file__) # I am the old file - four = os.path.join(targets, 'four') - self.write_file(one) - self.write_file(two) - self.write_file(four) - - self.assertEquals(newer_pairwise([one, two], [three, four]), - ([one],[three])) - - 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 test_suite(): - return unittest2.makeSuite(DepUtilTestCase) - -if __name__ == "__main__": - unittest2.main(defaultTest="test_suite") diff --git a/src/distutils2/util.py b/src/distutils2/util.py index 0faa008..adeb802 100644 --- a/src/distutils2/util.py +++ b/src/distutils2/util.py @@ -9,7 +9,6 @@ __revision__ = "$Id: util.py 77761 2010-01-26 22:46:15Z tarek.ziade $" import sys, os, string, re from distutils2.errors import DistutilsPlatformError -from distutils2.dep_util import newer from distutils2.spawn import spawn, find_executable from distutils2 import log from distutils2.version import LooseVersion @@ -22,6 +21,26 @@ except ImportError: _PLATFORM = None +def newer(source, target): + """Tells if the target is newer than the source. + + Return true if 'source' exists and is more recently modified than + 'target', or if 'source' exists and 'target' doesn't. + + Return false if both exist and 'target' is the same age or younger + than 'source'. Raise DistutilsFileError if 'source' does not exist. + + Note that this test is not very accurate: files created in the same second + will have the same "age". + """ + if not os.path.exists(source): + raise DistutilsFileError("file '%s' does not exist" % + os.path.abspath(source)) + if not os.path.exists(target): + return True + + return os.stat(source).st_mtime > os.stat(target).st_mtime + def get_platform(): """Return a string that identifies the current platform. @@ -480,3 +499,43 @@ def get_compiler_versions(): ld = _find_ld_version() dllwrap = _find_exe_version('dllwrap --version') return gcc, ld, dllwrap + +def newer_group(sources, target, missing='error'): + """Return true if 'target' is out-of-date with respect to any file + listed in 'sources'. + + In other words, if 'target' exists and is newer + than every file in 'sources', return false; otherwise return true. + 'missing' controls what we do when a source file is missing; the + default ("error") is to blow up with an OSError from inside 'stat()'; + if it is "ignore", we silently drop any missing source files; if it is + "newer", any missing source files make us assume that 'target' is + out-of-date (this is handy in "dry-run" mode: it'll make you pretend to + carry out commands that wouldn't work because inputs are missing, but + that doesn't matter because you're not actually going to run the + commands). + """ + # If the target doesn't even exist, then it's definitely out-of-date. + if not os.path.exists(target): + return True + + # Otherwise we have to find out the hard way: if *any* source file + # is more recent than 'target', then 'target' is out-of-date and + # we can immediately return true. If we fall through to the end + # of the loop, then 'target' is up-to-date and we return false. + target_mtime = os.stat(target).st_mtime + + for source in sources: + if not os.path.exists(source): + if missing == 'error': # blow up when we stat() the file + pass + elif missing == 'ignore': # missing source dropped from + continue # target's dependency list + elif missing == 'newer': # missing source means target is + return True # out-of-date + + if os.stat(source).st_mtime > target_mtime: + return True + + return False + |
