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

#117: Is this the end of Python virtual environments?

Published Thu, Feb 14, 2019, recorded Tue, Feb 12, 2019

Sponsored by pythonbytes.fm/datadog

Brian #1: Goodbye Virtual Environments?

  • by Chad Smith
  • venv’s are great but they introduce some problems as well:
    • Learning curve: explaining “virtual environments” to people who just want to jump in and code is not always easy
    • Terminal isolation: Virtual Environments are activated and deactivated on a per-terminal basis
    • Cognitive overhead: Setting up, remembering installation location, activating/deactivating
  • PEP 582 — Python local packages directory
    • This PEP proposes to add to Python a mechanism to automatically recognize a __pypackages__directory and prefer importing packages installed in this location over user or global site-packages. This will avoid the steps to create, activate or deactivate “virtual environments”. Python will use the __pypackages__ from the base directory of the script when present.
  • Try it now with pythonloc
    • pythonloc is a drop in replacement for python and pip that automatically recognizes a __pypackages__ directory and prefers importing packages installed in this location over user or global site-packages. If you are familiar with node, __pypackages__ works similarly to node_modules.
    • Instead of running python you run pythonloc and the __pypackages__ path will automatically be searched first for packages. And instead of running pip you run piploc and it will install/uninstall from __pypackages__.

Michael #2: webassets

  • Bundles and minifies CSS & JS files
  • Been doing a lot of work to rank higher on the sites
  • That lead me to Google’s Lighthouse
  • Despite 25ms response time to the network, Google thought my site was “kinda slow”, yikes!
  • webassets has integration for the big three: Django, Flask, & Pyramid.
    • But I prefer to just generate them and serve them off disk
          def build_asset(env: webassets.Environment, 
                         files: List[str], 
                         filters: str, 
                         output: str):
              bundle = webassets.Bundle(
                  *files,
                  filters=filters,
                  output=output,
                  env=env
              )
              bundle.build(force=True)
      

Brian #3: Bernat on Python Packaging

Michael #4: What the mock? — A cheatsheet for mocking in Python

  • Nice introduction
  • Some examples
        @mock.patch('work.os')
            def test_using_decorator(self, mocked_os):
                work_on()
        mocked_os.getcwd.assert_called_once()
    

And

        def test_using_context_manager(self):
            with mock.patch('work.os') as mocked_os:
                work_on()
    mocked_os.getcwd.assert_called_once()

Brian #5: Transitions: The easiest way to improve your tech talk

  • By Saron Yitbarek
  • Jeff Atwood of CodingHorror noted “The people who can write and communicate effectively are, all too often, the only people who get heard. They get to set the terms of the debate.”
  • Effectively presenting is part of effective communication.
  • I love the focus of this article. Focused on one little aspect of improving the performance of a tech talk.

Michael #6: Steering council announced

  • Our new leaders are
    • Barry Warsaw
    • Brett Cannon
    • Carol Willing
    • Guido van Rossum
    • Nick Coghlan
  • Via Joe Carey
  • We both think it’s great Guido is on the council.

Extras:

Joke:

From the list from Ant, my votes.

  • Q: What's the second movie about a database engineer called? A: The SQL.

  • !false It's funny 'cause it's true.

  • A programmer's spouse tells them, "Run to the store and pick up a loaf of bread. If they have eggs, get a dozen." The programmer comes home with 12 loaves of bread.


Want to go deeper? Check our projects