Learn Docker With My Newest Course

Dive into Docker takes you from "What is Docker?" to confidently applying Docker to your own projects. It's packed with best practices and examples. Start Learning Docker →

A Python CLI Tool to Help Diff Web Framework Versions

a-python-cli-tool-to-help-diff-web-framework-versions.jpg

It currently supports Phoenix, Rails, Django and Laravel, and this is a 30 minute video demoing how it works and how it was built.

Quick Jump:

Upgrading web framework versions is something we all deal with on a regular basis.

Before this tool existed, this is what I did every time I wanted to see what changed between 2 versions of a framework so I could update my app:

  • Launch a Docker container for XYZ language (let’s say Elixir)
  • Install my project’s current version of Phoenix (a web framework for Elixir)
  • Generate project A in a directory
  • Install the version of Phoenix I want to upgrade to
  • Generate project B in a different directory
  • Run the diff tool to see what changed between both versions

Needless to say it was a nuisance to do that every time I upgraded. This tool automates all of that by letting you run a single command such as verdiff --framework phoenix 1.4.4 1.4.8.

It’s a ~200 line Python script and uses Docker under the hood.

The first 10 minutes of the video below goes over using the tool and the last 20 or so minutes covers building a zero dependency Python CLI script that works for both Python 2.x and Python 3.x. You’ll see how to use argparse to build light weight and robust command line tools of your own.

# Demo Video of Using and Building This Tool

Timestamped Table of Contents

  • 0:34 – Running verdiff’s help menu to see what it does
  • 1:40 – What verdiff does and why I made this CLI tool
  • 2:49 – Running verdiff and watch it diff any 2 supported web framework versions
  • 3:55 – Comparing what changed between 2 Phoenix projects
  • 5:28 – Exploring the options we can use when running verdiff
  • 6:44 – Setting a custom project name to generate new projects (useful with Docker)
  • 8:16 – Checking out a new project and potentially diffing it with your code editor
  • 9:52 – Looking at the other verdiff flags
  • 10:16 – Keeping the Dockerfile around in case you want to use it
  • 10:52 – Time stamping the Dockerfile to keep it unique
  • 11:33 – Looking at the verdiff git repo
  • 11:54 – The README file explains every option and example use cases
  • 12:48 – Looking at the ~200 line Python CLI tool that makes verdiff work
  • 14:05 – Why are we using argparse instead of the click library?
  • 15:18 – Generating a help menu for your CLI tool
  • 17:03 – Defining required string arguments with N number of arguments
  • 18:25 – Writing 1 line of help text for each of your arguments
  • 18:50 – Setting up default values for your arguments
  • 19:35 – Creating custom types to help validate user input
  • 21:03 – Setting default values based on variables
  • 22:28 – Handling boolean values with defaults and 0 or 1 arguments
  • 24:40 – Parsing the arguments to get their values
  • 25:31 – Naming convention for argparse arguments and variable names
  • 25:53 – How to debug your args so you can see all of their values
  • 26:49 – Generating the Dockerfile based on the web framework name passed in
  • 33:05 – Checking out the Docker functions for the verdiff Python script
  • 33:52 – Running system commands with Python using subprocess
  • 34:43 – Using the Docker container copy command to save projects locally

Reference Links

What’s your process for upgrading web framework versions?

Never Miss a Tip, Trick or Tutorial

Like you, I'm super protective of my inbox, so don't worry about getting spammed. You can expect a few emails per year (at most), and you can 1-click unsubscribe at any time. See what else you'll get too.



Comments