[EN] Extracting setup_requires dependencies out of a setup.py

I ended up not using this code, but it may be useful to others: mock_setup_provider.py: import sys from unittest.mock import Mock class MockSetupProvider(Mock): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.captured_setup_requires = set() def setup(self, *args, **kwargs): self.captured_setup_…

[EN] Record an existing voicemail message with Python & Twilio

Last week, my father asked me if I could find make a backup of an old lovely voicemail message he had. I wrote a short Python script to accomplis this: twiml_url = 'https://handler.twilio.com/twiml/EH9515e9e0d2fb81f27d75a493225ae703' client = Client(os.environ['TWILIO_ACCOUNT_SID'], os.environ['TWILIO_AUTH_TOKEN']…

[EN] Solarized mindmaps with Python and graphviz

This week I wrote a small Python script, heavily inspired by this Treemap plugin for Zim wiki, and using Ethan Schoonover solarized palette, that can generate a mindmap from a simple indented text input like this: Winter december january february Spring march april may Summer june july august Autumn september…

[EN] Command history in a Python 3 virtualenv

Due to a long standing bug, no history file will be kept of the commands you enter in an interactive shell when using a Python 3 virtualenv. I found out a simple workaround. Simply put the following in your ~/.pythonrc : import atexit, os, readline, sys if sys.version_info >…

[EN] TIL zip files can contain comments

... and the standard UNIX tool zipinfo cannot display them ! So here is Python one-liner to extract them, and other useful meta informations: python -c "import json, sys, zipfile; json.dump([{k: str(getattr(i, k)) for k in zipfile.ZipInfo.__slots__} for i in zipfile.ZipFile(sys.argv[1]).infolist(…

[EN] Colored diff output with Python

Say you are generating a colored diff output with the standard difflib Python package: diff = difflib.ndiff(file1_lines, file2_lines) print('\n'.join(diff)) Now, I'll show you how to write a simple color_diff function that you can use to color your diff like this: diff = difflib.…