Skip to content

Commit 89e67da

Browse files
author
Kristian Rother
committed
fix format
1 parent a425d9e commit 89e67da

18 files changed

Lines changed: 13 additions & 106 deletions

class_diagram.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ The core logic of how the snake moves should not change because of that.
4848
A great thing about class diagrams is that you can create them to code easily.
4949
The Python `dataclasses` module saves you a lot of typing:
5050

51-
:::python3
5251
from dataclasses import dataclass
5352

5453
@dataclass
@@ -74,7 +73,6 @@ But we leave the method bodies empty for now.
7473
The `@dataclass` automatically creates the `__init__()` and `__repr__()` methods for you, so that you can set and inspect the attribute values.
7574
The code is already executable:
7675

77-
:::python3
7876
pf = PlayingField(size=(10, 10))
7977
print(pf)
8078
print(pf.size)
@@ -106,7 +104,6 @@ In Python, one could even state that the data structures are practically *identi
106104
Using the `@property` decorator, you can translate attributes into each other.
107105
The following code translates the `size` attribute into two new attributes `size_x` and `size_y`:
108106

109-
:::python3
110107
@property
111108
def size_x(self):
112109
return self.size[0]
@@ -117,7 +114,6 @@ The following code translates the `size` attribute into two new attributes `size
117114

118115
Now you can use all three attributes without storing redundant data:
119116

120-
:::python3
121117
pf = PlayingField(size=(5, 5))
122118
print(pf.size)
123119
print(pf.size_x)

coding_style.md

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,14 @@ The **pylint** tool checks whether your code conforms to the PEP8 coding guideli
1212

1313
Install it with
1414

15-
:::bash
1615
pip install pylint
1716

1817
Then you can analyze any Python file:
1918

20-
:::bash
2119
pylint my_program.py
2220

2321
Or all the files in a folder:
2422

25-
:::bash
2623
pyling *.py
2724

2825
----
@@ -36,7 +33,6 @@ In the output of `pylint`, there are two sections to pay attention to:
3633

3734
At the top of the output from **pylint**, you find a section with warning messages. Each warning contains the line number the warning refers to:
3835

39-
:::text
4036
W:117,12:Template.prepare_identifiers: Unused variable 'x'
4137
C: 32,0: Line too long (88/80)
4238
C:134,16:Renumerator.get_identifiers_list: Operator not preceded by a space
@@ -47,29 +43,25 @@ These warnings point you to the following issues:
4743

4844
#### Bugs and dead code
4945

50-
:::text
5146
W:117,12:Template.prepare_identifiers: Unused variable 'x'
5247

5348
This message indicates that line 117 either won't work or that the code has not been used at all.
5449

5550
#### Coding style
5651

57-
:::text
5852
C: 32,0: Line too long (88/80)
5953
C:134,16:Renumerator.get_identifiers_list: Operator not preceded by a space
6054

6155
Style issues regarding spaces, indentation and line lengths raised by pylint affect readability and are generally easy to fix.
6256

6357
#### Docstrings
6458

65-
:::text
6659
C: 1,0: Missing docstring
6760

6861
Functions and classes without docstrings are more difficult to understand. If you get a lot of docstring warnings your code may be hard to understand for someone else.
6962

7063
#### Variable names
7164

72-
:::text
7365
C:114,8:Renumerator.prepare_identifiers: Invalid name "fn" (should match [a-z_][a-z0-9_]{2,30}$)
7466

7567
Descriptive variable names are a big plus for code readability. Of course, it does not help much to replace **l** by **data_list** in order to satisfy pylint. But the name **fragment** tells you a lot more than **fn**.
@@ -78,7 +70,6 @@ Descriptive variable names are a big plus for code readability. Of course, it do
7870

7971
Pylint helps to analyze modularization by printing warning messages:
8072

81-
:::text
8273
R: 19,0:Renumerator: Too many public methods (30/20)
8374
R: 32,4:Renumerator.letter_generator: Method could be a function
8475
R: 45,0:RNAResidue: Too many instance attributes (11/7)
@@ -94,7 +85,6 @@ To assess modularization of a program as a whole, pylint is not the right tool.
9485

9586
At the end of the pylint output you find a score of up to 10 points:
9687

97-
:::text
9888
Your code has been rated at 8.18/10
9989

10090
When you have fixed some of the issues, re-run pylint and see your score improve. The score directly measures your success and makes working with pylint very rewarding.
@@ -109,7 +99,6 @@ A good practice is to disable some types of warnings (those you and your team ag
10999

110100
To ignore PEP8 warnings, create a file `.pylintrc` in your project directory. `pylint` finds it automatically. There you can list the types of warnings you would like to disable:
111101

112-
:::text
113102
[pylint]
114103
disable=C0103,C0111,line-too-long,too-few-public-methods
115104

continuous_integration.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ GitHub Actions needs instructions how to install the program.
2828
Create a folder `.github/workflows/`.
2929
Place a text file `check.yml` into that folder containing the following:
3030

31-
:::text
3231
name: run_tests
3332

3433
on:
@@ -78,7 +77,6 @@ Commit and push the changes.
7877

7978
Copy the following code into your `README.md` file:
8079

81-
:::text
8280
![Python application](https://github.com/USER/REPO/workflows/run_tests/badge.svg)
8381

8482
Replace **USER** and **REPO** by the data of your project.
@@ -89,4 +87,4 @@ You should see a red or green badge in the README that updates itself.
8987

9088
### Authors
9189

92-
**Malte Bonart participated in the writing of this chapter.**
90+
**Malte Bonart participated in the writing of this chapter.**

documenting.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ That said, there are a number of good Python tools to build and maintain documen
1616

1717
Running Sphinx could look like this:
1818

19-
:::bash
2019
sphinx-build html
2120

2221
Sphinx has its strengths in:
@@ -37,7 +36,6 @@ If you like to know more, check out this **[Talk by Eric Holscher](https://www.y
3736

3837
A very cool feature is that you can run a local documentation server with
3938

40-
:::bash
4139
mkdocs serve
4240

4341
and the local website is automatically updated as you edit the Markdown documents.

environment_variables.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ In this article, you can learn how to set and read environment variables on a Un
1818

1919
Type into the terminal:
2020

21-
:::bash
2221
export MY_TEXT=hello
2322

2423
Note the following:
@@ -35,15 +34,13 @@ Note the following:
3534

3635
Type into a terminal:
3736

38-
:::bash
3937
echo $MY_TEXT
4038

4139
The Unix `echo` command is the equivalent of `print()` in Python.
4240
The `$` symbol dereferences the variable.
4341

4442
If you want to see *all* environment variables that are defined, try the command:
4543

46-
:::bash
4744
env
4845

4946
The output is usually quite a mess.
@@ -54,7 +51,6 @@ The output is usually quite a mess.
5451

5552
No. Each environment has a local *scope*. Each program has its own variables. That means that typing
5653

57-
:::bash
5854
echo $MY_TEXT
5955

6056
in two terminals may yield different results.
@@ -69,13 +65,11 @@ E.g. when you start a Python program from a Unix command line, it receives the c
6965
If you want **all** programs to have a certain environment variable, add the `EXPORT` statement to a configuration file in your home directory.
7066
Open the file `.bashrc` (Linux) or `.bash_profile` (MacOS) and add the same line as above:
7167

72-
:::bash
7368
export MY_TEXT=hello
7469

7570
The changes are applied as soon as you start a new terminal.
7671
You can update your environment with:
7772

78-
:::bash
7973
source ~/.bashrc
8074

8175
**Note: Restart your Python editor, if you want it to see the new environment variables.**
@@ -86,7 +80,6 @@ You can update your environment with:
8680

8781
You can read an environment variable in two lines:
8882

89-
:::python3
9083
import os
9184

9285
text = os.getenv('MY_TEXT')
@@ -109,5 +102,4 @@ Here are a few common ones:
109102

110103
If you want to append a directory to an existing `PATH` or `PYTHONPATH`, this expression is useful:
111104

112-
:::bash
113105
export PATH=$PATH:/my/new/dir/

folders.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ A **Python package** is simply a folder that contains `.py` files.
1212
Create a folder `snake` inside your repository.
1313
On the bash terminal, you would use
1414

15-
:::bash
1615
mkdir snake
1716

1817
If your git repository is also called `snake`, you may want to rename your project folder to something else like `snake_project`, `snake_repo` or similar.
@@ -26,7 +25,6 @@ You will also want to have a place where you add test code later.
2625
Name that folder `tests/`.
2726
We will leave it empty for now.
2827

29-
:::bash
3028
mkdir tests
3129

3230
----
@@ -37,7 +35,6 @@ You may want to create a Python module (a `.py` file) to make sure everything is
3735
Create a file `game.py` inside the `snake/` folder.
3836
Add a placeholder function to it:
3937

40-
:::python3
4138
def play_snake():
4239
print('this is a snake game')
4340

@@ -59,14 +56,12 @@ Importing the `play_snake()` function to play the game is a bit inconvenient.
5956
Let's create a shortcut.
6057
Create a file named `__main__.py` (with double underscores on both ends) in the package folder that contains the following code:
6158

62-
:::python3
6359
from game import play_snake
6460

6561
play_snake()
6662

6763
Now it should be possible to start the game by typing:
6864

69-
:::text
7065
python snake
7166

7267
----
@@ -75,7 +70,6 @@ Now it should be possible to start the game by typing:
7570

7671
At this point, your project folder should contain:
7772

78-
:::text
7973
LICENSE
8074
prototype.py
8175
README.md

github_issues.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,12 @@ Go to the **Issues** tab on your repository on GitHub.
1212
Press the big **New Issue** button on the right side.
1313
Enter a title for the Issue, e.g.
1414

15-
:::text
1615
Features for the Snake Game
1716

1817
In the large text field below, you can add what is to be done.
1918
There are plenty of controls to format text and attach files (e.g. screenshots).
2019
One of the buttons lets you create a **Checklist**:
2120

22-
:::text
2321
- [ ] there is a wall around the playing field
2422
- [ ] there is food on the playing field
2523
- [ ] the snake gets longer when it eats food

good_software.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ When you use a program, you need to be 100% sure that it does exactly what you t
3535

3636
Each scientific program should include at least one set of sample data. There should be an instruction how to use the sample data and exactly what output it produces. Sometimes, this approach is broken down into small steps: a cookbook explaining small actions and their effect. Eventually, you will find an automatic test suite. This is a script that automatically checks whether different parts of the program work correctly. When you see a message like
3737

38-
39-
:::text
4038
110 of 110 tests OK.
4139

4240
you know that at least everything the developers felt important to check works.

interface.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ While both parts may change, the interface should remain stable.
4545
Let's separate the **User Interface** of the snake game from the **Game Logic**.
4646
For that, we will define a `SnakeGame` class that will be used as the only point of communication by the user interface:
4747

48-
:::python3
4948
class SnakeGame:
5049

5150
running: bool

loc.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@ More code means more work. The amount of code gives you a ballpark figure of how
99

1010
You can count the total number of files on Unix:
1111

12-
:::bash
1312
find . -name "*.py" | wc -l
1413

1514
A common metric is the number of **lines of code (LOC)**. The following command gives you the total number of LOC for all Python files in a Python directory tree:
1615

17-
:::bash
1816
find . -name "*.py" | xargs wc -l
1917

2018
Empty lines, docstrings and comments are counted, too, as they are part of the source code.

0 commit comments

Comments
 (0)