# coveo-systools
Language and OS related utilities.
Content in a nutshell:
- enhanced subprocess calls
- asyncio subprocess calls
- file and app finding made easy
- safe text write and replace-if-different
- git-repo-root locator
- bool platforms `if WINDOWS or LINUX or MAC or WSL:`
# searching the filesystem
```python
import os
from coveo_systools.filesystem import find_paths, find_application, find_repo_root
os.getcwd()
# '/code/coveo-python-oss/coveo-systools'
find_application('git')
# WindowsPath('C:/Program Files/Git/cmd/git.EXE') # windows example for completeness
find_repo_root()
# Path('/code/coveo-python-oss')
list(find_paths('pyproject.toml', search_from=find_repo_root(), in_root=True, in_children=True))
# [Path('/code/coveo-python-oss/pyproject.toml'), ...]
```
# enhanced subprocess calls
An opinionated version of `subprocess.check_call` and `subprocess.check_output`.
_New in 2.0.7_: asyncio support, through `async_check_call` and `async_check_output`.
Adds the following features:
- command line is a variable args (instead of a list)
- automatic conversion of output to a stripped string (instead of raw bytes)
- automatic conversion of Path, bytes and number variables in command line
- automatic filtering of ansi codes from the output
- enhanced DetailedCalledProcessError on error (a subclass of the typical CalledProcessError)
```python
from pathlib import Path
from coveo_systools.subprocess import check_call
check_call('mypy', '--config-file', Path('configs/mypy.ini'), verbose=True)
```
# safe I/O, if changed
Good programming practices requires files to be saved using a temporary filename and then renamed.
This helper takes it a step further by skipping the write operation if the content did not change:
```python
import json
from pathlib import Path
from coveo_systools.filesystem import safe_text_write
safe_text_write(Path('./path/to/file.txt'), json.dumps(...), only_if_changed=True)
```
# conditional platforms syntactic sugar
Readability is important, not repeating yourself is important.
Forget about `platform.platform()` and use bools directly:
```python
from coveo_systools.platforms import WINDOWS, LINUX, IOS, WSL
if WINDOWS or WSL:
print("Hello Windows!")
elif LINUX or IOS:
print("Hello Unix!")
```
Raw data
{
"_id": null,
"home_page": "https://github.com/coveooss/coveo-python-oss/tree/main/coveo-systools",
"name": "coveo-systools",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": null,
"author": "Jonathan Pich\u00e9",
"author_email": "tools@coveo.com",
"download_url": "https://files.pythonhosted.org/packages/47/39/1a7f8c542f60be238debd4d2b14e75b769f7af7d119e2db9cd3bc232fc0f/coveo_systools-2.0.18.tar.gz",
"platform": null,
"description": "# coveo-systools\n\nLanguage and OS related utilities.\n\n\nContent in a nutshell:\n\n- enhanced subprocess calls\n- asyncio subprocess calls\n- file and app finding made easy\n- safe text write and replace-if-different\n- git-repo-root locator\n- bool platforms `if WINDOWS or LINUX or MAC or WSL:`\n\n\n# searching the filesystem\n\n```python\nimport os\nfrom coveo_systools.filesystem import find_paths, find_application, find_repo_root\n\nos.getcwd()\n# '/code/coveo-python-oss/coveo-systools'\n\nfind_application('git')\n# WindowsPath('C:/Program Files/Git/cmd/git.EXE') # windows example for completeness\n\nfind_repo_root()\n# Path('/code/coveo-python-oss')\n\nlist(find_paths('pyproject.toml', search_from=find_repo_root(), in_root=True, in_children=True))\n# [Path('/code/coveo-python-oss/pyproject.toml'), ...]\n```\n\n# enhanced subprocess calls\n\nAn opinionated version of `subprocess.check_call` and `subprocess.check_output`.\n\n_New in 2.0.7_: asyncio support, through `async_check_call` and `async_check_output`.\n\nAdds the following features:\n- command line is a variable args (instead of a list)\n- automatic conversion of output to a stripped string (instead of raw bytes)\n- automatic conversion of Path, bytes and number variables in command line\n- automatic filtering of ansi codes from the output\n- enhanced DetailedCalledProcessError on error (a subclass of the typical CalledProcessError)\n\n```python\nfrom pathlib import Path\nfrom coveo_systools.subprocess import check_call\n\ncheck_call('mypy', '--config-file', Path('configs/mypy.ini'), verbose=True)\n```\n\n\n# safe I/O, if changed\n\nGood programming practices requires files to be saved using a temporary filename and then renamed.\nThis helper takes it a step further by skipping the write operation if the content did not change: \n\n```python\nimport json\nfrom pathlib import Path\nfrom coveo_systools.filesystem import safe_text_write\n\nsafe_text_write(Path('./path/to/file.txt'), json.dumps(...), only_if_changed=True)\n```\n\n\n# conditional platforms syntactic sugar\n\nReadability is important, not repeating yourself is important.\nForget about `platform.platform()` and use bools directly:\n\n```python\nfrom coveo_systools.platforms import WINDOWS, LINUX, IOS, WSL\n\nif WINDOWS or WSL:\n print(\"Hello Windows!\")\nelif LINUX or IOS:\n print(\"Hello Unix!\")\n```\n",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "Filesystem, language and OS related tools.",
"version": "2.0.18",
"project_urls": {
"Homepage": "https://github.com/coveooss/coveo-python-oss/tree/main/coveo-systools",
"Repository": "https://github.com/coveooss/coveo-python-oss/tree/main/coveo-systools"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "4511f0c91e1fd9f70768c4319f4f322806ab1584e0960068ef422244559f84da",
"md5": "c0cd7d2e47d1f7e83a6fa02a3b34111c",
"sha256": "3ce87b03234cadf15cf41c248148b48887cf58265c601dc8be53cb8f55130903"
},
"downloads": -1,
"filename": "coveo_systools-2.0.18-py3-none-any.whl",
"has_sig": false,
"md5_digest": "c0cd7d2e47d1f7e83a6fa02a3b34111c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 9689,
"upload_time": "2024-03-24T12:46:34",
"upload_time_iso_8601": "2024-03-24T12:46:34.775603Z",
"url": "https://files.pythonhosted.org/packages/45/11/f0c91e1fd9f70768c4319f4f322806ab1584e0960068ef422244559f84da/coveo_systools-2.0.18-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "47391a7f8c542f60be238debd4d2b14e75b769f7af7d119e2db9cd3bc232fc0f",
"md5": "2ce03d8b5ded8500d703df41756847b4",
"sha256": "dea9df3af60b7a66a25f54cf01c999f746676324d57b69e64a6d90dff7b5df97"
},
"downloads": -1,
"filename": "coveo_systools-2.0.18.tar.gz",
"has_sig": false,
"md5_digest": "2ce03d8b5ded8500d703df41756847b4",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 8968,
"upload_time": "2024-03-24T12:46:36",
"upload_time_iso_8601": "2024-03-24T12:46:36.653027Z",
"url": "https://files.pythonhosted.org/packages/47/39/1a7f8c542f60be238debd4d2b14e75b769f7af7d119e2db9cd3bc232fc0f/coveo_systools-2.0.18.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-03-24 12:46:36",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "coveooss",
"github_project": "coveo-python-oss",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "coveo-systools"
}