Brought to you by Michael and Brian - take a Talk Python course or get Brian's pytest book

#279: Autocorrect and other Git Tricks

Published Fri, Apr 15, 2022, recorded Tue, Apr 12, 2022
Watch this episode on YouTube
Play on YouTube
Watch the live stream replay

About the show

Sponsored by Datadog: pythonbytes.fm/datadog

Special guest: Brian Skinn (Twitter | Github)

Michael #1: OpenBB wants to be an open source challenger to Bloomberg Terminal

  • OpenBB Terminal provides a modern Python-based integrated environment for investment research, that allows an average joe retail trader to leverage state-of-the-art Data Science and Machine Learning technologies.
  • As a modern Python-based environment, OpenBBTerminal opens access to numerous Python data libraries in
    • Data Science (Pandas, Numpy, Scipy, Jupyter)
    • Machine Learning (Pytorch, Tensorflow, Sklearn, Flair)
    • Data Acquisition (Beautiful Soup, and numerous third-party APIs)
  • They have a discord community too
  • BTW, seem to be a successful open source project: OpenBB Raises $8.5M in Seed Round Funding Following Open Source Project Gamestonk Terminal's Success
  • Great graphics / gallery here.
  • Way more affordable than the $1,900/mo/user for the Bloomberg Terminal

Brian #2: Python f-strings

Brian S. #3: pyproject.toml and PEP 621 Support in setuptools

  • PEP 621: “Storing project metadata in pyproject.toml”
    • Authors: Brett Cannon, Dustin Ingram, Paul Ganssle, Pradyun Gedam, Sébastien Eustace, Thomas Kluyver, Tzu-ping Chung (Jun-Oct 2020)
    • Covers build-tool-independent fields (name, version, description, readme, authors, etc.)
  • Various tools had already implemented pyproject.toml support, but not setuptools
  • setuptools support had been discussed pretty extensively, and had been included on the PSF’s list of fundable packaging improvements
  • Initial experimental implementation spearheaded by Anderson Bravalheri, recently completed
    • Seeking testing and bug reports from the community (Discuss thread)
    • I tried it on one of my projects — it mostly worked, but revealed a bug that Anderson fixed super-quick (proper handling of a dynamic long_description, defined in setup.py)
  • Related tools (all early-stage/experimental AFAIK)
    • ini2toml (Anderson Bravalheri) — Can convert setup.cfg (which is in INI format) to pyproject.toml
      • Mostly worked well for me, though I had to manually fix a couple things, most of which were due to limitations of the INI format
        • INI has no list syntax!
    • validate-pyproject (Anderson Bravalheri) — Automated pyproject.toml checks
    • pyproject-fmt (Bernát Gábor) — Autoformatter for pyproject.toml
  • Don’t forget to use it with build, instead of via a python setup.py invocation!
    • $ pip install build $ python -m build
  • Will also want to constrain your setuptools version in the build-backend.requires key of pyproject.toml (you are using PEP517/518, right??)

Michael #4: JSON Web Tokens @ jwt.io

  • JSON Web Tokens are an open, industry standard RFC 7519 method for representing claims securely between two parties.
  • Basically a visualizer and debugger for JWTs
    • Enter an encoded token
    • Select a decryption algorithm
    • See the payload data
    • verify the signature
  • List of libraries, grouped by language

Brian #5: Autocorrect and other Git Tricks

- Waylon Walker
- Use `git config --global help.autocorrect 10` to have git automatically run the command you meant in 1 second. The `10` is 10 x 1/10 of a second. So `50` for 5 seconds, etc.

  • Automatically set upstream branch if it’s not there
    • git config --global push.default current
    • You may NOT want to do this if you are not careful with your branches.
    • From https://stackoverflow.com/a/22933955
  • git commit -a
    • Automatically “add” all changed and deleted files, but not untracked files.
    • From https://git-scm.com/docs/git-commit#Documentation/git-commit.txt--a
  • Now most of my interactions with git CLI, especially for quick changes, is: $ git checkout main $ git pull $ git checkout -b okken_something $ git commit -a -m 'quick message' $ git push
  • With these working, with autocorrect $ git chkout main $ git pll $ git comit -a -m 'quick message' $ git psh

Brian S. #6: jupyter-tempvars

  • Jupyter notebooks are great, and the global namespace of the Python kernel backend makes it super easy to flow analysis from one cell to another
  • BUT, that global namespace also makes it super easy to footgun, when variables leak into/out of a cell when you don’t want them to
  • jupyter-tempvars notebook extension
    • Built on top of the tempvars library, which defines a TempVars context manager for handling temporary variables
      • When you create a TempVars context manager, you provide it patterns for variable names to treat as temporary
      • In its simplest form, TempVars (1) clears matching variables from the namespace on entering the context, and then (2) clears them again upon exiting the context, and restoring their prior values, if any
      • TempVars works great, but it’s cumbersome and distracting to manually include it in every notebook cell where it’s needed
    • With jupyter-tempvars, you instead apply tags with a specific format to notebook cells, and the extension automatically wraps each cell’s code in a TempVars context before execution
  • Javascript adapted from existing extensions
  • See the README (with animated GIFs!) for installation and usage instructions
    • It’s on PyPI: $ pip install jupyter-tempvars
    • And, I made a shortcut install script for it: $ jupyter-tempvars install && jupyter-tempvars enable
  • Please try it out, find/report bugs, and suggest features!
  • Future work
    • Publish to conda-forge (definitely)
    • Adapt to JupyterLab, VS Code, etc. (pending interest)

Extras

Brian:

Michael:

Brian S.:

Jokes:

https://twitter.com/CaNerdIan/status/1512628780212396036

https://www.reddit.com/r/ProgrammerHumor/comments/tuh06y/i_guess_we_all_have_been_there/

https://twitter.com/PR0GRAMMERHUM0R/status/1507613349625966599


Want to go deeper? Check our projects