Metadata-Version: 2.4
Name: pystrip
Version: 1.1.0
Summary: Remove comments and docstrings from Python source files
Author-email: Zeecka <alex.garrido@protonmail.com>
License: MIT License
        
        Copyright (c) 2026 pystrip contributors
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Requires-Python: >=3.11
Requires-Dist: libcst>=1.1.0
Requires-Dist: rich>=13.0.0
Description-Content-Type: text/markdown

# Pystrip

[![CI](https://github.com/pystrip/pystrip/actions/workflows/ci.yml/badge.svg)](https://github.com/pystrip/pystrip/actions/workflows/ci.yml)
[![PyPI](https://img.shields.io/pypi/v/pystrip.svg?cacheSeconds=300)](https://pypi.org/project/pystrip/)
[![Python](https://img.shields.io/pypi/pyversions/pystrip.svg?cacheSeconds=300)](https://pypi.org/project/pystrip/)
[![Issues](https://img.shields.io/github/issues/pystrip/pystrip)](https://github.com/pystrip/pystrip/issues)
[![Pull Requests](https://img.shields.io/github/issues-pr/pystrip/pystrip)](https://github.com/pystrip/pystrip/pulls)
[![Ruff](https://img.shields.io/badge/lint-ruff-46a2f1)](https://github.com/astral-sh/ruff)
[![Ty](https://img.shields.io/badge/type%20check-ty-7c3aed)](https://github.com/astral-sh/ty)

![Banner](docs/banner.png)

Python tool to safely remove comments, docstrings, and type annotations from source files using [libcst](https://libcst.readthedocs.io/).

## Features

- Removes comments (inline and standalone)
- Removes docstrings (module, class, function)
- Removes type annotations (parameter hints, return types, variable annotations)
- Keeps regular string literals untouched
- Supports output formats: `text`, `json`, `sarif`, `gitlab`, `github`
- Works in CI with `--check`
- Supports config discovery and parallel processing

## Installation

```bash
pip install pystrip
```

## Usage

```bash
# Check mode (CI)
pystrip . --check

# Apply changes in place
pystrip ./src/ --in-place
```

```bash
usage: pystrip [-h] [--exclude PATH] [--exclude-glob PATTERN] [--keep-docstrings] [--keep-comments]
               [--keep-type-annotations] [--keep-blank] [--check] [--diff] [--in-place]
               [--output-dir DIR] [--no-recursive] [--jobs N] [--config PATH]
               [--format {text,json,sarif,gitlab,github}] [--quiet] [--verbose]
               [paths ...]

Remove comments, docstrings, and type annotations from Python source files.

positional arguments:
  paths                 Files or directories to process (default: ['.'])

options:
  -h, --help            show this help message and exit
  --exclude PATH        Exclude a file or directory path (repeatable) (default: None)
  --exclude-glob PATTERN
                        Exclude paths by glob pattern (repeatable) (default: None)
  --keep-docstrings     Keep docstrings and only strip comments (default: None)
  --keep-comments       Keep comments and only strip docstrings (default: None)
  --keep-type-annotations
                        Keep type annotations and only strip comments/docstrings (default: None)
  --keep-blank          Keep blank lines introduced by comment removal (default: None)
  --check               Do not write files; exit with code 1 if any file would change (default: False)
  --diff                Print unified diffs for changed files (default: False)
  --in-place            Write stripped output back to each input file (default: False)
  --output-dir DIR      Write changed files into DIR instead of modifying inputs (default: None)
  --no-recursive        Process only direct child files of each directory path (default: True)
  --jobs N              Number of worker processes to use (default: None)
  --config PATH         Load configuration from a specific TOML file (default: None)
  --format {text,json,sarif,gitlab,github}
                        Output format for violations (default: None)
  --quiet               Suppress progress and summary output (default: False)
  --verbose             Print detailed removal diagnostics (default: False)
```

Output example:

```bash
⠇ Processing 10 file(s)...
src/pystrip/__init__.py:1:0: DOCSTRING_REMOVED Module docstring removed
src/pystrip/__main__.py:1:0: DOCSTRING_REMOVED Module docstring removed
...
src/pystrip/visitor.py:1:0: DOCSTRING_REMOVED Module docstring removed
Changed 10 file(s), 63 violation(s), 26 docstring(s), 37 comment(s), 0 annotation(s).
```

## Configuration

Use either `pyproject.toml` (`[tool.pystrip]`) or `.pystrip.toml` (`[pystrip]`).
`pyproject.toml` is recommended when pystrip is part of a project; `.pystrip.toml` is useful for standalone usage.

```toml
[tool.pystrip]
remove_comments = true
remove_docstrings = true
remove_blank_lines = true
remove_type_annotations = true
exclude = ["tests/"]
exclude_glob = ["*.generated.py"]
jobs = 4
```

## Output and CI

```bash
# GitHub annotations
pystrip . --check --format github

# GitLab code-quality report
pystrip . --check --format gitlab > gl-code-quality-report.json
```

## Development

Developer setup, quality checks, and contribution workflow are documented in [docs/development.md](docs/development.md).

## Exit Codes

| Code | Meaning |
|------|---------|
| 0    | Clean (no changes needed) |
| 1    | Changes would be made in `--check` mode |
| 2    | Runtime or CLI error |
