summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Thursfield <sam.thursfield@codethink.co.uk>2012-08-24 18:05:16 +0100
committerSam Thursfield <sam.thursfield@codethink.co.uk>2012-08-24 18:05:16 +0100
commit3525f81ecea60f53d3ef842c1e11c4cab1538511 (patch)
treeea49c69e6baa1a000c78b3156eb5965c72ed68fd
parent98b802e36b2a291b39dbdb83b55546b1acae1573 (diff)
downloadmorph-3525f81ecea60f53d3ef842c1e11c4cab1538511.tar.gz
Refactor build system code for easier testing
-rw-r--r--morphlib/buildsystem.py23
-rw-r--r--morphlib/buildsystem_tests.py24
2 files changed, 16 insertions, 31 deletions
diff --git a/morphlib/buildsystem.py b/morphlib/buildsystem.py
index 86eac850..6287063a 100644
--- a/morphlib/buildsystem.py
+++ b/morphlib/buildsystem.py
@@ -55,7 +55,7 @@ class BuildSystem(object):
'bs': self.name,
}
- def used_by_project(self, exists):
+ def used_by_project(self, file_list):
'''Does a project use this build system?
``exists`` is a function that returns a boolean telling if a
@@ -71,7 +71,7 @@ class ManualBuildSystem(BuildSystem):
name = 'manual'
- def used_by_project(self, exists):
+ def used_by_project(self, file_list):
return False
@@ -87,7 +87,7 @@ class DummyBuildSystem(BuildSystem):
self.test_commands = ['echo dummy test']
self.install_commands = ['echo dummy install']
- def used_by_project(self, exists):
+ def used_by_project(self, file_list):
return False
@@ -114,7 +114,7 @@ class AutotoolsBuildSystem(BuildSystem):
'make DESTDIR="$DESTDIR" install',
]
- def used_by_project(self, exists):
+ def used_by_project(self, file_list):
indicators = [
'autogen',
'autogen.sh',
@@ -124,7 +124,7 @@ class AutotoolsBuildSystem(BuildSystem):
'configure.in.in',
]
- return any(exists(x) for x in indicators)
+ return any(x in file_list for x in indicators)
class PythonDistutilsBuildSystem(BuildSystem):
@@ -145,12 +145,12 @@ class PythonDistutilsBuildSystem(BuildSystem):
'python setup.py install --prefix "$PREFIX" --root "$DESTDIR"',
]
- def used_by_project(self, exists):
+ def used_by_project(self, file_list):
indicators = [
'setup.py',
]
- return any(exists(x) for x in indicators)
+ return any(x in file_list for x in indicators)
class CPANBuildSystem(BuildSystem):
@@ -178,12 +178,12 @@ class CPANBuildSystem(BuildSystem):
'make DESTDIR="$DESTDIR" install',
]
- def used_by_project(self, exists):
+ def used_by_project(self, file_list):
indicators = [
'Makefile.PL',
]
- return any(exists(x) for x in indicators)
+ return any(x in file_list for x in indicators)
build_systems = [
@@ -202,11 +202,8 @@ def detect_build_system(file_list):
For ``exists`` see the ``BuildSystem.exists`` method.
'''
- def exists(filename):
- return filename in file_list
-
for bs in build_systems:
- if bs.used_by_project(exists):
+ if bs.used_by_project(file_list):
return bs
return None
diff --git a/morphlib/buildsystem_tests.py b/morphlib/buildsystem_tests.py
index 53b4fc17..fa7f36f7 100644
--- a/morphlib/buildsystem_tests.py
+++ b/morphlib/buildsystem_tests.py
@@ -59,14 +59,10 @@ class ManualBuildSystemTests(unittest.TestCase):
self.bs = morphlib.buildsystem.ManualBuildSystem()
def test_does_not_autodetect_empty(self):
- def exists(filename):
- return filename in manual_project
- self.assertFalse(self.bs.used_by_project(exists))
+ self.assertFalse(self.bs.used_by_project(manual_project))
def test_does_not_autodetect_autotools(self):
- def exists(filename):
- return filename in autotools_project
- self.assertFalse(self.bs.used_by_project(exists))
+ self.assertFalse(self.bs.used_by_project(autotools_project))
class DummyBuildSystemTests(unittest.TestCase):
@@ -75,14 +71,10 @@ class DummyBuildSystemTests(unittest.TestCase):
self.bs = morphlib.buildsystem.DummyBuildSystem()
def test_does_not_autodetect_empty(self):
- def exists(filename):
- return filename in manual_project
- self.assertFalse(self.bs.used_by_project(exists))
+ self.assertFalse(self.bs.used_by_project(manual_project))
def test_does_not_autodetect_autotools(self):
- def exists(filename):
- return filename in autotools_project
- self.assertFalse(self.bs.used_by_project(exists))
+ self.assertFalse(self.bs.used_by_project(autotools_project))
class AutotoolsBuildSystemTests(unittest.TestCase):
@@ -91,14 +83,10 @@ class AutotoolsBuildSystemTests(unittest.TestCase):
self.bs = morphlib.buildsystem.AutotoolsBuildSystem()
def test_does_not_autodetect_empty(self):
- def exists(filename):
- return filename in manual_project
- self.assertFalse(self.bs.used_by_project(exists))
+ self.assertFalse(self.bs.used_by_project(manual_project))
def test_autodetects_autotools(self):
- def exists(filename):
- return filename in autotools_project
- self.assertTrue(self.bs.used_by_project(exists))
+ self.assertTrue(self.bs.used_by_project(autotools_project))
class DetectBuildSystemTests(unittest.TestCase):