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 Pragmatic topics Top

jimmykiang
This test is broken right out of the box… — FAIL: TestAgent (7.82s) agent_test.go:77: Error Trace: agent_test.go:77 agent_test.go:...
New
ianwillie
Hello Brian, I have some problems with running the code in your book. I like the style of the book very much and I have learnt a lot as...
New
Alexandr
Hi everyone! There is an error on the page 71 in the book “Programming machine learning from coding to depp learning” P. Perrotta. You c...
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
curtosis
Running mix deps.get in the sensor_hub directory fails with the following error: ** (Mix) No SSH public keys found in ~/.ssh. An ssh aut...
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
hazardco
On page 78 the following code appears: <%= link_to ‘Destroy’, product, class: ‘hover:underline’, method: :delete, data: { confirm...
New
taguniversalmachine
It seems the second code snippet is missing the code to set the current_user: current_user: Accounts.get_user_by_session_token(session["...
New
tkhobbes
After some hassle, I was able to finally run bin/setup, now I have started the rails server but I get this error message right when I vis...
New
EdBorn
Title: Agile Web Development with Rails 7: (page 70) I am running windows 11 pro with rails 7.0.3 and ruby 3.1.2p20 (2022-04-12 revision...
New

Other popular topics Top

Devtalk
Hello Devtalk World! Please let us know a little about who you are and where you’re from :nerd_face:
New
AstonJ
If it’s a mechanical keyboard, which switches do you have? Would you recommend it? Why? What will your next keyboard be? Pics always w...
New
axelson
I’ve been really enjoying obsidian.md: It is very snappy (even though it is based on Electron). I love that it is all local by defaul...
New
AstonJ
poll poll Be sure to check out @Dusty’s article posted here: An Introduction to Alternative Keyboard Layouts It’s one of the best write-...
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
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 ...
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
Margaret
Hello content creators! Happy new year. What tech topics do you think will be the focus of 2021? My vote for one topic is ethics in tech...
New
AstonJ
In case anyone else is wondering why Ruby 3 doesn’t show when you do asdf list-all ruby :man_facepalming: do this first: asdf plugin-upd...
New
mafinar
This is going to be a long an frequently posted thread. While talking to a friend of mine who has taken data structure and algorithm cou...
New

Latest in PragProg

View all threads ❯