pathier


Namepathier JSON
Version 1.5.1 PyPI version JSON
download
home_page
SummaryExtends the standard library pathlib.Path class.
upload_time2024-02-16 21:28:19
maintainer
docs_urlNone
author
requires_python<3.12,>=3.10
license
keywords extender extension json path pathlib shutil toml
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pathier

Extends the standard library pathlib.Path class.

## Installation

Install with:

<pre>
pip install pathier
</pre>



## Usage

Functions the same as pathlib.Path, but with added functions and some altered default arguments.<br>

#### Navigation

New paths can be obtained by:<br>
* naming the parent with moveup()
* subtracting a number of levels from the current path
* naming the parent of the path you actually want with move_under()
* separating a relative path at a named parent with separate()
* set current working directory to path
<pre>
>>> from pathier import Pathier
>>> path = Pathier("C:/some/directory/to/some/file/on/the/system")
>>> path.moveup("directory")
WindowsPath('C:/some/directory')
>>> path - 3
WindowsPath('C:/some/directory/to/some/file')
>>> path.move_under("directory")
WindowsPath('C:/some/directory/to')
>>> path.separate("file")
WindowsPath('on/the/system')
>>> path.separate("file", True)
WindowsPath('file/on/the/system')
>>> path.mkcwd()
>>> Pathier.cwd()
WindowsPath('C:/some/directory/to/some/file/on/the/system')
</pre>

#### Environment PATH Variable

