robmh26

robmh26

Intuitive Python: Use of tools

How do I run Flake, Black MyPy etc. I might have missed it but the book doesn’t seem to cover this.

Similarly, where the book says ‘consider running black . --check in your build system’ where is the guidance on what a build system is and how to set it up?

Thanks

Marked As Solved

davidmuller

davidmuller

Author of Intuitive Python

Hello,

Thanks for sharing this feedback - let me see if I can help out a bit.

I’m not sure what version of the book you might be reading (some early versions didn’t mention a companion Docker image), but the easiest way to try out the tools is to use the book’s companion Docker image:

  1. Install Docker.
  2. Run: docker run --pull=always --interactive --tty --rm ghcr.io/davidmuller/intuitive-python-book/intuitive-python-book:latest /bin/bash

After executing step 2, you’ll be logged into the Docker container as a user named monty in a directory with all the book’s source code. Use this space as a sandbox to run all the code examples as you read the book.

As you read through the book, you’ll see examples for how to invoke flake8 appear in the text. For example, flake8 variable_does_not_exist.py is one such invocation described in the section titled Detecting Undefined Variables.

Similarly, in the section titled Finding Unsupported Arguments, the text describes invoking mypy like mypy unsupported_argument.py.

Both of these examples demonstrate how to invoke flake / mypy against a single file. These examples should run successfully if you are inside of the companion Docker image (which includes all the book’s source code examples).

If you’re curious to learn more about invoking flake8 / mypy, I recommend their help commands (flake8 --help, mypy --help) and their online documentation (flake8, mypy).


As you point out, however, the book does not have a concrete example for how to invoke black. Just like flake8 and mypy, one way to invoke black is against a single file.

For example, you can run black --diff gil_example.py inside the Docker image to see some changes black would make to gil_example.py. If you remove the --diff and just run black gil_example.py, black will write out the changes you previewed in the first command to disk.

If you’re curious to learn more about black, I recommend its help command (black --help) and its online documentation.


what a build system is and how to set it up?

You’re right, build systems are not covered explicitly in the book. You can think of a build system as a server that automatically runs tests and other validations every time you change the source code in a project.

If you’re familiar with GitHub, you may have seen an example build system already. GitHub includes a product called GitHub Actions, which is a build system for developers who store their source code on GitHub. Those developers are able to run tests and other programs anytime they change their code on GitHub. These builds help developers catch bugs and other problems early—before, for example, they actually formally release their code for others to use.

(For a concrete example of a build system, you can visit the GitHub repository that stores the code that implements the Python language itself. Every time the developers of the Python language change the code that powers the language, a suite of builds + tests + validations are run. You can view the output of those Python language builds here.)

Running Example Commands for a Build System

black, flake8, and mypy are three tools that the book recommends running any time you change your Python source code. You can use a build system / server to run these tools for you, but you can also run them manually:

# navigate to your project code
$ cd /example/path/to/your/project/code

# make sure all the files in your project are black compliant (the . is important)
$ black --check --diff .

# run flake8 against all files in your project (the . is important)
$ flake8 .

# run mypy against all the files in your project (the . is important)
# (--pretty makes the results a little easier to read)
$ mypy --pretty .

Thanks for checking out the book. I hope some of the discussion here adds additional context for the book.

-David

Popular Prag Prog topics Top

jeffmcompsci
Title: Design and Build Great Web APIs - typo “https://company-atk.herokuapp.com/2258ie4t68jv” (page 19, third bullet in URL list) Typo:...
New
jesse050717
Title: Web Development with Clojure, Third Edition, pg 116 Hi - I just started chapter 5 and I am stuck on page 116 while trying to star...
New
Chrichton
Dear Sophie. I tried to do the “Authorization” exercise and have two questions: When trying to plug in an email-service, I found the ...
New
swlaschin
The book has the same “Problem space/Solution space” diagram on page 18 as is on page 17. The correct Problem/Solution space diagrams ar...
New
brian-m-ops
#book-python-testing-with-pytest-second-edition Hi. Thanks for writing the book. I am just learning so this might just of been an issue ...
New
adamwoolhether
Is there any place where we can discuss the solutions to some of the exercises? I can figure most of them out, but am having trouble with...
New
jonmac
The allprojects block listed on page 245 produces the following error when syncing gradle: “org.gradle.api.GradleScriptException: A prob...
New
bjnord
Hello @herbert ! Trying to get the very first “Hello, Bracket Terminal!" example to run (p. 53). I develop on an Amazon EC2 instance runn...
New
redconfetti
Docker-Machine became part of the Docker Toolbox, which was deprecated in 2020, long after Docker Desktop supported Docker Engine nativel...
New
mcpierce
@mfazio23 I’ve applied the changes from Chapter 5 of the book and everything builds correctly and runs. But, when I try to start a game,...
New

Other popular topics Top

AstonJ
What chair do you have while working… and why? Is there a ‘best’ type of chair or working position for developers?
New
Exadra37
I am thinking in building or buy a desktop computer for programing, both professionally and on my free time, and my choice of OS is Linux...
New
PragmaticBookshelf
Rust is an exciting new programming language combining the power of C with memory safety, fearless concurrency, and productivity boosters...
New
AstonJ
Saw this on TikTok of all places! :lol: Anyone heard of them before? Lite:
New
AstonJ
If you get Can't find emacs in your PATH when trying to install Doom Emacs on your Mac you… just… need to install Emacs first! :lol: bre...
New
PragmaticBookshelf
Build efficient applications that exploit the unique benefits of a pure functional language, learning from an engineer who uses Haskell t...
New
PragmaticBookshelf
Author Spotlight: Karl Stolley @karlstolley Logic! Rhetoric! Prag! Wow, what a combination. In this spotlight, we sit down with Karl ...
New
PragmaticBookshelf
Author Spotlight: Sophie DeBenedetto @SophieDeBenedetto The days of the traditional request-response web application are long gone, b...
New
New
AstonJ
If you’re getting errors like this: psql: error: connection to server on socket “/tmp/.s.PGSQL.5432” failed: No such file or directory ...
New