pycomfort


Namepycomfort JSON
Version 0.0.17 PyPI version JSON
download
home_pagehttps://github.com/antonkulaga/pycomfort
SummaryPython helper methods to make life easier
upload_time2025-01-06 11:39:54
maintainerNone
docs_urlNone
authorAnton Kulaga
requires_python<4.0,>=3.10
licenseApache-2.0
keywords python utils files
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pycomfort

A Python utility library that provides convenient methods for file operations and text manipulation using a functional programming approach.

## Installation

Install using pip:

Or preferably using Poetry:

## Features

### File Operations
The library provides functional-style methods for file system operations using the pyfunctional library:

### Key Functions

#### File System Operations
- `children(p: Path) -> seq` - Lists files and subfolders as pyfunctional sequence
- `dirs(p: Path) -> seq` - Lists subfolders as pyfunctional sequence
- `files(p: Path) -> seq` - Lists files as pyfunctional sequence
- `with_ext(p: Path, ext: str) -> seq` - Filters files by extension

#### File Manipulation
- `rename_files_with_dictionary(files_or_path, dictionary, test=False)` - Batch rename files using a dictionary
- `replace_in_file(file, what, to, output=None)` - Replace text in files
- `replace_from_dict_in_file(file, replacement, output=None)` - Replace multiple patterns using a dictionary

#### Extended Logging Features (based on Eliot logging library)
- `to_nice_stdout(output_file: Optional[Path])` - Configure Eliot logging with improved rendering to stdout
- `to_nice_file(output_file: Path, rendered_file: Path)` - Configure Eliot logging with improved rendering to separate files
- `log_function` decorator - Enhanced function logging with timing and argument tracking

### Examples

Some examples of how to use the library.

#### Get all Python files and print their names

```python
print(files("test"))
python_files = with_ext("test", ".py") #get all python files in current directory
python_files.map(lambda p: p.name).for_each(print) #print all python files names
```

Replace multiple patterns in all markdown files:
```python
replacements = {
"# TODO": "# DONE",
"- [ ]": "- [x]"
}
with_ext("docs", ".md").for_each(lambda f: replace_from_dict_in_file(f, replacements))
```

#### Pretty print directory structure:

```python
tprint("project", max_depth=2, debug=True)
```

#### Chain operations to process specific files:

```python
(dirs("src")
.flat_map(lambda d: with_ext(d, ".py"))
.filter(lambda p: p.stat().st_size > 1000)
.for_each(lambda f: replace_in_file(f, "old", "new")))
```


#### Function Logging with Decorator

```python
from pycomfort.logging import log_function, LogLevel
@log_function(
include_args=True,
include_result=True,
log_level=LogLevel.INFO,
include_timing=True
)
def process_data(data):
    # Some processing logic
    return data

process_data(123)
```

The decorator will log:
- Function entry with arguments
- Execution time
- Return value
- Any errors that occur

You can output logs in hirarcial way bu registering the logger file destinations using the `to_nice_stdout` or `to_nice_file` functions.
```python
to_nice_file(
output_file=Path("logs/output.json"),
rendered_file=Path("logs/readable.log")
)
```

#### Basic Logging Setup

### CLI Tools

The package provides command-line tools for text replacement:

## Development Setup

1. Clone the repository:

2. Install poetry if you haven't:

3. Install dependencies:

4. Run tests:

## Publishing

To publish a new version to PyPI:

1. Update version in pyproject.toml
2. Run the publish script:

## License

