pytriple


Namepytriple JSON
Version 1.0.0 PyPI version JSON
download
home_pageNone
SummaryPython tool for fixing triple-quoted string indentation
upload_time2025-07-10 06:43:31
maintainerNone
docs_urlNone
authorMartin Kalema
requires_python>=3.8
licenseNone
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pytriple

A Python tool for automatically fixing triple-quoted string indentation while preserving relative indentation structure.

## Features

- **Automatic Detection**: Uses AST parsing to accurately detect multiline strings
- **Preserves Relative Indentation**: Maintains the relative indentation structure within strings, ensuring that the hierarchical structure of SQL, JSON, HTML, YAML, etc. is preserved exactly as the developer intended
- **Clean Architecture**: Built with Domain-Driven Design principles
- **Backup Support**: Creates backups before modifying files (default behavior)
- **CLI Interface**: User-friendly command line interface
- **Comprehensive**: Handles all triple-quoted strings in assignments, returns, and function calls

## Installation

```bash
pip install pytriple
```

## Usage

### Fix a single file
```bash
pytriple fix-file example.py
```

### Fix all files in a directory
```bash
pytriple fix-directory /path/to/project
```

### Check a file without modifying
```bash
pytriple check example.py
```

### Command Options

#### fix-file
- `--no-backup`: Skip creating backup files
- `--dry-run`: Preview changes without modifying files
- `--verbose`, `-v`: Show detailed information about changes

#### fix-directory
- `--no-backup`: Skip creating backup files
- `--dry-run`: Preview changes without modifying files
- `--exclude`: Exclude files matching pattern (can be used multiple times)
- `--verbose`, `-v`: Show detailed output for each file

## Architecture

The project follows clean architecture principles:

- **Domain Layer**: Core business entities and rules
- **Application Layer**: Use cases for fixing files and directories
- **Infrastructure Layer**: File system operations and AST parsing
- **Presentation Layer**: CLI interface

## Example

Before:
```python
class DatabaseManager:
    def __init__(self):
        self.query = """
    SELECT u.id,
        u.username,
            u.email
    FROM users u
        WHERE u.active = 1
        """
```

After:
```python
class DatabaseManager:
    def __init__(self):
        self.query = """
            SELECT u.id,
                u.username,
                u.email
            FROM users u
                WHERE u.active = 1
        """
```

## How It Works

pytriple analyzes Python files using AST (Abstract Syntax Tree) parsing to find triple-quoted strings. It then:

1. Identifies strings where the base indentation doesn't match Python conventions
2. Calculates the minimum indentation level of content lines
3. Adjusts only the base indentation to match the code context (parent indentation + 4 spaces)
4. **Preserves all relative indentation** within the string content
5. Writes the corrected content back to the file

This approach ensures that:
- Python code follows consistent indentation practices
- The internal structure of SQL queries, JSON data, HTML templates, YAML configs, etc. remains exactly as intended
- Complex hierarchical content maintains its readability and structure

## Development

### Setup

```bash
# Clone the repository
git clone https://github.com/MartinKalema/pytriple.git
cd pytriple

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install in development mode
pip install -e .
```

### Running Tests

```bash
python -m pytest tests/
```

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

## License

This project is licensed under the MIT License - see the LICENSE file for details.

## Author

