Skip to content

Commit b8b8002

Browse files
committed
added bash and mypy script
1 parent aea31db commit b8b8002

File tree

8 files changed

+86
-68
lines changed

8 files changed

+86
-68
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## Core latex/pdflatex auxiliary files:
22
*.aux
3+
*.ind
34
*.lof
45
*.log
56
*.lot

bibliography/bibliography.bib

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ @string { a_bommarito_michael
4343
@string { a_bose_cherokee = "Cherokee Boose" }
4444
@string { a_bott_ed = "Ed Bott" }
4545
@string { a_bradbury_james = "James Bradbury" }
46+
@string { a_brash_ron = "Ron Brash" }
4647
@string { a_brett_matthew = "Matthew Brett" }
4748
@string { a_bright_jonathan = "Jonathan Bright" }
4849
@string { a_brucher_matthieu = "Matthieu Brucher" }
@@ -156,6 +157,7 @@ @string { a_moore_eric_w
156157
@string { a_moore_sherry = "Sherry Moore" }
157158
@string { a_morris_sidney_a = "Sidney A.\ Morris" }
158159
@string { a_murray_derek_gordon = "Derek Gordon Murray" }
160+
@string { a_naik_ganesh = "Ganesh Naik" }
159161
@string { a_negus_christopher = "Christopher Negus" }
160162
@string { a_nelson_andrew_r_j = "Andrew R.\ J.\ Nelson" }
161163
@string { a_nguyen_quan = "Quan Nguyen" }
@@ -250,6 +252,7 @@ @string { a_yang_edward_z
250252
@string { a_yang_xuanda = "Xuanda Yang" }
251253
@string { a_ye_jingchen = "Jingchen Ye" }
252254
@string { a_yu_yuan = "Yuan Yu" }
255+
@string { a_zarrelli_giorgio = "Giorgio Zarrelli" }
253256
@string { a_zheng_xiaoqiang = "Xiaoqiang Zheng" }
254257
@string { a_zijlstra_jelle = "Jelle Zijlstra" }
255258
@string { a_zinoviev_dimitry = "Dmitry Zinoviev" }
@@ -643,7 +646,7 @@ @book{B2023G2GLS
643646

644647
@book{B2023PFS,
645648
author = a_bruhin_florian,
646-
title = {\python\ f\nobreakdash-strings},
649+
title = {\python\ \pglspl{fstring}},
647650
publisher = p_bruhin_software,
648651
address = pa_bruhin_software,
649652
date = {2023-05-31},
@@ -691,6 +694,15 @@ @inbook{BHK2006NS
691694
urldate = {2024-07-27}
692695
}
693696

697+
@book{BN2018BC,
698+
author = a_brash_ron # and # a_naik_ganesh,
699+
title = {\bash\ Cookbook},
700+
date = {2018-07},
701+
publisher = p_packt,
702+
address = pa_packt,
703+
isbn = {9781788629362},
704+
}
705+
694706
@article{C2002LFLHADWTDM,
695707
title = {Learning from Liu Hui? A Different Way to Do Mathematics},
696708
author = a_cullen_christopher,
@@ -980,7 +992,7 @@ @book{LNL2020LJ
980992

981993
@book{M2017WAFSIPAHCIUT,
982994
author = a_maxwell_aaron,
983-
title = {What are f-strings in \python\ and how can I use them?},
995+
title = {What are \pglspl{fstring} in \python\ and how can I use them?},
984996
publisher = p_infinite_skills,
985997
address = pa_infinite_skills,
986998
date = {2017-06},
@@ -1392,6 +1404,15 @@ @book{Y2022PPADT
13921404
isbn = {9781837632442}
13931405
}
13941406

1407+
@book{Z2017MB,
1408+
author = a_zarrelli_giorgio,
1409+
title = {Mastering \bash},
1410+
date = {2017-06},
1411+
publisher = p_packt,
1412+
address = pa_packt,
1413+
isbn = {9781784396879}
1414+
}
1415+
13951416
@techreport{Z2024DESIEWS,
13961417
author = a_zinoviev_dimitry,
13971418
title = {Discrete Event Simulation: It's Easy with \simpy!},

notation/software.sty

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@
55
\protected\gdef\softwareStyle#1{\scalebox{0.95}[1]{\texttt{#1}}}%
66
%
77
%
8+
\newglossaryentry{bash}{%
9+
text={\softwareStyle{Bash}},%
10+
name={Bash},%
11+
sort={Bash},%
12+
description={%
13+
is a the shell used under \ubuntu\ \linux, i.e., the program that \inQuotes{runs} in the \pgls{terminal} and interprets your commands, allowing you to start and interact with other programs~\cite{Z2017MB,BN2018BC}. %
14+
Learn more at \url{https://www.gnu.org/software/bash/}.%
15+
}%
16+
}%
17+
\protected\gdef\bash{\pgls{bash}}%
18+
%
19+
%
820
\newglossaryentry{linux}{%
921
text={\softwareStyle{Linux}},%
1022
name={Linux},%

notation/terms.sty

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ description={%
153153
A terminal is a text-based window where you can enter commands and execute them~\cite{CN2020ULB,B2022ELATCL}. %
154154
Knowing what a terminal is and how to use it is very essential in any programming- or system administration-related task. %
155155
If you want to open a terminal under \windows, you can \windowsTerminal, as shown, e.g., in \cpageref{fig:installingPythonWindows01openTerminal}. %
156-
Under \ubuntu\ \linux, \ubuntuTerminal\ opens a terminal.%
156+
Under \ubuntu\ \linux, \ubuntuTerminal\ opens a terminal, which then runs a \bash\ shell inside.%
157157
}%
158158
}%
159159
%

styles/listing.sty

Lines changed: 28 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -6,59 +6,33 @@
66
%
77
\def\@lstbasicstyle{\small\color{listing-text-color}\linespread{1.0}\lst@ifdisplaystyle\small\fi\ttfamily{}}%
88
%
9-
\lstdefinestyle{python_style}{%
10-
%
9+
\lstdefinestyle{basic_style}{%
1110
backgroundcolor=\color{listing-background},%
1211
numbers=left,%
1312
frame=single,%
1413
rulecolor=\color{listing-rule},%
1514
frameround=ffff,%
16-
%
1715
breaklines=true,%
1816
tabsize=4,%
19-
%
20-
language=Python,%
2117
sensitive=true,%
22-
%
2318
basicstyle=\@lstbasicstyle,%
2419
identifierstyle=\color{listing-identifier},%
2520
numberstyle=\color{listing-line-numbers},%
26-
%
27-
otherkeywords={\%,\},\{,\&,\|},%
2821
keywordstyle=\color{listing-keyword-1}\bfseries,%
29-
%
30-
emph={and,break,class,continue,def,yield,del,elif,else,except,exec,finally,for,from,global,if,import,in,lambda,not,or,pass,print,raise,return,try,while,assert,with},%
3122
emphstyle=\color{listing-emph-1}\bfseries,%
32-
%
33-
emph={[2]True,False,None},%
3423
emphstyle=[2]\color{listing-emph-2},%
35-
%
36-
emph={[3]object,type,isinstance,deepcopy,zip,enumerate,reversed,list,set,len,dict,tuple,xrange,append,execfile,real,imag,reduce,str,repr},%
3724
emphstyle=[3]\color{listing-emph-3},%
38-
%
39-
emph={[4]Exception,NameError,IndexError,SyntaxError,TypeError,ValueError,OverflowError,ZeroDivisionError},%
4025
emphstyle=[4]\color{listing-emph-4}\bfseries,%
41-
%
42-
emph={[5]ode,fsolve,sqrt,exp,sin,cos,arctan,arctan2,arccos,pi,array,norm,dot,arange,isscalar,max,sum,flatten,shape,reshape,find,any,all,abs,plot,linspace,legend,quad,polyval,polyfit,hstack,concatenate,vstack,column_stack,empty,zeros,ones,rand,vander,grid,pcolor,eig,eigs,eigvals,svd,qr,tan,det,logspace,roll,min,mean,cumsum,cumprod,diff,vectorize,lstsq,cla,eye,xlabel,ylabel,squeeze},%
4326
emphstyle=[5]\color{listing-emph-5},%
44-
%
45-
emph={[6]__init__,__add__,__mul__,__div__,__sub__,__call__,__getitem__,__setitem__,__eq__,__ne__,__new__,__nonzero__,__rmul__,__radd__,__repr__,__str__,__get__,__truediv__,__pow__,__name__,__future__,__all__},%
4627
emphstyle=[6]\color{listing-emph-6},%
47-
%
48-
emph={[7]assert,yield},%
4928
emphstyle=[7]\color{listing-emph-7}\bfseries,%
50-
%
51-
emph={[8]range},%
5229
emphstyle={[8]\color{listing-emph-8}\bfseries},%
53-
%
5430
keywordstyle={[2]\color{listing-keyword-2}\bfseries},%
5531
keywordstyle={[3]\color{listing-keyword-3}\bfseries\itshape},%
56-
%
5732
commentstyle=\itshape\color{listing-comment},%
58-
%
5933
stringstyle=\color{listing-string},%
6034
showstringspaces=false,%
61-
morestring=[s]{"""}{"""},%
35+
postbreak=\mbox{\textcolor{red}{$\hookrightarrow$}\space},%
6236
%
6337
literate=%
6438
{á}{{\'a}}1 {é}{{\'e}}1 {í}{{\'i}}1 {ó}{{\'o}}1 {ú}{{\'u}}1%
@@ -76,25 +50,28 @@ literate=%
7650
{…}{{\ldots}}1 {≥}{{>=}}1 {≤}{{<=}}1 {„}{{\glqq}}1 {“}{{\grqq}}1%
7751
{”}{{''}}1 {π}{{$\pi$}}1%
7852
}%
53+
%
54+
\lstdefinestyle{python_style}{%
55+
style=basic_style,%
56+
language=Python,%
57+
otherkeywords={\%,\},\{,\&,\|},%
58+
emph={and,break,class,continue,def,yield,del,elif,else,except,exec,finally,for,from,global,if,import,in,lambda,not,or,pass,print,raise,return,try,while,assert,with},%
59+
emph={[2]True,False,None},%
60+
emph={[3]object,type,isinstance,deepcopy,zip,enumerate,reversed,list,set,len,dict,tuple,xrange,append,execfile,real,imag,reduce,str,repr},%
61+
emph={[4]Exception,NameError,IndexError,SyntaxError,TypeError,ValueError,OverflowError,ZeroDivisionError},%
62+
emph={[5]ode,fsolve,sqrt,exp,sin,cos,arctan,arctan2,arccos,pi,array,norm,dot,arange,isscalar,max,sum,flatten,shape,reshape,find,any,all,abs,plot,linspace,legend,quad,polyval,polyfit,hstack,concatenate,vstack,column_stack,empty,zeros,ones,rand,vander,grid,pcolor,eig,eigs,eigvals,svd,qr,tan,det,logspace,roll,min,mean,cumsum,cumprod,diff,vectorize,lstsq,cla,eye,xlabel,ylabel,squeeze},%
63+
emph={[6]__init__,__add__,__mul__,__div__,__sub__,__call__,__getitem__,__setitem__,__eq__,__ne__,__new__,__nonzero__,__rmul__,__radd__,__repr__,__str__,__get__,__truediv__,__pow__,__name__,__future__,__all__},%
64+
emph={[7]assert,yield},%
65+
emph={[8]range},%
66+
morestring=[s]{"""}{"""},%
67+
}%
7968
\lstset{style=python_style}%
8069
%
8170
%
8271
\lstdefinestyle{text_style}{%
83-
%
84-
backgroundcolor=\color{listing-background},%
85-
numbers=left,%
86-
frame=single,%
87-
rulecolor=\color{listing-rule},%
88-
frameround=ffff,%
89-
%
90-
breaklines=true,%
91-
tabsize=4,%
92-
%
72+
style=basic_style,%
9373
language={},%
94-
sensitive=true,%
95-
%
9674
basicstyle=\@lstbasicstyle,%
97-
numberstyle=\color{listing-line-numbers},%
9875
identifierstyle=\@lstbasicstyle,%
9976
keywords={},%
10077
otherkeywords={},%
@@ -122,27 +99,15 @@ emph={[7]},%
12299
emphstyle={[7]\@lstbasicstyle},%
123100
emph={[8]},%
124101
emphstyle={[8]\@lstbasicstyle},%
125-
breaklines=true,%
126-
postbreak=\mbox{\textcolor{red}{$\hookrightarrow$}\space},%
127-
%
128-
literate=%
129-
{á}{{\'a}}1 {é}{{\'e}}1 {í}{{\'i}}1 {ó}{{\'o}}1 {ú}{{\'u}}1%
130-
{Á}{{\'A}}1 {É}{{\'E}}1 {Í}{{\'I}}1 {Ó}{{\'O}}1 {Ú}{{\'U}}1%
131-
{à}{{\`a}}1 {è}{{\'e}}1 {ì}{{\`i}}1 {ò}{{\`o}}1 {ù}{{\`u}}1%
132-
{À}{{\`A}}1 {È}{{\'E}}1 {Ì}{{\`I}}1 {Ò}{{\`O}}1 {Ù}{{\`U}}1%
133-
{ä}{{\"a}}1 {ë}{{\"e}}1 {ï}{{\"i}}1 {ö}{{\"o}}1 {ü}{{\"u}}1%
134-
{Ä}{{\"A}}1 {Ë}{{\"E}}1 {Ï}{{\"I}}1 {Ö}{{\"O}}1 {Ü}{{\"U}}1%
135-
{â}{{\^a}}1 {ê}{{\^e}}1 {î}{{\^i}}1 {ô}{{\^o}}1 {û}{{\^u}}1%
136-
{Â}{{\^A}}1 {Ê}{{\^E}}1 {Î}{{\^I}}1 {Ô}{{\^O}}1 {Û}{{\^U}}1%
137-
{œ}{{\oe}}1 {Œ}{{\OE}}1 {æ}{{\ae}}1 {Æ}{{\AE}}1 {ß}{{\ss}}1%
138-
{ç}{{\c c}}1 {Ç}{{\c C}}1 {ø}{{\o}}1 {å}{{\r a}}1 {Å}{{\r A}}1%
139-
{€}{{\EUR}}1 {£}{{\pounds}}1 {«}{{\guillemotleft}}1%
140-
{»}{{\guillemotright}}1 {ñ}{{\~n}}1 {Ñ}{{\~N}}1 {¿}{{?`}}1%
141-
{…}{{\ldots}}1 {≥}{{>=}}1 {≤}{{<=}}1 {„}{{\glqq}}1 {“}{{\grqq}}1%
142-
{”}{{''}}1 {π}{{$\pi$}}1%
102+
breaklines=true%
143103
}%
144104
%
145105
%
106+
\lstdefinestyle{bash_style}{%
107+
style=basic_style,%
108+
language=bash,%
109+
}%
110+
%
146111
%
147112
%% the box around the inline listings
148113
\protected\gdef\inlinelistingbox#1{\bgroup%
@@ -167,7 +132,7 @@ literate=%
167132
%% #1 the optional args
168133
%% #2 the code to be printed inline
169134
\gdef\bashil#1{%
170-
\inlinelistingbox{\lstinline[language=bash]$#1$}}%
135+
\inlinelistingbox{\lstinline[style=bash_style]$#1$}}%
171136
%
172137
\newlength\@lstbasicstylesheight%
173138
\settoheight{\@lstbasicstylesheight}{\mbox{\bgroup\@lstbasicstyle{s}\egroup}}%
@@ -188,9 +153,9 @@ literate=%
188153
%% #6 the style to use
189154
\protected\gdef\gitCode#1#2#3#4#5#6{%
190155
\gitLoad{#1}{#2}{#3}%
191-
\expandafter\expandafter\expandafter\edef\expandafter\csname @pwp@gitUrl:lst:#5\endcsname{\gitUrl}%
192-
\expandafter\expandafter\expandafter\edef\expandafter\csname @pwp@gitFile:lst:#5\endcsname{\gitFile}%
193-
\lstinputlisting[float,label={lst:#4}#6,caption={#5~(\href{\csname @pwp@gitUrl:lst:#5\endcsname}{src})}]{\csname @pwp@gitFile:lst:#5\endcsname}%
156+
\expandafter\expandafter\expandafter\edef\expandafter\csname @pwp@gitUrl:lst:#4\endcsname{\gitUrl}%
157+
\expandafter\expandafter\expandafter\edef\expandafter\csname @pwp@gitFile:lst:#4\endcsname{\gitFile}%
158+
\lstinputlisting[float,label={lst:#4}#6,caption={#5~(\href{\csname @pwp@gitUrl:lst:#4\endcsname}{src})}]{\csname @pwp@gitFile:lst:#4\endcsname}%
194159
}%
195160
%
196161
%%

text/back/backmatter.tex

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
\setulmarginsandblock{2.5cm}{2.5cm}{*}%0
99
\checkandfixthelayout%
1010
%
11+
\hsection{}%
12+
\hinput{.}{scripts.tex}%
13+
\endhsection%
14+
%
1115
\printBestPractices%
1216
\printglossaries%
1317
%

text/back/scripts.tex

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
\hsection{Scripts}%
2+
%
3+
Here we provide some scripts that are used within this book.
4+
The book focuses on \python\ programming, so \bash\ shell scripts are not in the center of our attention and may mess up the flow of chapters.
5+
Nevertheless, the book would be incomplete if these scripts were not provided as well.
6+
So we put them here, at the end of the book.%
7+
%
8+
\gitCode{\programmingWithPythonCodeRepo}{scripts/mypy.sh}{}{bash:mypy}{%
9+
A \bash\ script for executing \mypy, which prints the command line and the exit code.%
10+
}{,style=bash_style}%
11+
%
12+
\endhsection%
13+
%

text/main/basics/variables/typesAndTypeHints/typesAndTypeHints.tex

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,12 @@
8484
\end{figure}%
8585
%
8686
\gitOutput{\programmingWithPythonCodeRepo}{.}{scripts/mypy.sh 01_variables variable_types_wrong.py}{variables:variable_types_wrong:mypy}{%
87-
The results of static type checking with \mypy\ of the program given in \cref{lst:variables:types_wrong}.}%
87+
The results of static type checking with \mypy\ of the program given in \cref{lst:variables:types_wrong}. %
88+
(This is actually output generated by the script~\cref{lst:bash:mypy} on \cpageref{lst:bash:mypy}.)}%
8889
%
8990
\gitOutput{\programmingWithPythonCodeRepo}{.}{scripts/mypy.sh 01_variables variable_types.py}{variables:variable_types:mypy}{%
90-
The results of static type checking with \mypy\ of the program given in \cref{lst:variables:types}.}%
91+
The results of static type checking with \mypy\ of the program given in \cref{lst:variables:types}. %
92+
(This is actually output generated by the script~\cref{lst:bash:mypy} on \cpageref{lst:bash:mypy}.)}%
9193
%
9294
A first step to avoiding any type-related errors in programs is, ofcourse, careful programming.
9395
The second step is to use tools that check whether your program code contains ambiguities or errors.

0 commit comments

Comments
 (0)