From 3525f81ecea60f53d3ef842c1e11c4cab1538511 Mon Sep 17 00:00:00 2001 From: Sam Thursfield Date: Fri, 24 Aug 2012 18:05:16 +0100 Subject: Refactor build system code for easier testing --- morphlib/buildsystem.py | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'morphlib/buildsystem.py') 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 -- cgit v1.2.1