PyClean

Clean up your Python bytecode & more.

pip install pyclean

 

PyCon X, Firenze 2019

PyClean

pyclean
py3clean
pypyclean

Bytecode

def foo(bar):
    print(bar)

foo.__code__.co_code

\x00\x00\x83\x01
\x01\x00\x00\x00

 __pycache__/foo.pyc

Don't want this in my (Debian) package.

 

python-defaults/pyclean (salsa.debian.org)

python3-defaults/py3clean (salsa.debian.org)

debian/scripts/pypyclean (salsa.debian.org)

github.com/bittner/pyclean

 

 Debian, mother of things

 Clean Code, Clean Pkg

 $ py3clean -v .

 

  • Code duplication
  • Debian only + dependencies
  • No PyPy3
  • No tests
  • Limited benefit

 

 What's broken?

# tox.ini
[tox]
envlist = py27,py37,clean

[testenv]
...

[testenv:clean]
deps = pyclean
commands = pyclean {toxinidir} --debris tox

 How could we use it?

# tox.ini
[testenv:clean]
commands =
    py3clean {toxinidir}
    find . -name foo -delete
    rm -rf .pytest_cache/ .tox/ *.egg-info
whitelist_externals =
    py3clean
    find
    rm

 

Contributors wanted!

 

Thank you!

for your precious time

Painless Software

Less pain, more fun.

PyClean - Clean up your Python bytecode & more

By Peter Bittner

PyClean - Clean up your Python bytecode & more

Bytecode is opcodes for the Python Virtual Machine. The *.pyc files and __pycache__ folders in your directory tree. On Debian there's pyclean to clean it all up when developing. We need to make this available on all platforms.

  • 4,037