lockable


Namelockable JSON
Version 0.11.0 PyPI version JSON
download
home_pagehttps://github.com/jupe/py-lockable
Summarylockable resource module
upload_time2024-01-24 12:16:28
maintainer
docs_urlNone
authorJussi Vatjus-Anttila
requires_python>=3.8, <4
license
keywords py.test pytest lockable resource
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            # lockable

[![CircleCI](https://circleci.com/gh/jupe/py-lockable/tree/master.svg?style=svg)](https://circleci.com/gh/jupe/py-lockable/tree/master)
[![PyPI version](https://badge.fury.io/py/lockable.svg)](https://pypi.org/project/lockable/)
[![Coverage Status](https://coveralls.io/repos/github/jupe/pytest-lockable/badge.svg)](https://coveralls.io/github/jupe/py-lockable)

Resource locking module for python.

Originally designed for following projects:
* [pytest-lockable](https://github.com/jupe/pytest-lockable)
* [robot-lockable](https://github.com/jupe/robot-lockable)


Module provides python API and simple CLI interface.

Resource is released in following cases:
* process ends
* when context ends when `lockable.auto_lock(..)` is used
* allocation.unlock() is called
* lockable.unlock(<allocation>) is called

Resources data provider support following mechanisms:
* `resources.json` file in file system
* python list of dictionaries
* http uri which points to API and is used with HTTP GET method. API should provide `resources.json` data as json object.

# CLI interface

```
% lockable --help
usage: lockable [-h] [--validate-only] [--lock-folder LOCK_FOLDER] [--resources RESOURCES]
                [--timeout TIMEOUT] [--hostname HOSTNAME]
                [--requirements REQUIREMENTS]
                [command [command ...]]

run given command while suitable resource is allocated.
Usage example: lockable --requirements {"online":true} echo using resource: $ID

positional arguments:
  command               Command to be execute during device allocation

optional arguments:
  -h, --help            show this help message and exit
  --validate-only       Only validate resources.json
  --lock-folder LOCK_FOLDER
                        lock folder
  --resources RESOURCES
                        Resources file (utf-8) or http uri
  --timeout TIMEOUT     Timeout for trying allocate suitable resource
  --hostname HOSTNAME   Hostname
  --requirements REQUIREMENTS
                        requirements as json string

```

# API's

Constructor
```python
lockable = Lockable([hostname], [resource_list_file], [resource_list], [lock_folder])
```

Allocation
```python
allocation_context = lockable.lock(requirements, [timeout_s])
print(allocation_context.resource_info)
print(allocation_context.resource_id)
allocation_context.unlock()
# or using resource info
lockable.unlock(allocation_context)
```

Allocation context contains following API:
* `requirements: dict` Original requirements for allocation
* `resource_info: dict` Allocated resource information
* `unlock(): func`  release resource lock function
* `allocation_queue_time: timedelta` How long waited before allocation
* `allocation_start_time: datetime` when allocation was started
* `release_time: datetime` when allocation was ended
* `alloc_id: str` allocation id
* `allocation_durations: timedelta` how long time allocation takes

or using context manager which unlock automatically
```python
with lockable.auto_lock(requirements, [timeout_s]) as allocation:
    print(allocation.resource_info)
```

**Tips:**

You can allocate also offline devices by set requirements `"online": None` . 
You can ignore also `hostname` same same way by  setting it to  None`



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/jupe/py-lockable",
    "name": "lockable",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8, <4",
    "maintainer_email": "",
    "keywords": "py.test pytest lockable resource",
    "author": "Jussi Vatjus-Anttila",
    "author_email": "jussiva@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/7e/18/0495dafa66c57aa68aef5d84fff64535aaf5279ba3b63b51ecf70ca4abc1/lockable-0.11.0.tar.gz",
    "platform": null,
    "description": "# lockable\n\n[![CircleCI](https://circleci.com/gh/jupe/py-lockable/tree/master.svg?style=svg)](https://circleci.com/gh/jupe/py-lockable/tree/master)\n[![PyPI version](https://badge.fury.io/py/lockable.svg)](https://pypi.org/project/lockable/)\n[![Coverage Status](https://coveralls.io/repos/github/jupe/pytest-lockable/badge.svg)](https://coveralls.io/github/jupe/py-lockable)\n\nResource locking module for python.\n\nOriginally designed for following projects:\n* [pytest-lockable](https://github.com/jupe/pytest-lockable)\n* [robot-lockable](https://github.com/jupe/robot-lockable)\n\n\nModule provides python API and simple CLI interface.\n\nResource is released in following cases:\n* process ends\n* when context ends when `lockable.auto_lock(..)` is used\n* allocation.unlock() is called\n* lockable.unlock(<allocation>) is called\n\nResources data provider support following mechanisms:\n* `resources.json` file in file system\n* python list of dictionaries\n* http uri which points to API and is used with HTTP GET method. API should provide `resources.json` data as json object.\n\n# CLI interface\n\n```\n% lockable --help\nusage: lockable [-h] [--validate-only] [--lock-folder LOCK_FOLDER] [--resources RESOURCES]\n                [--timeout TIMEOUT] [--hostname HOSTNAME]\n                [--requirements REQUIREMENTS]\n                [command [command ...]]\n\nrun given command while suitable resource is allocated.\nUsage example: lockable --requirements {\"online\":true} echo using resource: $ID\n\npositional arguments:\n  command               Command to be execute during device allocation\n\noptional arguments:\n  -h, --help            show this help message and exit\n  --validate-only       Only validate resources.json\n  --lock-folder LOCK_FOLDER\n                        lock folder\n  --resources RESOURCES\n                        Resources file (utf-8) or http uri\n  --timeout TIMEOUT     Timeout for trying allocate suitable resource\n  --hostname HOSTNAME   Hostname\n  --requirements REQUIREMENTS\n                        requirements as json string\n\n```\n\n# API's\n\nConstructor\n```python\nlockable = Lockable([hostname], [resource_list_file], [resource_list], [lock_folder])\n```\n\nAllocation\n```python\nallocation_context = lockable.lock(requirements, [timeout_s])\nprint(allocation_context.resource_info)\nprint(allocation_context.resource_id)\nallocation_context.unlock()\n# or using resource info\nlockable.unlock(allocation_context)\n```\n\nAllocation context contains following API:\n* `requirements: dict` Original requirements for allocation\n* `resource_info: dict` Allocated resource information\n* `unlock(): func`  release resource lock function\n* `allocation_queue_time: timedelta` How long waited before allocation\n* `allocation_start_time: datetime` when allocation was started\n* `release_time: datetime` when allocation was ended\n* `alloc_id: str` allocation id\n* `allocation_durations: timedelta` how long time allocation takes\n\nor using context manager which unlock automatically\n```python\nwith lockable.auto_lock(requirements, [timeout_s]) as allocation:\n    print(allocation.resource_info)\n```\n\n**Tips:**\n\nYou can allocate also offline devices by set requirements `\"online\": None` . \nYou can ignore also `hostname` same same way by  setting it to  None`\n\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "lockable resource module",
    "version": "0.11.0",
    "project_urls": {
        "Bug Reports": "https://github.com/jupe/pytest-lockable",
        "Homepage": "https://github.com/jupe/py-lockable",
        "Source": "https://github.com/jupe/pytest-lockable/"
    },
    "split_keywords": [
        "py.test",
        "pytest",
        "lockable",
        "resource"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2ed85c74765b64b0eb99651942f584629cb4cb3fbe563b93fee294b04a8725e4",
                "md5": "1d9480896d5776917a295d7ae7662bfd",
                "sha256": "55580c9a711fbc6ae282ea655166cf595fd79291ebe04860ad18820bcd52f141"
            },
            "downloads": -1,
            "filename": "lockable-0.11.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1d9480896d5776917a295d7ae7662bfd",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8, <4",
            "size": 14010,
            "upload_time": "2024-01-24T12:16:27",
            "upload_time_iso_8601": "2024-01-24T12:16:27.251258Z",
            "url": "https://files.pythonhosted.org/packages/2e/d8/5c74765b64b0eb99651942f584629cb4cb3fbe563b93fee294b04a8725e4/lockable-0.11.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7e180495dafa66c57aa68aef5d84fff64535aaf5279ba3b63b51ecf70ca4abc1",
                "md5": "a00e52ae2c1d8824296db7909ac69809",
                "sha256": "6e3b535779b04cb8b7c514d1810a839fb49938f6af42234ff2b241d7a900a150"
            },
            "downloads": -1,
            "filename": "lockable-0.11.0.tar.gz",
            "has_sig": false,
            "md5_digest": "a00e52ae2c1d8824296db7909ac69809",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8, <4",
            "size": 24317,
            "upload_time": "2024-01-24T12:16:28",
            "upload_time_iso_8601": "2024-01-24T12:16:28.852137Z",
            "url": "https://files.pythonhosted.org/packages/7e/18/0495dafa66c57aa68aef5d84fff64535aaf5279ba3b63b51ecf70ca4abc1/lockable-0.11.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-24 12:16:28",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "jupe",
    "github_project": "py-lockable",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "circle": true,
    "requirements": [],
    "lcname": "lockable"
}
        
Elapsed time: 0.17482s