馃悕 Python

Notes to self, snippets etc.

November 28, 2022 路 3 min

Installing Poetry system-wide

I recently got some feedback (thank you @simmel, much appreciated!) on a previous post on 2021-04-17-debugging-poetry. I then realized it was a bit hard to follow if all you wanted to do was to install Poetry globally, with some added control from the default installation method. This post aims to focus on this and cover the different system-wide installation alternatives that I am aware of. System-wide install with pipx You can very easily make Poetry available system-wide, by just following the installation docs....

November 13, 2021 路 3 min
Visual Studio Code

Debugging Poetry with Visual Studio Code

A guide on how to set up debugging of Poetry in Visual Studio Code, using Pipx and Pyenv. Prerequisites My developer environment is Ubuntu 20.04 via WSL2 running on Windows 10, so that鈥檚 what this guide is written for. In order to get set for debugging, we need to install/setup a couple of tools: Pyenv - Python version management Pipx - install and run Python applications in isolated environments Poetry - you should know what this is, if you are reading this ;) Pyenv I like to pick the Python interpreter version for a system-wide installations of tools, but also for individual projects using Pyenv....

April 17, 2021 路 5 min
Visual Studio Code

Encoding UUIDs with base62

A simple and homegrown UUID base62 encoding/decoding implementation.

January 8, 2021 路 2 min

Nuke gizmos to groups

Recursively replace all gizmos in Nuke script with a group. The only exception is the Cryptomatte nodes, which will be maintained as gizmos. Copy-paste the below code into the Nuke script editor and run. import uuid import nuke def is_gizmo(node): """Return True if given node is a gizmo (and not allowed gizmo type)""" allowed_gizmo_classes = ('Cryptomatte') for knob in node.knobs(): if 'gizmo' in knob and node.Class() not in allowed_gizmo_classes: return True def get_gizmo_names(): """Return the fullName attribute for all gizmos in script""" gizmos = [] all_nodes = nuke....

June 25, 2018 路 1 min

Distributing Python script(s) as zip file

A recent discussion on 3DPRO sparked me to scribble down some ideas on how to somewhat painlessly distribute a Python package to be run in DCC applications such as Maya or Nuke as simply as possible. So this is an alternative to building a wheel and mucking around with virtual environments. You can make Python import your modules or packages even when zipped. Example, where b is our package and c....

June 7, 2018 路 2 min

Google Hangouts Chat incoming webhook using Python standard library only

The official docs on setting up an incoming webhook uses the third-party httplib2, which is not part of the Python 3.6 standard library. Here鈥檚 a quick snippet using only the standard library instead: import json import urllib.parse import urllib.request def main(): # python 3.6 url = '<INCOMING-WEBHOOK-URL>' bot_message = {'text': 'Hello from Python script!'} message_headers = {'Content-Type': 'application/json; charset=UTF-8'} byte_encoded = json.dumps(bot_message).encode('utf-8') req = urllib.request.Request(url=url, data=byte_encoded, headers=message_headers) response = urllib.request.urlopen(req) print(response....

June 6, 2018 路 1 min

Cartesian product in Python

A cartesian product operation can return a set of 鈥渃ombinations鈥 based on given values, so for example I could have the following values: a b c 1 1 1 2 2 3 I would then expect the cartesian product operation to return something like a1b1c1, a1b1c2, a1b1c3, a1b2c1 and so on鈥 Many, many times have had to solve this problem over and over in Python鈥 it鈥檚 time to jot down some notes....

April 18, 2018 路 2 min

Official PySide2 wheels!

The Qt Company has released official and pip-installable PySide2 wheel snapshots! Simo posted the details today on the PySide mailing list, but in a nutshell: pip install --index-url=http://download.qt.io/snapshots/ci/pyside/5.9/latest/ pyside2 --trusted-host download.qt.io Update 2018-04-05: official docs are now also online at https://doc-snapshots.qt.io/qtforpython/ Update 2018-07-17: PySide2 can now be installed from pypi.org: pip install PySide2!

March 9, 2018 路 1 min

Standalone PySide2 wheels

The Qt Company has yet to release official, standalone and pip-installable PySide2 wheels. However, since they made it possible to build standalone wheels successfully, I鈥檓 now building such unofficial, standalone wheels here using free CI services (thanks Travis and AppVeyor!): fredrikaverpil/pyside2-windows fredrikaverpil/pyside2-macos fredrikaverpil/pyside2-linux Update 2018-03-09: The Qt Company now offers official and standalone wheels, read more here: 2018-03-09-official-pyside2-wheels Update 2018-07-17: PySide2 can now be installed from pypi.org: pip install PySide2!...

February 20, 2018 路 2 min