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

#257: Python Launcher - Launching Python Everywhere

Published Thu, Nov 4, 2021, recorded Wed, Nov 3, 2021

Watch the live stream:

Watch this episode on YouTube
Play on YouTube
Watch the live stream replay

About the show

Sponsored by Shortcut

Special guest: Morleh So-kargbo

Michael #1: Django 4.0 beta 1 released

  • Django 4.0 beta 1 is now available.
  • Django 4.0 has an abundance of new features
    • The new *expressions positional argument of UniqueConstraint() enables creating functional unique constraints on expressions and database functions.
    • The new scrypt password hasher is more secure and recommended over PBKDF2.
    • The new django.core.cache.backends.redis.RedisCache cache backend provides built-in support for caching with Redis.
    • To enhance customization of Forms, Formsets, and ErrorList they are now rendered using the template engine.

Brian #2: py - The Python launcher

  • py has been bundled with Python for Windows only since Python 3.3, as py.exe
    • See Python Launcher for Windows
    • I’ve mostly ignored it since I use Python on Windows, MacOS, and Linux and don’t want to have different workflows on different systems.
  • But now Brett Cannon has developed python-launcher which brings py to MacOS and various other Unix-y systems or any OS which supports Rust.
  • Now
    • py is everywhere I need it to be, and I’ve switched my workflow to use it.
  • Usage
    • py : Run the latest Python version on your system
    • py -3 : Run the latest Python 3 version
    • py -3.9 : Run latest 3.9 version
    • py -2.7 : Even run 2.x versions
    • py --``list : list all versions (with py-launcher, it also lists paths)
    • py --``list-paths : py.exe only - list all versions with path
  • Why is this cool? - I never have to care where Python is installed or where it is in my search path. - I can always run any version of Python installed without setting up symbolic links. - Same workflow works on Windows, MacOS, and Linux
    • Old workfow
      • Make sure latest Python is found first in search path, then call python3 -m venv venv
      • For a specific version, make sure python3.8, for example, or python38 or something is in my Path. If not, create it somewhere.
    • New workflow.
      • py -m venv venv - Create a virtual environment with the latest Python installed.
      • After activation, everything happens in the virtual env.
    • Create a specific venv to test something on an older version:
      • py -3.8 venv venv --``prompt '``3.8``'
    • Or even just run a script with an old version
      • py -3.8 script_name.py
    • Of course, you can run it with the latest version also
      • py script_name.py
  • Note: if you use py within a virtual environment, the default version is the one from the virtual env, not the latest.

Morleh #3: Transformers As General-Purpose Architecture

  • The Attention Is All You Need paper first proposed Transformers in June 2017.
  • The Hugging Face (🤗) Transformers package is a popular PYTHON library providing pre-trained models that are extraordinarily useful for various natural language processing (NLP) tasks.
  • It earlier supported only PyTorch, but, in 2019, it supported TensorFlow 2
  • 🤗 Transformers provides the following tasks out of the box: Sentiment analysis, Text generation, Question answering, Filling masked text, Summarization, Language Translation, Feature Extraction.
  • The State of AI Report 2021 (Nathan Beniach and Ian Hogarth) came out in late October, highlighting the role of transformers.
  • "Transformers have emerged as a general-purpose architecture for ML. Not just for Natural Language Processing, but also Speech, Computer Vision or even protein structure prediction."
  • Transformers are fulfilling the Transfer Learning promise, saving training time and costs.
  • 🤗 Transformers has a partnership with AWS to make it easier to leverage Machine Learning models.

Michael #4: Model bakery

  • Model Bakery offers you a smart way to create fixtures for testing in Django.
  • Usage example - generates a randomly populated Django Model (DB Entity)
  • If you’re not comfortable with random data or even if you just want to improve the semantics of the generated data, there’s hope for you. Use recipes.

Brian #5: Coverage goals, goals.py

  • Ned Batchelder
  • Ned wrote goals.py as a proof of concept to try out a feature request for coverage.py
  • Allows something like “100% coverage in tests and 85% in product code” requirements.
  • You give it a percentage number, and a list of glob patterns, and the return code indicates failure.
  • You can run it several times on the same coverage output to have complex requirements.
  • Example
    # We want to make sure all tests are run
    $ python goals.py --group 100 'tests/*.py'
    
    # Check all Python files collectively, except in the tests/ directory.
    $ python goals.py --group 85 '**/*.py' '!tests/*.py'
    
    # We definitely want complete coverage of anything related to html.
    $ python goals.py --group 100 '**/*html*.py'
    
    # No Python file should be below 90% covered.
    $ python goals.py --file 90 '**/*.py'
    

Morleh #6: Web3.py

  • Web3.py is the PYTHON library for interacting with the Ethereum Blockchain.
  • Web3.py lets you develop clients that interact with the Ethereum Blockchain.
  • Web3.py is a collection of libraries that enable you to create Ethereum transactions.
  • It is found in decentralized apps (dapps) to help with sending transactions, interacting (write or read) with and executing smart contracts or business logic.

Extras

Michael:

  • mcfly update
  • PWC 2022 - extended the Call for Papers until Monday, Nov. 15
  • Anker GAN charger for M1s - Anker Nano II 65W
  • And Ars view of the new M1s **
    • Rest assured: If you didn't like the direction Apple has been taking with the MacBook Pro for the last five years, this laptop mostly feels like an explicit apology for all of that. The result: It's the best laptop money can buy for many use cases, provided you have a lot of money.
  • M1 vs. M1 Max perf comparison

Joke: Competing standards


Want to go deeper? Check our projects