Skip to content

Commit f866f70

Browse files
committed
first steps towards packages chapter
1 parent 6535af9 commit f866f70

File tree

8 files changed

+82
-1
lines changed

8 files changed

+82
-1
lines changed

styles/listing.sty

+27-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ breaklines=true%
256256
\protected\gdef\gitPythonAndOutputFormatDefault{\gitPythonAndOutputFormat{text_style}}%
257257
\gitPythonAndOutputFormatDefault%
258258
%
259-
%% Use latexgit to place a listing with code and the program output.
259+
%% Use latexgit to place a listing with Python code and the program output.
260260
%% #1 the git repository
261261
%% #2 the path to the directory
262262
%% #3 the path to the file inside the directory
@@ -285,6 +285,32 @@ $\downarrow$~~\expandafter\bashil{python3 #3}~~$\downarrow$%
285285
\end{figure}%
286286
}%
287287
%
288+
%% Use latexgit to place a listing with Bash code and the program output.
289+
%% #1 the git repository
290+
%% #2 the path to the directory
291+
%% #3 the path to the file inside the directory
292+
%% #4 the label (lst: will be prepended to the program, exec: will be
293+
%% pre-pended to the output)
294+
%% #5 the caption
295+
\protected\gdef\gitBashAndOutput#1#2#3#4#5{%
296+
%
297+
\gitLoad{#1}{#2/#3}{}%
298+
\expandafter\expandafter\expandafter\edef\expandafter\csname @pwp@gitUrl:lst:#4\endcsname{\gitUrl}%
299+
\expandafter\expandafter\expandafter\edef\expandafter\csname @pwp@gitFile:lst:#4\endcsname{\gitFile}%
300+
\gitExec{#1}{#2}{bash #3}%
301+
\expandafter\expandafter\expandafter\edef\expandafter\csname @pwp@gitFile:exec:#4\endcsname{\gitFile}%
302+
%
303+
\begin{figure}[tb]%
304+
\centering%
305+
\lstinputlisting[label={lst:#4},style=bash_style,caption={#5~(stored in file~\href{\csname @pwp@gitUrl:lst:#4\endcsname}{\textil{#3}}; output in~\cref{exec:#4})}]{\csname @pwp@gitFile:lst:#4\endcsname}%
306+
%
307+
$\downarrow$~~\expandafter\bashil{bash #3}~~$\downarrow$%
308+
%
309+
\edef\@@@@gitOutputFmt{\csname @gitPythonAndOutputFormat:exec:#4\endcsname}%
310+
\lstinputlisting[label={exec:#4},style=tool_style,caption={The \gls{stdout} of the program~\href{\csname @pwp@gitUrl:lst:#4\endcsname}{\textil{#3}} given in~\cref{lst:#4}.}]{\csname @pwp@gitFile:exec:#4\endcsname}%
311+
\end{figure}%
312+
}%
313+
%
288314
%
289315
%% Use latexgit to place a listing with code and the program output.
290316
%% Ignore errors.

text/main/mainmatter.tex

+1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
\hinput{basics}{basics.tex}%
77
\hinput{controlFlow}{controlFlow.tex}%
88
\hinput{classes}{classes.tex}%
9+
\hinput{packages}{packages.tex}%
910
%

text/main/packages/packages.tex

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
%
2+
\hsection{Packages}%
3+
%
4+
\begin{figure}%
5+
\centering%
6+
\includegraphics[width=0.68\linewidth]{\currentDir/pypi}%
7+
\caption{A screenshot of the website \url{https://pypi.org}, the \python\ Package Index~\cite{PSF2024TPPIP}, taken on \mbox{2024-12-24}.}%
8+
\label{fig:pypi}%
9+
\end{figure}%
10+
%
11+
As already mentioned very early on in this book, one important strength of \python\ is the wide range of available packages.
12+
A package in \python\ is a piece of software, a library, that bundles some functionality and that can be installed on a system to make that functionality usable.
13+
Many of these packages are open source software and they are available for anyone to use, free of charge.
14+
The number one source for such packages is the \python\ Package Index~\cite{PSF2024TPPIP}, a website from which they can be downloaded and installed, illustrated in \cref{fig:pypi}.
15+
In this section of the book, we will focus on how we can obtain and use packages.%
16+
%
17+
\hinput{pipAndVenv}{pipAndVenv.tex}%
18+
\endhsection%
19+
%
Binary file not shown.
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
%
2+
\hsection{Pip and Virtual Environments}%
3+
%
4+
The go-to tool for installing \python\ packages is \pip.
5+
The standard way to install packages for use with \python\ is in a so-called virtual environment.
6+
%
7+
\hsection{Pip and Virtual Environments in \ubuntu\ \linux}%
8+
%
9+
\begin{figure}%
10+
\centering%
11+
\includegraphics[width=0.7\linewidth]{\currentDir/installPipVenvUbuntu}%
12+
\caption{Installing \pip\ and venv under \ubuntu\ \linux: \pip~is usually already installed, venv not. %
13+
We need to use the \bashil{apt-get} route to make sure that both \bashil{python3-pip} and \bashil{python3-venv} are installed.}%
14+
\label{fig:installPipVenvUbuntu}%
15+
\end{figure}%
16+
%
17+
\gitBashAndOutput{\programmingWithPythonCodeRepo}{10_packages}{numpy_user_venv.sh}{packages:numpy_user_venv}{%
18+
An example of using virtual environments and \pip\ under \ubuntu\ \linux.}%
19+
%
20+
\endhsection%
21+
%
22+
\hsection{Pip and Virtual Environments under \windows}%
23+
%
24+
\begin{figure}%
25+
\centering%
26+
\tightbox{\includegraphics[width=0.85\linewidth]{\currentDir/installPipVenvWindows}}%
27+
\caption{Installing \pip\ and venv under \windows: They are already installed.}%
28+
\label{fig:installPipVenvWindows}%
29+
\end{figure}%
30+
\endhsection%
31+
%
32+
\FloatBarrier%
33+
\endhsection%
34+
%

text/main/packages/pypi.pdf

148 KB
Binary file not shown.

text/main/packages/pypi.svg

+1
Loading

0 commit comments

Comments
 (0)