diff options
author | Richard Maw <richard.maw@codethink.co.uk> | 2014-07-11 14:25:40 +0100 |
---|---|---|
committer | Richard Maw <richard.maw@codethink.co.uk> | 2014-07-11 14:25:40 +0100 |
commit | ce1fedb4e5ab82105853c4f3a8e05fb83f62c18e (patch) | |
tree | 6a738f64b517992eed10c3d5891bbb27840202e4 /morphlib/util.py | |
parent | fe4486c1ec69c520a2c0aee7b52c35b57808120e (diff) | |
parent | 597f2a19363b7e91b928d814627c9236779998fb (diff) | |
download | morph-ce1fedb4e5ab82105853c4f3a8e05fb83f62c18e.tar.gz |
Merge remote-tracking branch 'origin/baserock/richardmaw/S11284/morphologies-by-path-v4'
Reviewed-by: Sam Thursfield
Reviewed-by: Lars Wirzenius
Diffstat (limited to 'morphlib/util.py')
-rw-r--r-- | morphlib/util.py | 23 |
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): |