resolva


Nameresolva JSON
Version 0.0.1 PyPI version JSON
download
home_page
SummarySimple and fast path template resolver.
upload_time2024-02-11 16:49:23
maintainer
docs_urlNone
author
requires_python>=3.7
licenseMIT License Copyright (c) 2024 Michael Haussmann Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords path templates
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# resolva

Simple and fast path template resolver.  
Inspired by and derived from Lucidity.


## What is resolva ?

**resolva** is a python library that extracts data from a string by matching configurated patterns.

`"/mnt/prods/hamlet/shots/sq010"` => 
`"/mnt/prods/{prod}/shots/{seq}"` => 
`{"prod": "hamlet", "seq": "sq010"}`

Typical usage:
- for a path or string input,
- loops through a series of configured patterns, 
- once a matching pattern found, 
- extracts data and returns a dictionary

Instead of bare regex, the pattern uses a simpler "format" style syntax.  

**resolva** can also format the data back to a string.

### Path resolving

Template based path resolving is a typical need in CG pipeline tools.

Examples include:

- [Shotgrid Toolkit (SGTK)](https://github.com/shotgunsoftware/tk-config-default/blob/master/core/templates.yml) - Leading commercial CG and VFX Project Management and pipeline toolkit
- [CGWire's kitsu file trees](https://zou.cg-wire.com/file_trees) - Kitsu is an Open Source collaboration platform for Animation and VFX studios. 
- [Lucidity](https://gitlab.com/4degrees/lucidity) - Inspired by SGTK templating, in turn inspiration and base of **resolva**
- [spil](https://github.com/MichaelHaussmann/spil) - Uses **resolva** at its core


## Usage Example

Configuration:
```python
from resolva import Resolver

template = {"maya_file": "/mnt/prods/{prod}/shots/{seq}/{shot}_{version:(v\d\d\d)}.{ext:(ma|mb)}",
            "hou_file": "/mnt/prods/{prod}/shots/{seq}/{shot}_{version:(v\d\d\d)}.{ext:(hip|hipnc)}"}
Resolver("id", template)  # create the Resolver in an instance cache
```
Usage:
```python
from resolva import Resolver
r = Resolver.get("id")  # read the Resolver from the instance cache

input = "/mnt/prods/hamlet/shots/sq010/sh010_v012.ma"
label, data = r.resolve_first(input)

# result:
print(f'Detected type "{label}" and extracted "{data}"')
```
Output:
```
Detected type "maya_file" and extracted 
{"prod": "hamlet", "seq": "sq010", "shot": "sh010", "version": "v012", "ext": "ma"}
```



## Features

- simple template format     
  - Example: `/{shot}/{version}/{name}.{extension:(ma|mb)}`
  - handles duplicate placeholders
- very simple API
  - resolve with one, first, or all patterns
  - format with one, first, or all patterns
  - format including reverse resolve check
- high speed using caches
  - instance cache (keep regex compilations in memory)
  - lru_caches (speed up immutable resolves)


## Why not Lucidity ?

**resolva** is a simplified version of [Lucidity](https://gitlab.com/4degrees/lucidity), a filesystem templating library.

**resolva** is now used at the core of [spil](https://github.com/MichaelHaussmann/spil).  
A large amount of strings and paths need to be resolved at high speed.

The end goal is to build a rust path template resolver.  
Rust development not started yet - contributions are highly welcomed :)

To prepare this in python, we reduced the Lucidity library to its essence (around 100 lines of code).

On top of these essential features, we built a simple Resolver class with an instance cache (to keep regex compiles in memory), and a lru cache, to memoize resolves that have no reason to change.

The result is a fast and very simple toolset.

**resolva** keeps essential Lucidity's features:

- simple template format 
- handles duplicate placeholders
- pattern anchoring (start:`^`,end:`$`)

**resolva** lacks some Lucidity features, that were left out:

- individual template API
- nested data structures
- template discovery
- templates referencing templates
- python 2 support

If you need one of these, go for the original :)


## Installation

**resolva** works in Python >=3.7.  
It is available on pypi and can be installed using `pip install resolva`,  
or from github `pip install git+https://github.com/MichaelHaussmann/resolva.git`

**resolva** is open source, License: MIT.

### TODO:

- docstrings (+doctests) 
- pytests calling the existing tests
- Usage documentation, dev documentation + API documentation (readthedocs or github?)
- black, refurb, etc.
- pip installable and python bound rust implementation 


### Acknowledgements

**resolva** is inspired by, and derived from **Lucidity**.

#### Lucidity 

https://gitlab.com/4degrees/lucidity/  
https://lucidity.readthedocs.io  
copyright: Copyright (c) 2013 Martin Pengelly-Phillips  
licence: Apache License, Version 2.0

#### resolva

https://github.com/MichaelHaussmann/resolva  
(c) 2024 Michael Haussmann  
licence: MIT

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "resolva",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "path templates",
    "author": "",
    "author_email": "Michael Haussmann <spil@xeo.info>",
    "download_url": "https://files.pythonhosted.org/packages/3a/31/f1b1b9283a436a45adea2dbcc3be8a613edaabf21b0068a1250d0b67dee5/resolva-0.0.1.tar.gz",
    "platform": null,
    "description": "\n# resolva\n\nSimple and fast path template resolver.  \nInspired by and derived from Lucidity.\n\n\n## What is resolva ?\n\n**resolva** is a python library that extracts data from a string by matching configurated patterns.\n\n`\"/mnt/prods/hamlet/shots/sq010\"` => \n`\"/mnt/prods/{prod}/shots/{seq}\"` => \n`{\"prod\": \"hamlet\", \"seq\": \"sq010\"}`\n\nTypical usage:\n- for a path or string input,\n- loops through a series of configured patterns, \n- once a matching pattern found, \n- extracts data and returns a dictionary\n\nInstead of bare regex, the pattern uses a simpler \"format\" style syntax.  \n\n**resolva** can also format the data back to a string.\n\n### Path resolving\n\nTemplate based path resolving is a typical need in CG pipeline tools.\n\nExamples include:\n\n- [Shotgrid Toolkit (SGTK)](https://github.com/shotgunsoftware/tk-config-default/blob/master/core/templates.yml) - Leading commercial CG and VFX Project Management and pipeline toolkit\n- [CGWire's kitsu file trees](https://zou.cg-wire.com/file_trees) - Kitsu is an Open Source collaboration platform for Animation and VFX studios. \n- [Lucidity](https://gitlab.com/4degrees/lucidity) - Inspired by SGTK templating, in turn inspiration and base of **resolva**\n- [spil](https://github.com/MichaelHaussmann/spil) - Uses **resolva** at its core\n\n\n## Usage Example\n\nConfiguration:\n```python\nfrom resolva import Resolver\n\ntemplate = {\"maya_file\": \"/mnt/prods/{prod}/shots/{seq}/{shot}_{version:(v\\d\\d\\d)}.{ext:(ma|mb)}\",\n            \"hou_file\": \"/mnt/prods/{prod}/shots/{seq}/{shot}_{version:(v\\d\\d\\d)}.{ext:(hip|hipnc)}\"}\nResolver(\"id\", template)  # create the Resolver in an instance cache\n```\nUsage:\n```python\nfrom resolva import Resolver\nr = Resolver.get(\"id\")  # read the Resolver from the instance cache\n\ninput = \"/mnt/prods/hamlet/shots/sq010/sh010_v012.ma\"\nlabel, data = r.resolve_first(input)\n\n# result:\nprint(f'Detected type \"{label}\" and extracted \"{data}\"')\n```\nOutput:\n```\nDetected type \"maya_file\" and extracted \n{\"prod\": \"hamlet\", \"seq\": \"sq010\", \"shot\": \"sh010\", \"version\": \"v012\", \"ext\": \"ma\"}\n```\n\n\n\n## Features\n\n- simple template format     \n  - Example: `/{shot}/{version}/{name}.{extension:(ma|mb)}`\n  - handles duplicate placeholders\n- very simple API\n  - resolve with one, first, or all patterns\n  - format with one, first, or all patterns\n  - format including reverse resolve check\n- high speed using caches\n  - instance cache (keep regex compilations in memory)\n  - lru_caches (speed up immutable resolves)\n\n\n## Why not Lucidity ?\n\n**resolva** is a simplified version of [Lucidity](https://gitlab.com/4degrees/lucidity), a filesystem templating library.\n\n**resolva** is now used at the core of [spil](https://github.com/MichaelHaussmann/spil).  \nA large amount of strings and paths need to be resolved at high speed.\n\nThe end goal is to build a rust path template resolver.  \nRust development not started yet - contributions are highly welcomed :)\n\nTo prepare this in python, we reduced the Lucidity library to its essence (around 100 lines of code).\n\nOn top of these essential features, we built a simple Resolver class with an instance cache (to keep regex compiles in memory), and a lru cache, to memoize resolves that have no reason to change.\n\nThe result is a fast and very simple toolset.\n\n**resolva** keeps essential Lucidity's features:\n\n- simple template format \n- handles duplicate placeholders\n- pattern anchoring (start:`^`,end:`$`)\n\n**resolva** lacks some Lucidity features, that were left out:\n\n- individual template API\n- nested data structures\n- template discovery\n- templates referencing templates\n- python 2 support\n\nIf you need one of these, go for the original :)\n\n\n## Installation\n\n**resolva** works in Python >=3.7.  \nIt is available on pypi and can be installed using `pip install resolva`,  \nor from github `pip install git+https://github.com/MichaelHaussmann/resolva.git`\n\n**resolva** is open source, License: MIT.\n\n### TODO:\n\n- docstrings (+doctests) \n- pytests calling the existing tests\n- Usage documentation, dev documentation + API documentation (readthedocs or github?)\n- black, refurb, etc.\n- pip installable and python bound rust implementation \n\n\n### Acknowledgements\n\n**resolva** is inspired by, and derived from **Lucidity**.\n\n#### Lucidity \n\nhttps://gitlab.com/4degrees/lucidity/  \nhttps://lucidity.readthedocs.io  \ncopyright: Copyright (c) 2013 Martin Pengelly-Phillips  \nlicence: Apache License, Version 2.0\n\n#### resolva\n\nhttps://github.com/MichaelHaussmann/resolva  \n(c) 2024 Michael Haussmann  \nlicence: MIT\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2024 Michael Haussmann  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "Simple and fast path template resolver.",
    "version": "0.0.1",
    "project_urls": {
        "Homepage": "https://github.com/MichaelHaussmann/resolva"
    },
    "split_keywords": [
        "path",
        "templates"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a95f44d4894205ed54a4c226d292728ccd502ade3727cf9345aad51537933d44",
                "md5": "dadb64f3f5a30b57d227534369f133a2",
                "sha256": "7f02d7eec1079e013877d83dbbfcc6788dca84e673c6019630464ebe3963684c"
            },
            "downloads": -1,
            "filename": "resolva-0.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "dadb64f3f5a30b57d227534369f133a2",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 9304,
            "upload_time": "2024-02-11T16:49:22",
            "upload_time_iso_8601": "2024-02-11T16:49:22.188565Z",
            "url": "https://files.pythonhosted.org/packages/a9/5f/44d4894205ed54a4c226d292728ccd502ade3727cf9345aad51537933d44/resolva-0.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3a31f1b1b9283a436a45adea2dbcc3be8a613edaabf21b0068a1250d0b67dee5",
                "md5": "678cae51e34461c6d3c7970832bf284f",
                "sha256": "cd7d73bd6d170c8afbce11b6e1d4cba0d2085a48e506419acae2b0416beed77e"
            },
            "downloads": -1,
            "filename": "resolva-0.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "678cae51e34461c6d3c7970832bf284f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 7592,
            "upload_time": "2024-02-11T16:49:23",
            "upload_time_iso_8601": "2024-02-11T16:49:23.605540Z",
            "url": "https://files.pythonhosted.org/packages/3a/31/f1b1b9283a436a45adea2dbcc3be8a613edaabf21b0068a1250d0b67dee5/resolva-0.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-11 16:49:23",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "MichaelHaussmann",
    "github_project": "resolva",
    "github_not_found": true,
    "lcname": "resolva"
}
        
Elapsed time: 2.32744s