summaryrefslogtreecommitdiff
path: root/morphlib/util.py
diff options
context:
space:
mode:
authorRichard Maw <richard.maw@codethink.co.uk>2014-06-17 16:36:07 +0000
committerRichard Maw <richard.maw@codethink.co.uk>2014-07-10 13:50:00 +0000
commit3dc83847b8f17793bdab5e978d13d394b48987b0 (patch)
treea67c54b99b7e822ab7f49df3c9df2199435f21ff /morphlib/util.py
parentae007688d8f1f57b138dafffdfc3683aa7c7730f (diff)
downloadmorph-3dc83847b8f17793bdab5e978d13d394b48987b0.tar.gz
Use exact filenames to refer to morphology files
Rather than repeatedly stripping and appending an optional .morph extension morphology names, instead always use the file path of the morphology relative to the definitions repository. This is an inversion of the previous logic, which would strip the .morph extension and use the "name" internally. The exception to this rule of always using the filename, is that `morph edit CHUNK` uses the name of the morphology as-defined in the stratum. This is based off Adam Coldrick's inital patch, but this version will allow the old style of providing the "name" by converting it into a path if it does not have either a / or a . in it. An unfortunate consequence of this change is that the show-dependencies command's output changed, so the test needed updating.
Diffstat (limited to 'morphlib/util.py')
-rw-r--r--morphlib/util.py23
1 files changed, 16 insertions, 7 deletions
diff --git a/morphlib/util.py b/morphlib/util.py
index 024de495..0c551296 100644
--- a/morphlib/util.py
+++ b/morphlib/util.py
@@ -61,13 +61,22 @@ def indent(string, spaces=4):
return '\n'.join(lines)
-def strip_morph_extension(morph_name):
- if morph_name.startswith('.'):
- raise morphlib.Error(
- 'Invalid morphology name: %s' % morph_name)
- elif morph_name.endswith('.morph'):
- return morph_name[:-len('.morph')]
- return morph_name
+def sanitise_morphology_path(morph_name):
+ '''Turn morph_name into a file path to a morphology.
+
+ We support both a file path being provided, and just the morphology
+ name for backwards compatibility.
+
+ '''
+ # If it has a / it must be a path, so return it unmolested
+ if '/' in morph_name:
+ return morph_name
+ # Must be an old format, which is always name + .morph
+ elif not morph_name.endswith('.morph'):
+ return morph_name + '.morph'
+ # morphology already ends with .morph
+ else:
+ return morph_name
def make_concurrency(cores=None):