summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2014-07-07 13:12:00 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2014-07-07 13:12:00 +0000
commitdc16450fa37c715a81b61213ade807734b404914 (patch)
tree3bdbf24e5503a620c4d0224fe5d07ec28392acae
parent09b6d77a5eea0594965b27d1697fa2fed2ec3b39 (diff)
downloadmorph-dc16450fa37c715a81b61213ade807734b404914.tar.gz
Make MorphologyFinder use file paths
We want to use file paths to locate morphologies now, so the old model of get a list of names and hand it those back to get the contents doesn't really make sense any more. This abstraction initially came about as one idea I had for moving morphologies out of the source tree was to put them in something like git notes, where it's possible to look up information for one commit in another ref in the repository, at which point this abstraction would have been flexible enough to handle that as well as in the However, moving the chunk morphologies into the definitions repository has other benefits too, so it makes more sense to be honest about using filenames in the API. It remains as a single point where we can put the logic for knowing which files in a repository look like morphologies, but if we need to remove any further functionality, it should be replaced by a single function.
-rw-r--r--morphlib/morphologyfinder.py21
-rw-r--r--morphlib/morphologyfinder_tests.py16
-rw-r--r--morphlib/plugins/deploy_plugin.py5
-rw-r--r--morphlib/sysbranchdir.py4
4 files changed, 18 insertions, 28 deletions
diff --git a/morphlib/morphologyfinder.py b/morphlib/morphologyfinder.py
index affa0e97..87c0de1a 100644
--- a/morphlib/morphologyfinder.py
+++ b/morphlib/morphologyfinder.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2013 Codethink Limited
+# Copyright (C) 2013-2014 Codethink Limited
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -34,38 +34,29 @@ class MorphologyFinder(object):
self.gitdir = gitdir
self.ref = ref
- def read_morphology(self, name):
+ def read_morphology(self, filename):
'''Return the un-parsed text of a morphology.
For the given morphology name, locate and return the contents
of the morphology as a string.
- Also returns a string describing where in the repository the
- morphology is located.
-
Parsing of this morphology into a form useful for manipulating
is handled by the MorphologyLoader class.
'''
- filename = '%s.morph' % name
- return self.gitdir.read_file(filename, self.ref), filename
+ return self.gitdir.read_file(filename, self.ref)
def list_morphologies(self):
- '''Return the names of all morphologies in the (repo, ref).
+ '''Return the filenames of all morphologies in the (repo, ref).
Finds all morphologies in the git directory at the specified
- ref. Morphology names are returned instead of filenames,
- so the implementation may change how morphologies are stored
- in git repositories.
+ ref.
'''
def is_morphology_path(path):
return path.endswith('.morph')
- def transform_path_to_name(path):
- return path[:-len('.morph')]
-
- return (transform_path_to_name(path)
+ return (path
for path in self.gitdir.list_files(self.ref)
if is_morphology_path(path))
diff --git a/morphlib/morphologyfinder_tests.py b/morphlib/morphologyfinder_tests.py
index ff83ccff..b07b2613 100644
--- a/morphlib/morphologyfinder_tests.py
+++ b/morphlib/morphologyfinder_tests.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2013 Codethink Limited
+# Copyright (C) 2013-2014 Codethink Limited
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -54,13 +54,13 @@ class MorphologyFinderTests(unittest.TestCase):
gd = morphlib.gitdir.GitDirectory(self.dirname)
mf = morphlib.morphologyfinder.MorphologyFinder(gd, 'HEAD')
self.assertEqual(sorted(mf.list_morphologies()),
- ['bar', 'baz'])
+ ['bar.morph', 'baz.morph'])
def test_list_morphs_in_master(self):
gd = morphlib.gitdir.GitDirectory(self.dirname)
mf = morphlib.morphologyfinder.MorphologyFinder(gd, 'master')
self.assertEqual(sorted(mf.list_morphologies()),
- ['bar', 'baz'])
+ ['bar.morph', 'baz.morph'])
def test_list_morphs_raises_with_invalid_ref(self):
gd = morphlib.gitdir.GitDirectory(self.dirname)
@@ -72,7 +72,7 @@ class MorphologyFinderTests(unittest.TestCase):
gd = morphlib.gitdir.GitDirectory(self.dirname)
mf = morphlib.morphologyfinder.MorphologyFinder(gd)
self.assertEqual(sorted(mf.list_morphologies()),
- ['bar', 'baz', 'foo'])
+ ['bar.morph', 'baz.morph', 'foo.morph'])
def test_list_morphs_raises_no_worktree_no_ref(self):
gd = morphlib.gitdir.GitDirectory(self.mirror)
@@ -83,13 +83,13 @@ class MorphologyFinderTests(unittest.TestCase):
def test_read_morph_in_HEAD(self):
gd = morphlib.gitdir.GitDirectory(self.dirname)
mf = morphlib.morphologyfinder.MorphologyFinder(gd, 'HEAD')
- self.assertEqual(mf.read_morphology('bar')[0],
+ self.assertEqual(mf.read_morphology('bar.morph'),
"dummy morphology text")
def test_read_morph_in_master(self):
gd = morphlib.gitdir.GitDirectory(self.dirname)
mf = morphlib.morphologyfinder.MorphologyFinder(gd, 'master')
- self.assertEqual(mf.read_morphology('bar')[0],
+ self.assertEqual(mf.read_morphology('bar.morph'),
"dummy morphology text")
def test_read_morph_raises_with_invalid_ref(self):
@@ -101,11 +101,11 @@ class MorphologyFinderTests(unittest.TestCase):
def test_read_morph_in_work_tree(self):
gd = morphlib.gitdir.GitDirectory(self.dirname)
mf = morphlib.morphologyfinder.MorphologyFinder(gd)
- self.assertEqual(mf.read_morphology('foo')[0],
+ self.assertEqual(mf.read_morphology('foo.morph'),
"altered morphology text")
def test_read_morph_raises_no_worktree_no_ref(self):
gd = morphlib.gitdir.GitDirectory(self.mirror)
mf = morphlib.morphologyfinder.MorphologyFinder(gd)
self.assertRaises(morphlib.gitdir.NoWorkingTreeError,
- mf.read_morphology, 'bar')
+ mf.read_morphology, 'bar.morph')
diff --git a/morphlib/plugins/deploy_plugin.py b/morphlib/plugins/deploy_plugin.py
index 6fc0998c..7c009071 100644
--- a/morphlib/plugins/deploy_plugin.py
+++ b/morphlib/plugins/deploy_plugin.py
@@ -292,11 +292,10 @@ class DeployPlugin(cliapp.Plugin):
name = morphlib.git.get_user_name(self.app.runcmd)
email = morphlib.git.get_user_email(self.app.runcmd)
build_ref_prefix = self.app.settings['build-ref-prefix']
-
root_repo_dir = morphlib.gitdir.GitDirectory(
sb.get_git_directory_name(sb.root_repository_url))
- mf = morphlib.morphologyfinder.MorphologyFinder(root_repo_dir)
- cluster_text, cluster_filename = mf.read_morphology(cluster_name)
+ cluster_filename = cluster_name + '.morph'
+ cluster_text = root_repo_dir.read_file(cluster_filename)
cluster_morphology = loader.load_from_string(cluster_text,
filename=cluster_filename)
diff --git a/morphlib/sysbranchdir.py b/morphlib/sysbranchdir.py
index 9d96e974..ee6a3cc7 100644
--- a/morphlib/sysbranchdir.py
+++ b/morphlib/sysbranchdir.py
@@ -176,8 +176,8 @@ class SystemBranchDirectory(object):
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)
+ for filename in mf.list_morphologies():
+ text = mf.read_morphology(filename)
m = loader.load_from_string(text, filename=filename)
m.repo_url = self.root_repository_url
m.ref = self.system_branch_name