Pathier objects can be added and removed from sys.path:<br>
(The path will only be added if it isn't already in sys.path)
<pre>
>>> from pathier import Pathier
>>> path = Pathier.cwd()
>>> path.in_PATH
False
>>> path.add_to_PATH(0)
>>> path.in_PATH
True
>>> path.remove_from_PATH()
>>> path.in_PATH
False
>>> path.append_to_PATH()
>>> path.in_PATH
True
</pre>


#### Read and Write

Can dump and load toml, json, and pickle files without needed to explicityly import and call functions from the respective libraries:
<pre>
from pathier import Pathier
path = Pathier("some_file.toml")
content = path.loads()
path.with_suffix(".json").dumps(content, indent=2)
</pre>

`Pathier().mkdir()` creates parent directories and doesn't throw an error if the path already exists by default.<br>

`Pathier().write_text()` and `Pathier().write_bytes()` will create parent directories by default if they won't exist.<br>

`Pathier().write_text()` will also try to cast the data to be written to a string if a TypeError is thrown.<br>

`Pathier().delete()` will delete a file or directory, event if that directory isn't empty.<br>

`Pathier().copy()` will copy a file or a directory tree to a new destination and return a Pathier object for the new path<br>
By default, files in the destination will not be overwritten.<br>

`Pathier().backup()` will create a copy of the path with `_backup` appended to the stem.
If the optional parameter, `timestamp`, is `True`, a datetime string will be added after `_backup` to prevent overwriting previous backup files.<br>

`Pathier().replace_strings()` takes a list of string pairs and will read the file the instance points to, replace the first of each pair with the second of each pair, and then write it back to the file.<br>
Essentially just condenses reading the file, using str.replace(), and then writing the new content into one function call.<br>

`Pathier().execute()` wraps calling `os.system()` on the path pointed to be the `Pathier` instance.<br>
Optional strings that should come before and after the path string can be specified with the `command` and `args` params, respectively.<br>
`Pathier("file.py").execute("py", "--iterations 10")` is equivalent to `os.system("py file.py --iterations 10")`<br>

`Pathier().append()` will append the given string to the file pointed at by the instance.<br>

`Pathier().join(data)` is equivalent to calling `Pathier().write_text("\n".join(data))`.<br>
The joining string can be specified with the `sep` parameter.<br>

`Pathier().split()` is equivalent to calling `Pathier().read_text().splitlines()`.<br>
Optionally, line endings can be kept with `Pathier().split(keepends=True)`.<br>
#### Stats and Comparisons
<pre>
>>> from pathier import Pathier
>>> p = Pathier.cwd() / "pathier.py"
>>> i = p.parent / "__init__.py"
>>> p.dob
datetime.datetime(2023, 3, 31, 18, 43, 12, 360000)
>>> p.age
8846.024934
>>> p.mod_date
datetime.datetime(2023, 3, 31, 21, 7, 30)
>>> p.mod_delta
207.488857
>>> p.size
10744
>>> p.format_bytes(p.size)
'10.74 kb'
>>> p.formatted_size
'10.74 kb'
>>> p.is_larger(i)
True
>>> p.is_older(i)
False
>>> p.modified_more_recently(i)
True
</pre>

#### CLI Scripts
Execute `sizeup` from a terminal to get a grid of sub-directories and their sizes.
<pre>
P:\python\projects\pathier>sizeup
Sizing up 7 directories...
Scanning 'dist' [____________________________________________________________________________________________________________________________________________]-100.00%
+---------------+-----------+
| Dir           | Size      |
+===============+===========+
| docs          | 362.74 kb |
+---------------+-----------+
| tests         | 63.69 kb  |
+---------------+-----------+
| dist          | 61.78 kb  |
+---------------+-----------+
| src           | 50.91 kb  |
+---------------+-----------+
| .git          | 24.25 kb  |
+---------------+-----------+
| .pytest_cache | 540 bytes |
+---------------+-----------+
| .vscode       | 197 bytes |
+---------------+-----------+
Total size of 'P:\python\projects\pathier': 564.11 kb
sizeup average execution time: 37ms 895us
</pre>

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "pathier",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "<3.12,>=3.10",
    "maintainer_email": "",
    "keywords": "extender,extension,json,path,pathlib,shutil,toml",
    "author": "",
    "author_email": "Matt Manes <mattmanes@pm.me>",
    "download_url": "https://files.pythonhosted.org/packages/1d/28/9853842fdb8f8956d0ae104199963f64b1456f967507028d4a907d859818/pathier-1.5.1.tar.gz",
    "platform": null,
    "description": "# pathier\n\nExtends the standard library pathlib.Path class.\n\n## Installation\n\nInstall with:\n\n<pre>\npip install pathier\n</pre>\n\n\n\n## Usage\n\nFunctions the same as pathlib.Path, but with added functions and some altered default arguments.<br>\n\n#### Navigation\n\nNew paths can be obtained by:<br>\n* naming the parent with moveup()\n* subtracting a number of levels from the current path\n* naming the parent of the path you actually want with move_under()\n* separating a relative path at a named parent with separate()\n* set current working directory to path\n<pre>\n>>> from pathier import Pathier\n>>> path = Pathier(\"C:/some/directory/to/some/file/on/the/system\")\n>>> path.moveup(\"directory\")\nWindowsPath('C:/some/directory')\n>>> path - 3\nWindowsPath('C:/some/directory/to/some/file')\n>>> path.move_under(\"directory\")\nWindowsPath('C:/some/directory/to')\n>>> path.separate(\"file\")\nWindowsPath('on/the/system')\n>>> path.separate(\"file\", True)\nWindowsPath('file/on/the/system')\n>>> path.mkcwd()\n>>> Pathier.cwd()\nWindowsPath('C:/some/directory/to/some/file/on/the/system')\n</pre>\n\n#### Environment PATH Variable\n\nPathier objects can be added and removed from sys.path:<br>\n(The path will only be added if it isn't already in sys.path)\n<pre>\n>>> from pathier import Pathier\n>>> path = Pathier.cwd()\n>>> path.in_PATH\nFalse\n>>> path.add_to_PATH(0)\n>>> path.in_PATH\nTrue\n>>> path.remove_from_PATH()\n>>> path.in_PATH\nFalse\n>>> path.append_to_PATH()\n>>> path.in_PATH\nTrue\n</pre>\n\n\n#### Read and Write\n\nCan dump and load toml, json, and pickle files without needed to explicityly import and call functions from the respective libraries:\n<pre>\nfrom pathier import Pathier\npath = Pathier(\"some_file.toml\")\ncontent = path.loads()\npath.with_suffix(\".json\").dumps(content, indent=2)\n</pre>\n\n`Pathier().mkdir()` creates parent directories and doesn't throw an error if the path already exists by default.<br>\n\n`Pathier().write_text()` and `Pathier().write_bytes()` will create parent directories by default if they won't exist.<br>\n\n`Pathier().write_text()` will also try to cast the data to be written to a string if a TypeError is thrown.<br>\n\n`Pathier().delete()` will delete a file or directory, event if that directory isn't empty.<br>\n\n`Pathier().copy()` will copy a file or a directory tree to a new destination and return a Pathier object for the new path<br>\nBy default, files in the destination will not be overwritten.<br>\n\n`Pathier().backup()` will create a copy of the path with `_backup` appended to the stem.\nIf the optional parameter, `timestamp`, is `True`, a datetime string will be added after `_backup` to prevent overwriting previous backup files.<br>\n\n`Pathier().replace_strings()` takes a list of string pairs and will read the file the instance points to, replace the first of each pair with the second of each pair, and then write it back to the file.<br>\nEssentially just condenses reading the file, using str.replace(), and then writing the new content into one function call.<br>\n\n`Pathier().execute()` wraps calling `os.system()` on the path pointed to be the `Pathier` instance.<br>\nOptional strings that should come before and after the path string can be specified with the `command` and `args` params, respectively.<br>\n`Pathier(\"file.py\").execute(\"py\", \"--iterations 10\")` is equivalent to `os.system(\"py file.py --iterations 10\")`<br>\n\n`Pathier().append()` will append the given string to the file pointed at by the instance.<br>\n\n`Pathier().join(data)` is equivalent to calling `Pathier().write_text(\"\\n\".join(data))`.<br>\nThe joining string can be specified with the `sep` parameter.<br>\n\n`Pathier().split()` is equivalent to calling `Pathier().read_text().splitlines()`.<br>\nOptionally, line endings can be kept with `Pathier().split(keepends=True)`.<br>\n#### Stats and Comparisons\n<pre>\n>>> from pathier import Pathier\n>>> p = Pathier.cwd() / \"pathier.py\"\n>>> i = p.parent / \"__init__.py\"\n>>> p.dob\ndatetime.datetime(2023, 3, 31, 18, 43, 12, 360000)\n>>> p.age\n8846.024934\n>>> p.mod_date\ndatetime.datetime(2023, 3, 31, 21, 7, 30)\n>>> p.mod_delta\n207.488857\n>>> p.size\n10744\n>>> p.format_bytes(p.size)\n'10.74 kb'\n>>> p.formatted_size\n'10.74 kb'\n>>> p.is_larger(i)\nTrue\n>>> p.is_older(i)\nFalse\n>>> p.modified_more_recently(i)\nTrue\n</pre>\n\n#### CLI Scripts\nExecute `sizeup` from a terminal to get a grid of sub-directories and their sizes.\n<pre>\nP:\\python\\projects\\pathier>sizeup\nSizing up 7 directories...\nScanning 'dist' [____________________________________________________________________________________________________________________________________________]-100.00%\n+---------------+-----------+\n| Dir           | Size      |\n+===============+===========+\n| docs          | 362.74 kb |\n+---------------+-----------+\n| tests         | 63.69 kb  |\n+---------------+-----------+\n| dist          | 61.78 kb  |\n+---------------+-----------+\n| src           | 50.91 kb  |\n+---------------+-----------+\n| .git          | 24.25 kb  |\n+---------------+-----------+\n| .pytest_cache | 540 bytes |\n+---------------+-----------+\n| .vscode       | 197 bytes |\n+---------------+-----------+\nTotal size of 'P:\\python\\projects\\pathier': 564.11 kb\nsizeup average execution time: 37ms 895us\n</pre>\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Extends the standard library pathlib.Path class.",
    "version": "1.5.1",
    "project_urls": {
        "Documentation": "https://github.com/matt-manes/pathier/tree/main/docs",
        "Homepage": "https://github.com/matt-manes/pathier",
        "Source code": "https://github.com/matt-manes/pathier/tree/main/src/pathier"
    },
    "split_keywords": [
        "extender",
        "extension",
        "json",
        "path",
        "pathlib",
        "shutil",
        "toml"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fb17193635bb465676cb42d23e1cb5672d4eb477ec2b3ff46c35e0f5a5083d3e",
                "md5": "64b7ea5d6be0bb3014d245114eb00427",
                "sha256": "7aa332f09c8a6310d877f10d9bd145f126c0b4309719fc5f2b8e99be19055885"
            },
            "downloads": -1,
            "filename": "pathier-1.5.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "64b7ea5d6be0bb3014d245114eb00427",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<3.12,>=3.10",
            "size": 10503,
            "upload_time": "2024-02-16T21:28:17",
            "upload_time_iso_8601": "2024-02-16T21:28:17.972952Z",
            "url": "https://files.pythonhosted.org/packages/fb/17/193635bb465676cb42d23e1cb5672d4eb477ec2b3ff46c35e0f5a5083d3e/pathier-1.5.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1d289853842fdb8f8956d0ae104199963f64b1456f967507028d4a907d859818",
                "md5": "e4cc7443aea76e0e8a3a065e69db1c3c",
                "sha256": "bf1bae0f6fe3d8bc4975d68435b961211b6dabfab55546db32e9c23ecea87e2c"
            },
            "downloads": -1,
            "filename": "pathier-1.5.1.tar.gz",
            "has_sig": false,
            "md5_digest": "e4cc7443aea76e0e8a3a065e69db1c3c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<3.12,>=3.10",
            "size": 106558,
            "upload_time": "2024-02-16T21:28:19",
            "upload_time_iso_8601": "2024-02-16T21:28:19.468388Z",
            "url": "https://files.pythonhosted.org/packages/1d/28/9853842fdb8f8956d0ae104199963f64b1456f967507028d4a907d859818/pathier-1.5.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-16 21:28:19",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "matt-manes",
    "github_project": "pathier",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "pathier"
}
        
Elapsed time: 0.18818s