Skip to main content

Remove unsightly non-whitespace characters from your code.

Project description

Bleach

Read the documentation at https://acme-bleach.readthedocs.io/

Remove unsightly visible characters from your code. Inspired by the Acme::Bleach Perl module by Damian Conway.

Installation

You can install Bleach via pip from PyPI:

$ pip install acme-bleach

Usage

Let's start with the following Python script, hello.py:

print("Hello, world!")

Bleaching

To bleach it, run the following command:

$ bleach bleach hello.py -o hello-bleached.py

The result is a bleached version of the original script. The contents of hello-bleached.py are (representing tabs with »»»» and spaces with ·):

# coding=bleach
»»»»···»»»»»»»»»»»»»»»»»···»»»»»·»»»»»»»··»»·»»»»»»»·»»»··»»···»»»»»···»·»»»»»»»
»»»»»»»»·»»»·»»»»»»»»»»»»»»»»»»»·»»»»»»»»»»»·»»»»»»»·»»»»»»»·»»»»»»»»»»»»»»»··»»»»»»·»»»·»»»··»»··»»»»»»
»»»»··»»··»»»»»»»»»»··»»····»»»»»»»»·»»»··»»»»»»»»»»»»»»·»»»»»»»»»»»»»»»»»»»»»»»···»···
»»»»··»»····»»»»···»»»»»·»»»»»»»··»»··»»»»»»»»»»··»»»»»»·»»»»»»»»»»»»»»»·»»»»»»»»»»»»»»»·
»»»»»»»»·»»»»»»»»»»»·»»»»»»»»»»»·»»»·»»»»»»»·»»»»»»»»»»»»»»»·»»»·»»»

Running

You can run the bleached file using bleach run:

$ bleach run hello-bleached.py
Hello, world!

Unbleaching

You can unbleach the file using bleach unbleach:

$ bleach unbleach hello-bleached.py -o hello-unbleached.py
$ cat hello-unbleached.py
print("Hello, world!")

Installing the bleach codec

Running scripts with bleach run is far too much effort. If you want to run bleached scripts directly, you can install the bleach codec:

$ bleach install
Wrote /home/stefans/bleach/.venv/lib/python3.10/site-packages/bleach.pth
$ python hello-bleached.py
Hello, world!

Installing the codec will attempt to write a .pth file to the site-packages directory of the current Python interpreter. Note the import in the .pth file will be evaluated every time the current Python runs, so there is a tiny amount of overhead.

License

Distributed under the terms of the MIT license, Bleach is free and open source software.

Credits

This project was generated from a variant of @cjolowicz's Hypermodern Python Cookiecutter template.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

acme_bleach-0.2.3.tar.gz (6.5 kB view hashes)

Uploaded Source

Built Distribution

acme_bleach-0.2.3-py3-none-any.whl (7.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page