txtar


Nametxtar JSON
Version 0.1.1 PyPI version JSON
download
home_pagehttps://github.com/davidventura/txtar
SummaryPort of golang's txtar, a trivial tar-like format for unit tests
upload_time2023-12-12 22:57:21
maintainer
docs_urlNone
authordavid
requires_python>=3.8,<4.0
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # txtar

`txtar` is a Python reimplementation of Go's txtar format, a tool for bundling and managing multiple text files in a single archive.

## Features

- Parse `txtar` formatted text into structured data.
- Serialize structured data back into `txtar` format.
- Unpack `txtar` archives into the file system.


## Usage

### In unit tests

```python
from pathlib import Path
import os

def test_my_function():
    # Define the txtar structure for sysfs-like files
    txtar_content = """
-- sys/class/thermal/thermal_zone0/temp --
55000
-- sys/class/power_supply/BAT0/capacity --
45
-- sys/block/sda/size --
1024000
"""

    with MockFS.from_string(txtar_content):
        assert os.path.exists("/sys/class/thermal/thermal_zone0/temp")
        assert os.path.exists("/sys/class/power_supply/BAT0/capacity")
        assert os.path.exists("/sys/block/sda/size")

        assert Path("/sys/block/sda/size").exists()
```

### Reading a file
```python
from txtar import TxTar

content = "..."  # txtar formatted string
archive = TxTar.parse(content)
```

### Serializing to txtar Format

```python
from txtar import TxTar, File

archive = TxTar(
    comments=["Example txtar archive"],
    files=[File(name="example.txt", lines=["Hello", "World"])]
)
content = archive.serialize()
```

### Unpacking an Archive

```python
from pathlib import Path
from txtar import TxTar

archive = TxTar.parse("...")
archive.unpack_in(Path("/path/to/unpack"))
```

## Development

 * Install dependencies: `poetry install`
 * Run tests with `pytest`.

## Releasing

```
poetry publish --build --username __token__ --password $PYPI_PASSWORD
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/davidventura/txtar",
    "name": "txtar",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8,<4.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "david",
    "author_email": "davidventura27@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/f2/5a/74eeed94bc8babf0a2b472d6869e8b792e106cef1bbdce0187778d7196d0/txtar-0.1.1.tar.gz",
    "platform": null,
    "description": "# txtar\n\n`txtar` is a Python reimplementation of Go's txtar format, a tool for bundling and managing multiple text files in a single archive.\n\n## Features\n\n- Parse `txtar` formatted text into structured data.\n- Serialize structured data back into `txtar` format.\n- Unpack `txtar` archives into the file system.\n\n\n## Usage\n\n### In unit tests\n\n```python\nfrom pathlib import Path\nimport os\n\ndef test_my_function():\n    # Define the txtar structure for sysfs-like files\n    txtar_content = \"\"\"\n-- sys/class/thermal/thermal_zone0/temp --\n55000\n-- sys/class/power_supply/BAT0/capacity --\n45\n-- sys/block/sda/size --\n1024000\n\"\"\"\n\n    with MockFS.from_string(txtar_content):\n        assert os.path.exists(\"/sys/class/thermal/thermal_zone0/temp\")\n        assert os.path.exists(\"/sys/class/power_supply/BAT0/capacity\")\n        assert os.path.exists(\"/sys/block/sda/size\")\n\n        assert Path(\"/sys/block/sda/size\").exists()\n```\n\n### Reading a file\n```python\nfrom txtar import TxTar\n\ncontent = \"...\"  # txtar formatted string\narchive = TxTar.parse(content)\n```\n\n### Serializing to txtar Format\n\n```python\nfrom txtar import TxTar, File\n\narchive = TxTar(\n    comments=[\"Example txtar archive\"],\n    files=[File(name=\"example.txt\", lines=[\"Hello\", \"World\"])]\n)\ncontent = archive.serialize()\n```\n\n### Unpacking an Archive\n\n```python\nfrom pathlib import Path\nfrom txtar import TxTar\n\narchive = TxTar.parse(\"...\")\narchive.unpack_in(Path(\"/path/to/unpack\"))\n```\n\n## Development\n\n * Install dependencies: `poetry install`\n * Run tests with `pytest`.\n\n## Releasing\n\n```\npoetry publish --build --username __token__ --password $PYPI_PASSWORD\n```\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Port of golang's txtar, a trivial tar-like format for unit tests",
    "version": "0.1.1",
    "project_urls": {
        "Documentation": "https://github.com/davidventura/txtar",
        "Homepage": "https://github.com/davidventura/txtar",
        "Repository": "https://github.com/davidventura/txtar"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b4a203ac1dd484b8fab77fed0bf72fcf52768a987f101b828078a93cd237e872",
                "md5": "dae74b93fb0f4ff44d6e1ceb2fcc4efc",
                "sha256": "ed21701cd8418466cf60387c0eac4d300cfccf0de2aa7309850f0790946c3f6a"
            },
            "downloads": -1,
            "filename": "txtar-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "dae74b93fb0f4ff44d6e1ceb2fcc4efc",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<4.0",
            "size": 2815,
            "upload_time": "2023-12-12T22:57:20",
            "upload_time_iso_8601": "2023-12-12T22:57:20.698639Z",
            "url": "https://files.pythonhosted.org/packages/b4/a2/03ac1dd484b8fab77fed0bf72fcf52768a987f101b828078a93cd237e872/txtar-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f25a74eeed94bc8babf0a2b472d6869e8b792e106cef1bbdce0187778d7196d0",
                "md5": "8c3f91770864e06ae2af9d2c269797d2",
                "sha256": "d1c0065e8538cd891518fa3f703fdf8f6e2a1be59032ee8c9602118de0a73726"
            },
            "downloads": -1,
            "filename": "txtar-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "8c3f91770864e06ae2af9d2c269797d2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<4.0",
            "size": 2944,
            "upload_time": "2023-12-12T22:57:21",
            "upload_time_iso_8601": "2023-12-12T22:57:21.831188Z",
            "url": "https://files.pythonhosted.org/packages/f2/5a/74eeed94bc8babf0a2b472d6869e8b792e106cef1bbdce0187778d7196d0/txtar-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-12-12 22:57:21",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "davidventura",
    "github_project": "txtar",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "txtar"
}
        
Elapsed time: 0.38743s