Apache License 2.0 - See LICENSE file for details.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/antonkulaga/pycomfort",
    "name": "pycomfort",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.10",
    "maintainer_email": null,
    "keywords": "python, utils, files",
    "author": "Anton Kulaga",
    "author_email": "antonkulaga@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/7c/54/203462164b7f5625e580ec480e4c67562a4fe6b1e71d73011179c287aba4/pycomfort-0.0.17.tar.gz",
    "platform": null,
    "description": "# pycomfort\n\nA Python utility library that provides convenient methods for file operations and text manipulation using a functional programming approach.\n\n## Installation\n\nInstall using pip:\n\nOr preferably using Poetry:\n\n## Features\n\n### File Operations\nThe library provides functional-style methods for file system operations using the pyfunctional library:\n\n### Key Functions\n\n#### File System Operations\n- `children(p: Path) -> seq` - Lists files and subfolders as pyfunctional sequence\n- `dirs(p: Path) -> seq` - Lists subfolders as pyfunctional sequence\n- `files(p: Path) -> seq` - Lists files as pyfunctional sequence\n- `with_ext(p: Path, ext: str) -> seq` - Filters files by extension\n\n#### File Manipulation\n- `rename_files_with_dictionary(files_or_path, dictionary, test=False)` - Batch rename files using a dictionary\n- `replace_in_file(file, what, to, output=None)` - Replace text in files\n- `replace_from_dict_in_file(file, replacement, output=None)` - Replace multiple patterns using a dictionary\n\n#### Extended Logging Features (based on Eliot logging library)\n- `to_nice_stdout(output_file: Optional[Path])` - Configure Eliot logging with improved rendering to stdout\n- `to_nice_file(output_file: Path, rendered_file: Path)` - Configure Eliot logging with improved rendering to separate files\n- `log_function` decorator - Enhanced function logging with timing and argument tracking\n\n### Examples\n\nSome examples of how to use the library.\n\n#### Get all Python files and print their names\n\n```python\nprint(files(\"test\"))\npython_files = with_ext(\"test\", \".py\") #get all python files in current directory\npython_files.map(lambda p: p.name).for_each(print) #print all python files names\n```\n\nReplace multiple patterns in all markdown files:\n```python\nreplacements = {\n\"# TODO\": \"# DONE\",\n\"- [ ]\": \"- [x]\"\n}\nwith_ext(\"docs\", \".md\").for_each(lambda f: replace_from_dict_in_file(f, replacements))\n```\n\n#### Pretty print directory structure:\n\n```python\ntprint(\"project\", max_depth=2, debug=True)\n```\n\n#### Chain operations to process specific files:\n\n```python\n(dirs(\"src\")\n.flat_map(lambda d: with_ext(d, \".py\"))\n.filter(lambda p: p.stat().st_size > 1000)\n.for_each(lambda f: replace_in_file(f, \"old\", \"new\")))\n```\n\n\n#### Function Logging with Decorator\n\n```python\nfrom pycomfort.logging import log_function, LogLevel\n@log_function(\ninclude_args=True,\ninclude_result=True,\nlog_level=LogLevel.INFO,\ninclude_timing=True\n)\ndef process_data(data):\n    # Some processing logic\n    return data\n\nprocess_data(123)\n```\n\nThe decorator will log:\n- Function entry with arguments\n- Execution time\n- Return value\n- Any errors that occur\n\nYou can output logs in hirarcial way bu registering the logger file destinations using the `to_nice_stdout` or `to_nice_file` functions.\n```python\nto_nice_file(\noutput_file=Path(\"logs/output.json\"),\nrendered_file=Path(\"logs/readable.log\")\n)\n```\n\n#### Basic Logging Setup\n\n### CLI Tools\n\nThe package provides command-line tools for text replacement:\n\n## Development Setup\n\n1. Clone the repository:\n\n2. Install poetry if you haven't:\n\n3. Install dependencies:\n\n4. Run tests:\n\n## Publishing\n\nTo publish a new version to PyPI:\n\n1. Update version in pyproject.toml\n2. Run the publish script:\n\n## License\n\nApache License 2.0 - See LICENSE file for details.\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "Python helper methods to make life easier",
    "version": "0.0.17",
    "project_urls": {
        "Homepage": "https://github.com/antonkulaga/pycomfort",
        "Repository": "https://github.com/antonkulaga/pycomfort"
    },
    "split_keywords": [
        "python",
        " utils",
        " files"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a284f1ec673a5653edceeb495e526d173bb77a06d596f2b86444529c0ba379ae",
                "md5": "4a6c12a1d57933c5a464c3e5c3bcbd6f",
                "sha256": "9da8cde93898f5b4f185032af1732ddb3fc76842e18e8b4923fce0c63559e472"
            },
            "downloads": -1,
            "filename": "pycomfort-0.0.17-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4a6c12a1d57933c5a464c3e5c3bcbd6f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.10",
            "size": 13600,
            "upload_time": "2025-01-06T11:39:52",
            "upload_time_iso_8601": "2025-01-06T11:39:52.408900Z",
            "url": "https://files.pythonhosted.org/packages/a2/84/f1ec673a5653edceeb495e526d173bb77a06d596f2b86444529c0ba379ae/pycomfort-0.0.17-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7c54203462164b7f5625e580ec480e4c67562a4fe6b1e71d73011179c287aba4",
                "md5": "a8caf0f20e5633178565d6f2a997e259",
                "sha256": "31c890f88ebebb665fbeec6b8f8af17f5163d308897f9cfeb6158bb64bcd0606"
            },
            "downloads": -1,
            "filename": "pycomfort-0.0.17.tar.gz",
            "has_sig": false,
            "md5_digest": "a8caf0f20e5633178565d6f2a997e259",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.10",
            "size": 12871,
            "upload_time": "2025-01-06T11:39:54",
            "upload_time_iso_8601": "2025-01-06T11:39:54.963132Z",
            "url": "https://files.pythonhosted.org/packages/7c/54/203462164b7f5625e580ec480e4c67562a4fe6b1e71d73011179c287aba4/pycomfort-0.0.17.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-06 11:39:54",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "antonkulaga",
    "github_project": "pycomfort",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pycomfort"
}
        
Elapsed time: 1.15691s