diff options
author | Richard Maw <richard.maw@codethink.co.uk> | 2014-07-07 13:12:00 +0000 |
---|---|---|
committer | Richard Maw <richard.maw@codethink.co.uk> | 2014-07-07 13:12:00 +0000 |
commit | dc16450fa37c715a81b61213ade807734b404914 (patch) | |
tree | 3bdbf24e5503a620c4d0224fe5d07ec28392acae /morphlib/morphologyfinder.py | |
parent | 09b6d77a5eea0594965b27d1697fa2fed2ec3b39 (diff) | |
download | morph-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.
Diffstat (limited to 'morphlib/morphologyfinder.py')
-rw-r--r-- | morphlib/morphologyfinder.py | 21 |
1 files changed, 6 insertions, 15 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)) |