PipeFile
- class naming.PipeFile(name='', sep=' ')[source]
A convenience mixin for pipeline files in a project.
- Example:
>>> from naming import PipeFile >>> class MyPipeFile(PipeFile): ... config = dict(base=r'\w+') ... >>> p = MyPipeFile('wipfile.7.ext') >>> p.values {'base': 'wipfile', 'pipe': '.7', 'version': '7', 'suffix': 'ext'} >>> [p.get(index=x, output='render') for x in range(10)] ['wipfile.render.7.0.ext', 'wipfile.render.7.1.ext', 'wipfile.render.7.2.ext', 'wipfile.render.7.3.ext', 'wipfile.render.7.4.ext', 'wipfile.render.7.5.ext', 'wipfile.render.7.6.ext', 'wipfile.render.7.7.ext', 'wipfile.render.7.8.ext', 'wipfile.render.7.9.ext'] >>> class ProjectFile(MyPipeFile): ... config = dict(year='[0-9]{4}', ... user='[a-z]+', ... another='(constant)', ... last='[a-zA-Z0-9]+') ... >>> pf = ProjectFile('project_data_name_2017_christianl_constant_iamlast.data.17.abc', sep='_') >>> pf.values {'base': 'project_data_name', 'year': '2017', 'user': 'christianl', 'another': 'constant', 'last': 'iamlast', 'pipe': '.data.17', 'output': 'data', 'version': '17', 'suffix': 'abc'} >>> pf.nice_name # no pipe & suffix fields 'project_data_name_2017_christianl_constant_iamlast' >>> pf.year '2017' >>> pf.year = 'nondigits' # mutating with invalid fields raises a ValueError Traceback (most recent call last): ... ValueError: Can't set field 'year' with invalid value 'nondigits' on 'ProjectFile("project_data_name_2017_christianl_constant_iamlast.data.17.abc")'. A valid field value should match pattern: '[0-9]{4}' >>> pf.year = 1907 >>> pf ProjectFile("project_data_name_1907_christianl_constant_iamlast.data.17.abc") >>> pf.suffix 'abc' >>> pf.sep = ' ' # you can set the separator to a different set of characters >>> pf.name 'project_data_name 1907 christianl constant iamlast.data.17.abc'