diff options
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): |