Skip to content

Commit 365f142

Browse files
committed
new texgit version and steps towards better listings api
1 parent f68e5e5 commit 365f142

File tree

22 files changed

+356
-216
lines changed

22 files changed

+356
-216
lines changed

text/back/scripts.tex

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
\hsection{Scripts}%
22
%
3-
\gitBash{\programmingWithPythonCodeRepo}{_scripts_/mypy.sh}{bash:mypy}{%
3+
\gitLoad{lst:bash:mypy}{\programmingWithPythonCodeRepo}{_scripts_/mypy.sh}{}%
4+
\listingBash{bash:mypy}{%
45
A \bash\ script for executing \mypy, which prints the command line and the exit code; see \cref{ut:mypy}.}%
56
%
6-
\gitBash{\programmingWithPythonCodeRepo}{_scripts_/ruff.sh}{bash:ruff}{%
7+
\gitLoad{lst:bash:ruff}{\programmingWithPythonCodeRepo}{_scripts_/ruff.sh}{}%
8+
\listingBash{bash:ruff}{%
79
A \bash\ script for executing \ruff, which prints the command line and the exit code; see \cref{ut:ruff}.}%
810
%
9-
\gitBash{\programmingWithPythonCodeRepo}{_scripts_/pylint.sh}{bash:pylint}{%
11+
\gitLoad{lst:bash:pylint}{\programmingWithPythonCodeRepo}{_scripts_/pylint.sh}{}%
12+
\listingBash{bash:pylint}{%
1013
A \bash\ script for executing \pylint, which prints the command line and the exit code; see \cref{ut:pylint}.}%
1114
%
12-
\gitBash{\programmingWithPythonCodeRepo}{_scripts_/pytest.sh}{bash:pytest}{%
15+
\gitLoad{lst:bash:pytest}{\programmingWithPythonCodeRepo}{_scripts_/pytest.sh}{}%
16+
\listingBash{bash:pytest}{%
1317
A \bash\ script for executing test cases with \pytest, which prints the command line and the exit code; see \cref{ut:pytest}.}%
1418
%
15-
\gitBash{\programmingWithPythonCodeRepo}{_scripts_/pytest_doctest.sh}{bash:pytest_doctest}{%
19+
\gitLoad{lst:bash:pytest_doctest}{\programmingWithPythonCodeRepo}{_scripts_/pytest_doctest.sh}{}%
20+
\listingBash{bash:pytest_doctest}{%
1621
A \bash\ script for executing \pglspl{doctest} with \pytest, which prints the command line and the exit code; see \cref{ut:doctest}.}%
1722
%
1823
Here we provide some scripts that are used within this book.

text/front/preface/preface.tex

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,5 @@ \chapter*{Preface}%
6868
%
6969
\strut\vfill\strut%
7070
This book was built using the following software:%
71-
\gitOutputWithStyle{}{}{text/front/preface/dependencyVersions.sh}{versions}{}{text_style}%
71+
\gitExec{exec:versions}{}{}{text/front/preface/dependencyVersions.sh}%
72+
\lstinputlisting[style=text_style]{\gitFile{exec:versions}}%

text/main/basics/collections/dictionaries/dictionaries.tex

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
\hsection{Dictionaries}%
22
\label{sec:dictionaries}%
33
%
4-
\gitPythonAndOutput{\programmingWithPythonCodeRepo}{collections}{dicts_1.py}{--args format}{dicts:dicts_1}{%
5-
An example of using dictionaries in \python.}%
4+
\gitLoadAndExecPython{dicts:dicts_1}{}{collections}{dicts_1.py}{}%
5+
\listingPythonAndOutput{dicts:dicts_1}{dicts_1.py}{%
6+
An example of using dictionaries in \python.}{}%
67
%
78
Dictionaries in \python\ are containers that store key-value pairs.
89
The value associated with a given key is accessed via the \pythonil{[...]}\pythonIdx{[\idxdots]}-based indexing.

text/main/basics/collections/lists/lists.tex

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@
77
\hsection{Basic Functionality and Examples}%
88
\label{sec:lists:basicFunctions}%
99
%
10-
\gitPythonAndOutput{\programmingWithPythonCodeRepo}{collections}{lists_1.py}{--args format}{lists:lists_1}{%
11-
A first example for using lists in \python: creating, indexing, printing of and appending elements and other lists to lists.}%
10+
\gitLoadAndExecPython{lists:lists_1}{}{collections}{lists_1.py}{}%
11+
\listingPythonAndOutput{lists:lists_1}{lists_1.py}{%
12+
A first example for using lists in \python:~creating, indexing, printing of and appending elements and other lists to lists.}{}%
1213
%
13-
\gitPythonAndOutput{\programmingWithPythonCodeRepo}{collections}{lists_2.py}{--args format}{lists:lists_2}{%
14-
A second example of using lists in \python: inserting and deleting elements, sorting and reversing lists.}%
14+
\gitLoadAndExecPython{lists:lists_2}{}{collections}{lists_2.py}{}%
15+
\listingPythonAndOutput{lists:lists_2}{lists_2.py}{%
16+
A second example of using lists in \python: inserting and deleting elements, sorting and reversing lists.}{}%
1517
%
16-
\gitPythonAndOutput{\programmingWithPythonCodeRepo}{collections}{lists_3.py}{--args format}{lists:lists_3}{%
17-
A third example of using lists in \python: slicing, adding, and multiplying lists.}%
18+
\gitLoadAndExecPython{lists:lists_3}{}{collections}{lists_3.py}{}%
19+
\listingPythonAndOutput{lists:lists_3}{lists_3.py}{%
20+
A third example of using lists in \python: slicing, adding, and multiplying lists.}{}%
1821
%
1922
In \cref{lst:lists:lists_1}, we provide some first examples for using lists.
2023
A list can be defined by simply writing its contents, separated by~\pythonilIdx{,} inside square brackets~\pythonil{[...]}\pythonIdx{[\idxdots]}.
@@ -143,17 +146,19 @@
143146
\hsection{An Example of Errors and a new Tool}%
144147
\label{sec:listExampleForErrorsAndRuff}%
145148
%
146-
\gitPythonAndOutput{\programmingWithPythonCodeRepo}{collections}{lists_error.py}{--args format}{lists:lists_error}{%
147-
A program processing lists which exhibits some subtle errors and inefficiencies.}
148-
149+
\gitLoadAndExecPython{lists:lists_error}{}{collections}{lists_error.py}{}%
150+
\listingPythonAndOutput{lists:lists_error}{lists_error.py}{%
151+
A program processing lists which exhibits some subtle errors and inefficiencies.}{}%
152+
%
149153
Now, in the previous chapter, we learned that static code analysis tools can help us to discover subtle problems in our programs.
150154
Obviously, when dealing with more complex datastructures like lists, there are also more potential problems, more mistakes that one could make.
151155
Let us look at the very short example \cref{lst:lists:lists_error}.
152156
The program consists of only two lines, \pythonil{my_list: list[str] = list([1, 2, 3])} and \pythonil{print(my_list)}.
153157
It does not have any \emph{error} in the strict sense.
154158
We can execute it just fine and it will produce the output \textil{[1, 2, 3]} as shown in \cref{exec:lists:lists_error}.
155159

156-
\gitOutputTool{\programmingWithPythonCodeRepo}{.}{_scripts_/mypy.sh collections lists_error.py}{lists:lists_error:mypy}{%
160+
\gitExec{exec:lists:lists_error:mypy}{\programmingWithPythonCodeRepo}{.}{_scripts_/mypy.sh collections lists_error.py}%
161+
\listingToolOutput{lists:lists_error:mypy}{%
157162
The results of static type checking with \mypy\ of the program given in \cref{lst:lists:lists_error}.}
158163

159164
However, upon closer inspection, we discover some issues.
@@ -179,7 +184,8 @@
179184
We provide a script for using \ruff\ with a reasonable default configuration in \cref{lst:bash:ruff} on \cpageref{lst:bash:ruff}.%
180185
}%
181186
%
182-
\gitOutputTool{\programmingWithPythonCodeRepo}{.}{_scripts_/ruff.sh collections lists_error.py}{lists:lists_error:ruff}{%
187+
\gitExec{exec:lists:lists_error:ruff}{\programmingWithPythonCodeRepo}{.}{_scripts_/ruff.sh collections lists_error.py}%
188+
\listingToolOutput{lists:lists_error:ruff}{%
183189
The results of linting with \ruff\ of the program given in \cref{lst:lists:lists_error}. (We used the script given in \cref{lst:bash:ruff} on \cpageref{lst:bash:ruff} to apply \ruff.)}%
184190
%
185191
Let us apply \ruff\ to the program \textil{lists_error.py} given in \cref{lst:lists:lists_error}, which produces the output \cref{exec:lists:lists_error:ruff}.
@@ -199,8 +205,9 @@
199205
It basically creates a list via \pythonil{[1, 2, 3]} and then immediately makes a copy of it via the \pythonilIdx{list} function wrapped around the list specification.
200206
We can leave this outer call to \pythonil{list} away.
201207

202-
\gitPythonAndOutput{\programmingWithPythonCodeRepo}{collections}{lists_fixed.py}{--args format}{lists:lists_fixed}{%
203-
The corrected version of~\cref{lst:lists:lists_error}, taking into account the information given by \mypy\ in \cref{exec:lists:lists_error:mypy} and \ruff\ in \cref{exec:lists:lists_error:ruff}.}%
208+
\gitLoadAndExecPython{lists:lists_fixed}{}{collections}{lists_fixed.py}{}%
209+
\listingPythonAndOutput{lists:lists_fixed}{lists_fixed.py}{%
210+
The corrected version of~\cref{lst:lists:lists_error}, taking into account the information given by \mypy\ in \cref{exec:lists:lists_error:mypy} and \ruff\ in \cref{exec:lists:lists_error:ruff}.}{}%
204211
%
205212
%
206213
In \cref{lst:lists:lists_fixed} we implement the three recommendations from the two tools.
@@ -220,10 +227,12 @@
220227
%
221228
\FloatBarrier%
222229
%
223-
\gitOutputTool{\programmingWithPythonCodeRepo}{.}{_scripts_/mypy.sh collections lists_fixed.py}{lists:lists_fixed:mypy}{%
230+
\gitExec{exec:lists:lists_fixed:mypy}{\programmingWithPythonCodeRepo}{.}{_scripts_/mypy.sh collections lists_fixed.py}%
231+
\listingToolOutput{lists:lists_fixed:mypy}{%
224232
The results of static type checking with \mypy\ of the program given in \cref{lst:lists:lists_fixed}.}%
225233
%
226-
\gitOutputTool{\programmingWithPythonCodeRepo}{.}{_scripts_/ruff.sh collections lists_fixed.py}{lists:lists_fixed:ruff}{%
234+
\gitExec{exec:lists:lists_fixed:ruff}{\programmingWithPythonCodeRepo}{.}{_scripts_/ruff.sh collections lists_fixed.py}%
235+
\listingToolOutput{lists:lists_fixed:ruff}{%
227236
The results of static type checking with \ruff\ of the program given in \cref{lst:lists:lists_fixed}.}
228237

229238
Well, this was only a two-line program.

text/main/basics/collections/sets/sets.tex

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
\hsection{Sets}%
22
\label{sec:sets}%
33
%
4-
\gitPythonAndOutput{\programmingWithPythonCodeRepo}{collections}{sets_1.py}{--args format}{sets:sets_1}{%
4+
\gitLoadAndExecPython{sets:sets_1}{}{collections}{sets_1.py}{}%
5+
\listingPythonAndOutput{sets:sets_1}{sets_1.py}{%
56
A first example of using sets in \python: creating, modifying, and converting sets. %
6-
Since sets are unordered, printing them can yield a different result each time a program is executed (see \cref{bp:setsUnordered}).}%
7+
Since sets are unordered, printing them can yield a different result each time a program is executed (see \cref{bp:setsUnordered}).}{}%
78
%
8-
\gitPythonAndOutput{\programmingWithPythonCodeRepo}{collections}{sets_2.py}{--args format}{sets:sets_2}{%
9-
A second example of using sets in \python: creating sets and set operations (as illustrated in \cref{fig:setOperations}). %
10-
Since sets are unordered, printing them can yield a different result each time a program is executed (see \cref{bp:setsUnordered}).}%
9+
\gitLoadAndExecPython{sets:sets_2}{}{collections}{sets_2.py}{}%
10+
\listingPythonAndOutput{sets:sets_2}{sets_2.py}{%
11+
A second example of using sets in \python: creating sets and set operations~(as illustrated in \cref{fig:setOperations}). %
12+
Since sets are unordered, printing them can yield a different result each time a program is executed~(see \cref{bp:setsUnordered}).}{}%
1113
%
1214
\begin{figure}%
1315
\centering%

text/main/basics/collections/tuples/tuples.tex

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
\hsection{Tuples}%
22
\label{sec:tuples}%
33
%
4-
\gitPythonAndOutput{\programmingWithPythonCodeRepo}{collections}{tuples_1.py}{--args format}{tuples:tuples_1}{%
5-
A first example of using tuples in \python: creating, indexing, and printing of tuples.}%
4+
\gitLoadAndExecPython{tuples:tuples_1}{}{collections}{tuples_1.py}{}%
5+
\listingPythonAndOutput{tuples:tuples_1}{tuples_1.py}{%
6+
A first example of using tuples in \python:~creating, indexing, and printing of tuples.}{}%
67
%
7-
\gitPythonAndOutput{\programmingWithPythonCodeRepo}{collections}{tuples_2.py}{--args format}{tuples:tuples_2}{%
8-
A second example of using tuples in \python: tuples with elements of different types and tuple unpacking.}%
8+
\gitLoadAndExecPython{tuples:tuples_2}{}{collections}{tuples_2.py}{}%
9+
\listingPythonAndOutput{tuples:tuples_2}{tuples_2.py}{%
10+
A second example of using tuples in \python:~tuples with elements of different types and tuple unpacking.}{}%
911
%
1012
\gitPythonAndErrorOutput{\programmingWithPythonCodeRepo}{collections}{tuples_3.py}{--args format}{tuples:tuples_3}{%
11-
A third example of using tuples in \python: testing the immutability property.}%
13+
A third example of using tuples in \python:~testing the immutability property.}%
1214
%
13-
\gitOutputTool{\programmingWithPythonCodeRepo}{.}{_scripts_/mypy.sh collections tuples_3.py}{tuples:tuples_3:mypy}{%
15+
\gitExec{exec:tuples:tuples_3:mypy}{\programmingWithPythonCodeRepo}{.}{_scripts_/mypy.sh collections tuples_3.py}%
16+
\listingToolOutput{tuples:tuples_3:mypy}{%
1417
The results of static type checking with \mypy\ of the program given in \cref{lst:tuples:tuples_3}.}%
1518
%
1619
\pythonIdx{tuple}%

text/main/basics/gettingStarted/firstProgram/firstProgram.tex

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
This program should just print \inQuotes{Hello World!} to the text output and then exit.
77
It therefore will consist of the single statement \pythonil{print("Hello World!")}, as illustrated in \cref{lst:very_first_program}.
88

9-
\gitPythonAndOutput{\programmingWithPythonCodeRepo}{veryFirstProject}{very_first_program.py}{--args format}{very_first_program}{%
10-
Our very first \python\ program, which just prints \inQuotes{Hello World!}}%
9+
\gitLoadAndExecPython{very_first_program}{}{veryFirstProject}{very_first_program.py}{}%
10+
\listingPythonAndOutput{very_first_program}{very_first_program.py}{%
11+
Our very first \python\ program, which just prints \inQuotes{Hello World!}}{}%
1112
%
1213
\begin{figure}%
1314
\centering%

text/main/basics/variables/assignment/assignment.tex

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
Here, \pythonil{name} is the name of the variable and \pythonil{value} be the value that we want to assign to that name.%
77
%
88
\hsection{A Simple Example of Variable Assignment and Comments in the Code}%
9-
\gitPythonAndOutput{\programmingWithPythonCodeRepo}{variables}{assignment.py}{--args format}{variables:assignment}{%
10-
A \python\ program showing some examples for variable assignments.}%
9+
\gitLoadAndExecPython{variables:assignment}{}{variables}{assignment.py}{}%
10+
\listingPythonAndOutput{variables:assignment}{assignment.py}{%
11+
A \python\ program showing some examples for variable assignments.}{}%
1112
%
1213
\begin{figure}[tb]%
1314
\centering%
@@ -203,7 +204,7 @@
203204

204205
Now this is a very coarse approximation of~\numberPi.
205206
We can get closer to the actual ratio if we would use more edges, i.e., higher values of~$e$.
206-
The ingenious idea of LIU Hui is to use $e$\nobreakdashes-gons with~$e=3*2^n$.
207+
The ingenious idea of LIU Hui~(刘徽) is to use $e$\nobreakdashes-gons with~$e=3*2^n$.
207208
For $n=1$, we get the hexagon with $e=6$.
208209
For $n=2$, we double the edges and have a dodecagon with $e=12$~edges.
209210
But how do we get the edge length~\liuhuist\ of this dodecagon?
@@ -232,8 +233,9 @@
232233
\pi_{2e} &= \frac{e}{2} s_{2e}\label{eq:liuhui:approx}%
233234
\end{align}%
234235
%
235-
\gitPythonAndOutput{\programmingWithPythonCodeRepo}{variables}{pi_liu_hui.py}{--args format}{variables:pi_liu_hui}{%
236-
A \python\ program showing several steps of the approximation of~\numberPi\ using the method of LIU Hui.}%
236+
\gitLoadAndExecPython{variables:pi_liu_hui}{}{variables}{pi_liu_hui.py}{}%
237+
\listingPythonAndOutput{variables:pi_liu_hui}{file}{%
238+
A \python\ program showing several steps of the approximation of~\numberPi\ using the method of LIU Hui~(刘徽).}{}%
237239
%
238240
\begin{figure}[tb]%
239241
\centering%

text/main/basics/variables/identity/identity.tex

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@
2121
\label{fig:variables:equalityAndIdentity}%
2222
\end{figure}%
2323
%
24-
\gitPythonAndOutput{\programmingWithPythonCodeRepo}{variables}{identity_1.py}{--args format}{variables:identity_1}{%
25-
An example of the difference between equality and identity\pythonIdx{sqrt}.}%
24+
\gitLoadAndExecPython{variables:identity_1}{}{variables}{identity_1.py}{}%
25+
\listingPythonAndOutput{variables:identity_1}{identity_1.py}{%
26+
An example of the difference between equality and identity\pythonIdx{sqrt}.}{}%
2627
%
27-
\gitPythonAndOutput{\programmingWithPythonCodeRepo}{variables}{identity_2.py}{--args format}{variables:identity_2}{%
28-
An second example of the difference between equality and identity.}%
28+
\gitLoadAndExecPython{variables:identity_2}{}{variables}{identity_2.py}{}%
29+
\listingPythonAndOutput{variables:identity_2}{identity_2.py}{%
30+
An second example of the difference between equality and identity.}{}%
2931
%
3032
We use variables to references objects in memory.
3133
When we compare two variables, we actually compare the objects they reference.

text/main/basics/variables/multiAndSwap/multiAndSwap.tex

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
\hsection{Multiple Assignments and Value Swapping}%
22
%
3-
\gitPythonAndOutput{\programmingWithPythonCodeRepo}{variables}{multi_and_swap.py}{--args format}{variables:multi_and_swap}{%
4-
A \python\ program assigning multiple values to multiple variables and using the same method to swap variable values.}%
3+
\gitLoadAndExecPython{variables:multi_and_swap}{}{variables}{multi_and_swap.py}{}%
4+
\listingPythonAndOutput{variables:multi_and_swap}{multi_and_swap.py}{%
5+
A \python\ program assigning multiple values to multiple variables and using the same method to swap variable values.}{}%
56
%
67
Let us return to the topic of variables and assignments.
78
In \python, we can assign values to multiple variables at once.

0 commit comments

Comments
 (0)