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

#181: It's time to interrogate your Python code

Published Thu, May 14, 2020, recorded Wed, May 6, 2020

Sponsored by Datadog: pythonbytes.fm/datadog


Brian #1: interrogate: checks your code base for missing docstrings

  • Suggested by Herbert Beemster
  • Written and Maintained by Lynn Root, @roguelynn
  • Having docstrings helps you understand code.
  • They can be on methods, functions, classes, and modules, and even packages, if you put a docstring in __init__.py files.
  • I love how docstrings pop up in editors like VS Code & PyCharm do with them. If you hover over a function call, a popup shows up which includes the docstring for the function.
  • Other tools like Sphinx, pydoc, docutils can generate documentation with the help of docstrings.
  • But good is your project at including docstrings?
  • interrogate is a command line tool that checks your code to make sure everything has docstrings. Neato.
  • What’s missing? -vv will tell you which pieces are covered and not.
  • Don’t want to have everything forced to include docstrings? There are options to select what needs a docstring and what doesn’t.
  • Also can be incorporated into tox testing, and CI workflows.

Michael #2: Streamlit: Turn Python Scripts into Beautiful ML Tools

  • via Daniel Hoadley
  • Many folks come to Python from “scripting” angles
  • The gap between that and interactive, high perf SPA web apps is gigantic
  • Streamlit let’s you build these as if they were imperative top-to-bottom code
  • Really neat tricks make callbacks act like blocking methods
  • Use existing data science toolkits

Brian #3: Why You Should Document Your Tests

  • Hynek Schlawack, @hyneck
  • All test_ methods should include a docstring telling you or someone else the what and why of the test.
  • The test name should be descriptive, and the code should be clear. But still, you can get confused in the future.
  • Hynek includes a great example of a simple test that is not obvious what it’s doing because the test is checking for a side effect of an action.
  • “This is quite common in testing: very often, you can’t ask questions directly. Instead you verify certain properties that prove that your code is achieving its goals.”
  • “If you don’t explain what you’re actually testing, you force the reader (possibly future you) to deduce the main intent by looking at all of its properties. This makes it tiring and time-consuming to quickly scan a file for a certain test or to understand what you’ve actually broken if a test starts failing.”
  • Want to make sure all of your test methods have docstrings?
    • interrogate -vv --fail-under 100 --whitelist-regex "test_.*" tests will do the trick.
  • See also: How to write docstrings for tests

Michael #4: HoloViz project

  • HoloViz is a coordinated effort to make browser-based data visualization in Python easier to use, easier to learn, and more powerful.
  • HoloViz provides:
    • High-level tools that make it easier to apply Python plotting libraries to your data.
    • A comprehensive tutorial showing how to use the available tools together to do a wide range of different tasks.
    • A Conda metapackage "holoviz" that makes it simple to install matching versions of libraries that work well together.
    • Sample datasets to work with.
  • Comprised of a bunch of cool independent projects
  • Panel for making apps and dashboards for your plots from any supported plotting library
  • hvPlot to quickly generate interactive plots from your data
  • HoloViews to help you make all of your data instantly visualizable
  • GeoViews to extend HoloViews for geographic data
  • Datashader for rendering even the largest datasets
  • Param to create declarative user-configurable objects
  • Colorcet for perceptually uniform colormaps.

Brian #5: A cool new progress bar for python

  • Rogério Sampaio, @rsalmei
  • project: alive-progress
  • Way cool CLI progress bars with or without spinners
  • Clean coding interface.
  • Fun features and options like sequential framing, scrolling, bouncing, delays, pausing and restarting.
  • Repo README notes:
    • Great animations in the README. (we love this)
    • “To do” list, encourages contributions
    • “Interesting facts”
      • functional style
      • extensive use of closures and generators
      • no dependencies
  • “Changelog highlights”
    • I love this. 1-2 lines of semicolon separated features added per version.

Michael #6: Awesome Panel

  • by Marc Skov Madsen
  • Awesome Panel Project is to share knowledge on how awesome Panel is and can become.
  • A curated list of awesome Panel resources.
  • A gallery of awesome panel applications.
  • This app as a best practice multi page app with a nice layout developed in Panel.
  • Kind of meta as it’s built with Panel. :)
  • Browse the gallery to get a sense of what it can do

Extras:

Michael:

Brian:


Joke:

O’Really book covers


Want to go deeper? Check our projects