Skip to content

Latest commit

 

History

History
100 lines (84 loc) · 3.57 KB

2023-11-14.md

File metadata and controls

100 lines (84 loc) · 3.57 KB

2023-11-14 -- Virtual

Tim on adding CLI to module

  • A good example: python -m rich.emoji
  • Can be used to show what the module can do
  • Probably best not to have a fully-fledged CLI

Tim on monkey patching non-test code

A word of warning: monkey patching is useful when it is required, but it's a very deep topic (and not really suitable for a lightning talk; sorry!). Presented below is just one small example of needing a 3rd-party library to act just a little bit differently, without said 3rd-party library being aware.

  • Use case: Robot Framework
  • RF doesn't only use standard logger
  • Tim needs the ability to keep sensitive data (basic authentication) from log files
  • Only way (maybe?) was to monkey patch the 3rd party functions in all places to insert code.

Steps taken:

  1. Find all of the module imports in the 3rd party library
  2. Make a local copy of the original functions
  3. Create identical function signatures
  4. "monkey patch" each use of the 3rd party function with the new function.

This is fraught with peril, and is very fragile. This is one was to get around poor library design (imo).

Quick example:

import copy

# import all of the library you need to patch
import robot.libraries.BuiltIn
import robot.output.listenerarguments

# Make a copy of the original function
orig_safe_str = copy.deepcopy(robot.utils.unic)

# Create a new function **with the same interface** as the one you are replacing
def safe_str(item):
    result = orig_safe_str(item)
    return redact_sensitive_text(result)

# Tell Python to use _your_ function anytime the 3rd part library tries to
# call it.
robot.libraries.BuiltIn.safe_str = safe_str
robot.output.listenerarguments.safe_str = safe_str

General discussion

  • dn talked about Big Blue Button web-conferencing as a possible alternative to Google Meet
  • We talked about various fonts used for terminals and editors
    • Fira Code
    • Geist
    • JetBrains mono
    • IBM Plex
  • What your terminal can display is also based on the font you use
  • Tim talked about using Ansible to configure the terminal
  • We talked about a few projects being used to "keep us in the terminal"

Relevant Chat Log

Scott 6:01 PM
Howdy
Tim 6:07 PM
https://github.com/pysprings/lightning-talks/tree/master/robotframework
Scott 6:12 PM
I'm not on mic or camera this evening. I'm still learning Python and just hoping to listen and learn something new.
Tim 6:12 PM
Hey, Scott!
Ryan 6:12 PM
Welcome Scott!
dn 6:15 PM
Big Blue Button web-conferencing https://bigbluebutton.org/
Tim 6:19 PM
fira code font
Tim 6:20 PM
https://rich.readthedocs.io/en/stable/introduction.html
dn 6:23 PM
Good terminal/IDE mono fonts: Fira, Geist, JetBrains mono, IBM Plex
dn 6:25 PM
Now I recall (last meeting): was wanting to ask if could copy/adapt/borrow your terminal prompt colors (ASCII Escape Codes)
Tim 6:51 PM
https://github.com/mtik00/ansible-role-zsh/tree/main
Tim 6:53 PM
https://github.com/mtik00/ansible-role-zsh/tree/main/tasks
Tim 6:56 PM
https://github.com/tiangolo/typer
Ryan Freckleton6:57 PM
https://www.visidata.org/
Tim 6:58 PM
https://textual.textualize.io/
dn 6:58 PM
Thanks guys!
Scott 6:58 PM
Thank you all.
I'm now scared to ever use monkey patching.

back