pathschema


Namepathschema JSON
Version 0.2.1 PyPI version JSON
download
home_page
SummaryStandardize and plan out a file structure!
upload_time2023-08-12 04:04:58
maintainer
docs_urlNone
author
requires_python>=3.9
license
keywords directory file file system folder schema validation
VCS
bugtrack_url
requirements pylint colorama build
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Path Schema

![PyPi Version](https://img.shields.io/pypi/v/pathschema.svg) ![PyPI Python Version](https://img.shields.io/pypi/pyversions/pathschema.svg?logo=python&logoColor=gold) ![License MIT](https://img.shields.io/pypi/l/pathschema)

```bash
pip install pathschema
```

[Check out the online demo!](https://apollo-roboto.github.io/python-pathschema/)

# How to use

```python
from pathschema import validate

schema = 'YOUR SCHEMA HERE'

path_to_validate = './path'

with open('path/to/schema.pathschema', 'r') as f:
	schema = f.read()

result = validate(path_to_validate, schema)

if(result.has_error()):
	print('Invalid')
else:
	print('Valid')
```

## Syntax

|  Symbol | Description  | Example |
|---------|--------------|---------|
| `/` | Slashes at the end of the name marks this path as a folder | `root/` |
| `""` | Quotes adds regex validation to the file name | `"file[0-9]{3}"` |
| `""/` | Quotes with a slash adds regex validation to the folder name | `"folder[0-9]{3}"/` |
| `*` | Unix style pattern matching for files | `*.txt` |
| `*/` | Unix style pattern matching for folders | `log_*/` |
| `...` | Allows any (and nested) files and folder | `...` |
| `+` | A `+` at the start makes the file or folder required | `+required_file.txt` |
| `-` | A `-` at the start makes the file or folder forbidden | `-forbidden_folder/` |
| `#` | Write a comment | `# cool comment` |

## Command line

pathschema can be used directly in the command line.

```bash
python -m pathschema ./.pathschema path/to/dir/to/validate
```

Argument details:
```txt
usage: __main__.py [-h] [--errors-only] schema directory

Validate a directory against a schema

positional arguments:
  schema         Path to schema file
  directory      Path to directory to validate

options:
  -h, --help     show this help message and exit
  --errors-only  Only show errors
```

# Development

Installing
```bash
python -m pip install -r ./requirements.txt
python -m build
python -m pip install -e .
```

Running tests
```bash
python -m unittest discover -v -s ./tests -p test_*.py
```

Command line without installing
```bash
python ./pathschema/ ./tests/experimentations/test_schema.pathschema ./tests/experimentations/test_directory_ok
```

# Example Schema Definition

Example:
```txt
assets/
	textures/
		*.gif
		*.png
	materials/
		"(trans|solid)_.+\.mat"
	+README.md
```

## Only allows `.mp4` or `.flv` in the `videos` folder
```txt
videos/
	*.mp4
	*.flv
```

This structure would be valid.
```txt
videos/
	robots.mp4
	planets.flv
	my-mix-tape.flv
```

This structure would be invalid. *(`.png` and `.jpg` is not allowed)*
```txt
videos/
	office.png
	robots.jpg
```

## Any files and folder allowed in the `assets` folder
```txt
assets/
	...
```

Any files and directories would be valid in the `assets` folder.
```txt
assets/
	banner.png
	backgrounds/
		bg_black.png
		bg_white.png
```

## Must have a `README.md` file
```txt
example/
	*/
		*
		+README.md
```

This structure would be valid.

```txt
example/
	things/
		file.txt
		README.md
	morethings/
		README.md
```

This structure would be invalid. (Missing `README.md`)

```txt
example/
	things/
		file.txt
	morethings/
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "pathschema",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "",
    "keywords": "Directory,File,File System,Folder,Schema,Validation",
    "author": "",
    "author_email": "Apollo-Roboto <Apollo_Roboto@outlook.com>",
    "download_url": "https://files.pythonhosted.org/packages/9a/84/74b6a4583b3a5e9c43491413396015369a6727c65c52689e5bf75f77b885/pathschema-0.2.1.tar.gz",
    "platform": null,
    "description": "# Path Schema\n\n![PyPi Version](https://img.shields.io/pypi/v/pathschema.svg) ![PyPI Python Version](https://img.shields.io/pypi/pyversions/pathschema.svg?logo=python&logoColor=gold) ![License MIT](https://img.shields.io/pypi/l/pathschema)\n\n```bash\npip install pathschema\n```\n\n[Check out the online demo!](https://apollo-roboto.github.io/python-pathschema/)\n\n# How to use\n\n```python\nfrom pathschema import validate\n\nschema = 'YOUR SCHEMA HERE'\n\npath_to_validate = './path'\n\nwith open('path/to/schema.pathschema', 'r') as f:\n\tschema = f.read()\n\nresult = validate(path_to_validate, schema)\n\nif(result.has_error()):\n\tprint('Invalid')\nelse:\n\tprint('Valid')\n```\n\n## Syntax\n\n|  Symbol | Description  | Example |\n|---------|--------------|---------|\n| `/` | Slashes at the end of the name marks this path as a folder | `root/` |\n| `\"\"` | Quotes adds regex validation to the file name | `\"file[0-9]{3}\"` |\n| `\"\"/` | Quotes with a slash adds regex validation to the folder name | `\"folder[0-9]{3}\"/` |\n| `*` | Unix style pattern matching for files | `*.txt` |\n| `*/` | Unix style pattern matching for folders | `log_*/` |\n| `...` | Allows any (and nested) files and folder | `...` |\n| `+` | A `+` at the start makes the file or folder required | `+required_file.txt` |\n| `-` | A `-` at the start makes the file or folder forbidden | `-forbidden_folder/` |\n| `#` | Write a comment | `# cool comment` |\n\n## Command line\n\npathschema can be used directly in the command line.\n\n```bash\npython -m pathschema ./.pathschema path/to/dir/to/validate\n```\n\nArgument details:\n```txt\nusage: __main__.py [-h] [--errors-only] schema directory\n\nValidate a directory against a schema\n\npositional arguments:\n  schema         Path to schema file\n  directory      Path to directory to validate\n\noptions:\n  -h, --help     show this help message and exit\n  --errors-only  Only show errors\n```\n\n# Development\n\nInstalling\n```bash\npython -m pip install -r ./requirements.txt\npython -m build\npython -m pip install -e .\n```\n\nRunning tests\n```bash\npython -m unittest discover -v -s ./tests -p test_*.py\n```\n\nCommand line without installing\n```bash\npython ./pathschema/ ./tests/experimentations/test_schema.pathschema ./tests/experimentations/test_directory_ok\n```\n\n# Example Schema Definition\n\nExample:\n```txt\nassets/\n\ttextures/\n\t\t*.gif\n\t\t*.png\n\tmaterials/\n\t\t\"(trans|solid)_.+\\.mat\"\n\t+README.md\n```\n\n## Only allows `.mp4` or `.flv` in the `videos` folder\n```txt\nvideos/\n\t*.mp4\n\t*.flv\n```\n\nThis structure would be valid.\n```txt\nvideos/\n\trobots.mp4\n\tplanets.flv\n\tmy-mix-tape.flv\n```\n\nThis structure would be invalid. *(`.png` and `.jpg` is not allowed)*\n```txt\nvideos/\n\toffice.png\n\trobots.jpg\n```\n\n## Any files and folder allowed in the `assets` folder\n```txt\nassets/\n\t...\n```\n\nAny files and directories would be valid in the `assets` folder.\n```txt\nassets/\n\tbanner.png\n\tbackgrounds/\n\t\tbg_black.png\n\t\tbg_white.png\n```\n\n## Must have a `README.md` file\n```txt\nexample/\n\t*/\n\t\t*\n\t\t+README.md\n```\n\nThis structure would be valid.\n\n```txt\nexample/\n\tthings/\n\t\tfile.txt\n\t\tREADME.md\n\tmorethings/\n\t\tREADME.md\n```\n\nThis structure would be invalid. (Missing `README.md`)\n\n```txt\nexample/\n\tthings/\n\t\tfile.txt\n\tmorethings/\n```\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Standardize and plan out a file structure!",
    "version": "0.2.1",
    "project_urls": {
        "Source": "https://github.com/Apollo-Roboto/python-pathschema"
    },
    "split_keywords": [
        "directory",
        "file",
        "file system",
        "folder",
        "schema",
        "validation"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d35ac2c591389c57e1d207081e2f484ffb2c1f6c73366e00505ff8984d5c095c",
                "md5": "e52ae8f14b1cd4085deea542aaa11333",
                "sha256": "2a0e67ee5ba81df8d8486a6ade39f2a69464ba60cbb7f92690427161d930c743"
            },
            "downloads": -1,
            "filename": "pathschema-0.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e52ae8f14b1cd4085deea542aaa11333",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 9541,
            "upload_time": "2023-08-12T04:04:56",
            "upload_time_iso_8601": "2023-08-12T04:04:56.276506Z",
            "url": "https://files.pythonhosted.org/packages/d3/5a/c2c591389c57e1d207081e2f484ffb2c1f6c73366e00505ff8984d5c095c/pathschema-0.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9a8474b6a4583b3a5e9c43491413396015369a6727c65c52689e5bf75f77b885",
                "md5": "2db2f412ec8d36fbc66b9c2687056d14",
                "sha256": "4ec45060b1c2288b40acb046f87470f546d50227cbd25d2bd9a851e4c2f8b349"
            },
            "downloads": -1,
            "filename": "pathschema-0.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "2db2f412ec8d36fbc66b9c2687056d14",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 13205,
            "upload_time": "2023-08-12T04:04:58",
            "upload_time_iso_8601": "2023-08-12T04:04:58.007456Z",
            "url": "https://files.pythonhosted.org/packages/9a/84/74b6a4583b3a5e9c43491413396015369a6727c65c52689e5bf75f77b885/pathschema-0.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-12 04:04:58",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Apollo-Roboto",
    "github_project": "python-pathschema",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "pylint",
            "specs": [
                [
                    "==",
                    "2.17.4"
                ]
            ]
        },
        {
            "name": "colorama",
            "specs": [
                [
                    "==",
                    "0.4.6"
                ]
            ]
        },
        {
            "name": "build",
            "specs": [
                [
                    "==",
                    "0.9.0"
                ]
            ]
        }
    ],
    "lcname": "pathschema"
}
        
Elapsed time: 0.10281s