From b38e47f413c6651c8953d2bebd99ae0bb80c07f9 Mon Sep 17 00:00:00 2001 From: Richard Maw Date: Fri, 22 Nov 2013 13:44:15 +0000 Subject: sysbranchdir: Move load_all_morphologies helper here This was previously a private method of the branch and merge plugin, but it's useful to other plugins, so has been moved to the SystemBranchDirectory class, where everything else can get to it. It has an unpleasant amount of coupling to other classes, but in a *good* object oriented design it would either be a tiny module on its own, or not exist and leave all its users to re-implement the same logic multiple ways, so we've opted for a less clean, but more useful design. It is left un-covered by the unit tests, since it requires a great deal of instrumentation to test, at which point it may be best to leave it to integration tests. --- morphlib/plugins/branch_and_merge_new_plugin.py | 11 ++--------- morphlib/sysbranchdir.py | 14 ++++++++++++++ morphlib/util.py | 1 - 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/morphlib/plugins/branch_and_merge_new_plugin.py b/morphlib/plugins/branch_and_merge_new_plugin.py index 8ad9effd..3a3c1d1b 100644 --- a/morphlib/plugins/branch_and_merge_new_plugin.py +++ b/morphlib/plugins/branch_and_merge_new_plugin.py @@ -615,15 +615,8 @@ class SimpleBranchAndMergePlugin(cliapp.Plugin): '''Read in all the morphologies in the root repository.''' self.app.status(msg='Loading in all morphologies') morphs = morphlib.morphset.MorphologySet() - mf = morphlib.morphologyfinder.MorphologyFinder( - morphlib.gitdir.GitDirectory( - sb.get_git_directory_name(sb.root_repository_url))) - for morph in mf.list_morphologies(): - text, filename = mf.read_morphology(morph) - m = loader.load_from_string(text, filename=filename) - m.repo_url = sb.root_repository_url - m.ref = sb.system_branch_name - morphs.add_morphology(m) + for morph in sb.load_all_morphologies(loader): + morphs.add_morphology(morph) return morphs def petrify(self, args): diff --git a/morphlib/sysbranchdir.py b/morphlib/sysbranchdir.py index 73a07d5e..1a8b898a 100644 --- a/morphlib/sysbranchdir.py +++ b/morphlib/sysbranchdir.py @@ -161,6 +161,20 @@ class SystemBranchDirectory(object): for dirname in morphlib.util.find_leaves(self.root_directory, '.git')) + # Not covered by unit tests, since testing the functionality spans + # multiple modules and only tests useful output with a full system + # branch, so it is instead covered by integration tests. + def load_all_morphologies(self, loader): # pragma: no cover + gd_name = self.get_git_directory_name(self.root_repository_url) + gd = morphlib.gitdir.GitDirectory(gd_name) + mf = morphlib.morphologyfinder.MorphologyFinder(gd) + for morph in mf.list_morphologies(): + text, filename = mf.read_morphology(morph) + m = loader.load_from_string(text, filename=filename) + m.repo_url = self.root_repository_url + m.ref = self.system_branch_name + yield m + def create(root_directory, root_repository_url, system_branch_name): '''Create a new system branch directory on disk. diff --git a/morphlib/util.py b/morphlib/util.py index 7382e40c..16e56366 100644 --- a/morphlib/util.py +++ b/morphlib/util.py @@ -18,7 +18,6 @@ import os import re import morphlib -import logging '''Utility functions for morph.''' -- cgit v1.2.1