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

jimschubert
In Chapter 3, the source for index introduces Config on page 31, followed by more code including tests; Config isn’t introduced until pag...
New
mikecargal
Title: Hands-On Rust (Chap 8 (Adding a Heads Up Display) It looks like ​.with_simple_console_no_bg​(SCREEN_WIDTH*2, SCREEN_HEIGHT*2...
New
conradwt
First, the code resources: Page 237: rumbl_umbrella/apps/rumbl/mix.exs Note: That this file is missing. Page 238: rumbl_umbrella/app...
New
joepstender
The generated iex result below should list products instead of product for the metadata. (page 67) iex> product = %Product{} %Pento....
New
alanq
This isn’t directly about the book contents so maybe not the right forum…but in some of the code apps (e.g. turbo/06) it sends a TURBO_ST...
New
cro
I am working on the “Your Turn” for chapter one and building out the restart button talked about on page 27. It recommends looking into ...
New
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
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...
New

Other popular topics Top

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
AstonJ
Curious to know which languages and frameworks you’re all thinking about learning next :upside_down_face: Perhaps if there’s enough peop...
New
AstonJ
Thanks to @foxtrottwist’s and @Tomas’s posts in this thread: Poll: Which code editor do you use? I bought Onivim! :nerd_face: https://on...
New
AstonJ
Inspired by this post from @Carter, which languages, frameworks or other tech or tools do you think is killing it right now? :upside_down...
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...
New
AstonJ
If you are experiencing Rails console using 100% CPU on your dev machine, then updating your development and test gems might fix the issu...
New
PragmaticBookshelf
A Hero’s Journey with Chris Pine @chrispine Chris Pine, author of Learn to Program, Third Edition, discusses his journey to beco...
New
PragmaticBookshelf
Rails 7 completely redefines what it means to produce fantastic user experiences and provides a way to achieve all the benefits of single...
New
PragmaticBookshelf
Build efficient applications that exploit the unique benefits of a pure functional language, learning from an engineer who uses Haskell t...
New
First poster: bot
zig/http.zig at 7cf2cbb33ef34c1d211135f56d30fe23b6cacd42 · ziglang/zig. General-purpose programming language and toolchain for maintaini...
New

Latest in PragProg

View all threads ❯