Martin Kalema

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pytriple",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": "Martin Kalema",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/9b/9a/f320e5e2f1fae3020aa2fdeb4230dd9c7bfcc9aec53c4c0a11e1f88ef4cd/pytriple-1.0.0.tar.gz",
    "platform": null,
    "description": "# pytriple\n\nA Python tool for automatically fixing triple-quoted string indentation while preserving relative indentation structure.\n\n## Features\n\n- **Automatic Detection**: Uses AST parsing to accurately detect multiline strings\n- **Preserves Relative Indentation**: Maintains the relative indentation structure within strings, ensuring that the hierarchical structure of SQL, JSON, HTML, YAML, etc. is preserved exactly as the developer intended\n- **Clean Architecture**: Built with Domain-Driven Design principles\n- **Backup Support**: Creates backups before modifying files (default behavior)\n- **CLI Interface**: User-friendly command line interface\n- **Comprehensive**: Handles all triple-quoted strings in assignments, returns, and function calls\n\n## Installation\n\n```bash\npip install pytriple\n```\n\n## Usage\n\n### Fix a single file\n```bash\npytriple fix-file example.py\n```\n\n### Fix all files in a directory\n```bash\npytriple fix-directory /path/to/project\n```\n\n### Check a file without modifying\n```bash\npytriple check example.py\n```\n\n### Command Options\n\n#### fix-file\n- `--no-backup`: Skip creating backup files\n- `--dry-run`: Preview changes without modifying files\n- `--verbose`, `-v`: Show detailed information about changes\n\n#### fix-directory\n- `--no-backup`: Skip creating backup files\n- `--dry-run`: Preview changes without modifying files\n- `--exclude`: Exclude files matching pattern (can be used multiple times)\n- `--verbose`, `-v`: Show detailed output for each file\n\n## Architecture\n\nThe project follows clean architecture principles:\n\n- **Domain Layer**: Core business entities and rules\n- **Application Layer**: Use cases for fixing files and directories\n- **Infrastructure Layer**: File system operations and AST parsing\n- **Presentation Layer**: CLI interface\n\n## Example\n\nBefore:\n```python\nclass DatabaseManager:\n    def __init__(self):\n        self.query = \"\"\"\n    SELECT u.id,\n        u.username,\n            u.email\n    FROM users u\n        WHERE u.active = 1\n        \"\"\"\n```\n\nAfter:\n```python\nclass DatabaseManager:\n    def __init__(self):\n        self.query = \"\"\"\n            SELECT u.id,\n                u.username,\n                u.email\n            FROM users u\n                WHERE u.active = 1\n        \"\"\"\n```\n\n## How It Works\n\npytriple analyzes Python files using AST (Abstract Syntax Tree) parsing to find triple-quoted strings. It then:\n\n1. Identifies strings where the base indentation doesn't match Python conventions\n2. Calculates the minimum indentation level of content lines\n3. Adjusts only the base indentation to match the code context (parent indentation + 4 spaces)\n4. **Preserves all relative indentation** within the string content\n5. Writes the corrected content back to the file\n\nThis approach ensures that:\n- Python code follows consistent indentation practices\n- The internal structure of SQL queries, JSON data, HTML templates, YAML configs, etc. remains exactly as intended\n- Complex hierarchical content maintains its readability and structure\n\n## Development\n\n### Setup\n\n```bash\n# Clone the repository\ngit clone https://github.com/MartinKalema/pytriple.git\ncd pytriple\n\n# Create virtual environment\npython -m venv venv\nsource venv/bin/activate  # On Windows: venv\\Scripts\\activate\n\n# Install in development mode\npip install -e .\n```\n\n### Running Tests\n\n```bash\npython -m pytest tests/\n```\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a Pull Request.\n\n## License\n\nThis project is licensed under the MIT License - see the LICENSE file for details.\n\n## Author\n\nMartin Kalema\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Python tool for fixing triple-quoted string indentation",
    "version": "1.0.0",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "d0311c639b62190b8eeefcf36df3c8a7186ec7ec541bf850efd3b3218d53e845",
                "md5": "627d7360ff9fb7fa8a5c189f13436e34",
                "sha256": "dc0950aa4ce4c189d004a8dc15ec9af5aba583599f1b26618df99bf59c9a6049"
            },
            "downloads": -1,
            "filename": "pytriple-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "627d7360ff9fb7fa8a5c189f13436e34",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 24423,
            "upload_time": "2025-07-10T06:43:29",
            "upload_time_iso_8601": "2025-07-10T06:43:29.948959Z",
            "url": "https://files.pythonhosted.org/packages/d0/31/1c639b62190b8eeefcf36df3c8a7186ec7ec541bf850efd3b3218d53e845/pytriple-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "9b9af320e5e2f1fae3020aa2fdeb4230dd9c7bfcc9aec53c4c0a11e1f88ef4cd",
                "md5": "7eb3af83656614978ed1161cc371524f",
                "sha256": "98bc678e4da9fdbd3fc61f83c1f534ce77f562ce983eb8492dab07c4ae340c79"
            },
            "downloads": -1,
            "filename": "pytriple-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "7eb3af83656614978ed1161cc371524f",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 18272,
            "upload_time": "2025-07-10T06:43:31",
            "upload_time_iso_8601": "2025-07-10T06:43:31.619318Z",
            "url": "https://files.pythonhosted.org/packages/9b/9a/f320e5e2f1fae3020aa2fdeb4230dd9c7bfcc9aec53c4c0a11e1f88ef4cd/pytriple-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-10 06:43:31",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "pytriple"
}
        
Elapsed time: 0.50446s