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

1 834 1

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

JohnS
I can’t setup the Rails source code. This happens in a working directory containing multiple (postgres) Rails apps. With: ruby-3.0.0 s...
0 1272 3
New
herminiotorres
Hi! I know not the intentions behind this narrative when called, on page XI: mount() |> handle_event() |> render() but the correc...
3 1296 17
New
HarryDeveloper
Hi @venkats, It has been mentioned in the description of ‘Supervisory Job’ title that 2 things as mentioned below result in the same eff...
0 2203 2
New
rmurray10127
Title: Intuitive Python: docker run… denied error (page 2) Attempted to run the docker command in both CLI and Powershell PS C:\Users\r...
9 1256 4
New
jskubick
I’m under the impression that when the reader gets to page 136 (“View Data with the Database Inspector”), the code SHOULD be able to buil...
2 1163 8
New
Charles
In general, the book isn’t yet updated for Phoenix version 1.6. On page 18 of the book, the authors indicate that an auto generated of ro...
9 2047 12
New
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...
17 1369 9
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,...
0 1143 10
New
roadbike
From page 13: On Python 3.7, you can install the libraries with pip by running these commands inside a Python venv using Visual Studio ...
1 963 3
New

Other popular topics Top

AstonJ
A thread that every forum needs! Simply post a link to a track on YouTube (or SoundCloud or Vimeo amongst others!) on a separate line an...
193 4238 93
New
AstonJ
What chair do you have while working… and why? Is there a ‘best’ type of chair or working position for developers?
74 4636 41
New
New
PragmaticBookshelf
Rust is an exciting new programming language combining the power of C with memory safety, fearless concurrency, and productivity boosters...
118 6884 31
New
AstonJ
Just done a fresh install of macOS Big Sur and on installing Erlang I am getting: asdf install erlang 23.1.2 Configure failed. checking ...
10 5353 8
New
AstonJ
I ended up cancelling my Moonlander order as I think it’s just going to be a bit too bulky for me. I think the Planck and the Preonic (o...
105 13994 48
New
OvermindDL1
Woooooooo! This is such a huge release for it, and 2 years incoming! In short, the library is now using an updated hyper backend (not j...
20 2654 6
New
New
PragmaticBookshelf
Author Spotlight: Sophie DeBenedetto @SophieDeBenedetto The days of the traditional request-response web application are long gone, b...
37 2987 15
New
PragmaticBookshelf
A Ruby-Centric Chat with Noel Rappin @noelrappin Once you start noodling around with Ruby you quickly figure out, as Noel Rappi...
41 2554 20
New

Latest in PragProg

View all threads ❯