Skip to content

Commit bae931f

Browse files
committed
Lots of github
1 parent d5a14e4 commit bae931f

16 files changed

+298
-130
lines changed

doc/source/1_introduction.rst

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ abstraction in mathematics, abstraction in coding is a form of
6363
constructive laziness: it simultaneously allows the mathematician to
6464
achieve more and do less work.
6565

66+
.. _tools:
67+
6668
Obtaining the right software tools
6769
----------------------------------
6870

@@ -127,6 +129,8 @@ Python you use.
127129
which were introduced in Python 3.6, so the code will not work in earlier
128130
versions of Python.
129131

132+
.. _venv:
133+
130134
Setting up a Python virtual environment
131135
---------------------------------------
132136

@@ -191,24 +195,26 @@ there then open the `View` menu and select `Terminal` to make it appear.
191195

192196
The most straightforward way to create a venv is on the terminal
193197
command line, not from within Python itself. This is accomplished
194-
using Python's :mod:`venv` package. For example, to create a venv
195-
called `my_venv` on Windows, you would type:
198+
using Python's :mod:`venv` package. The venv has to be given a name. You will
199+
want this to be short, but distinctive enough that you know which venv you are
200+
using. For example, to create a venv
201+
called `PoP_venv` on Windows, you would type:
196202

197203
.. code-block:: console
198204
199-
> py -m venv my_venv
205+
> py -m venv PoP_venv
200206
201207
while on Mac or Linux you would type:
202208

203209
.. code-block:: console
204210
205-
$ python3 -m venv my_venv
211+
$ python3 -m venv PoP_venv
206212
207213
Don't forget that the `>` or `$` stands for the command prompt: you don't
208-
type it. This command will create the folder `my_venv` and various
214+
type it. This command will create the folder `PoP_venv` and various
209215
subfolders containing things like the Python program itself and space
210216
for any packages which you install in the venv. If there was already a
211-
file or folder called `my_venv` in the current folder then you'll get
217+
file or folder called `PoP_venv` in the current folder then you'll get
212218
an error, so make sure you choose a new name.
213219

214220
.. note::
@@ -218,7 +224,7 @@ an error, so make sure you choose a new name.
218224
multiple Python installations on your computer then you might end up
219225
running the wrong one. If this happens then you will need to type the full
220226
path to the Python you want to use (starting with `/` on Mac or Linux or
221-
`\` on Windows). Once the venv is installed and activated, it will be
227+
`\\` on Windows). Once the venv is installed and activated, it will be
222228
sufficient to type `python` as the venv will ensure that this is the
223229
correct version.
224230

@@ -229,7 +235,7 @@ again. In the bash or zsh shells you would type:
229235

230236
.. code-block:: console
231237
232-
$ rm -rf my_venv
238+
$ rm -rf PoP_venv
233239
234240
.. warning::
235241

@@ -248,27 +254,27 @@ Linux you would type:
248254

249255
.. code-block:: console
250256
251-
$ source my_venv/bin/activate
257+
$ source PoP_venv/bin/activate
252258
253259
while using bash on Windows you would type:
254260

255261
.. code-block:: console
256262
257-
$ source my_venv/Scripts/activate
263+
$ source PoP_venv/Scripts/activate
258264
259265
If using PowerShell on Windows then you type:
260266

261267
.. code-block:: powershell
262268
263-
> .\my_venv\Scripts\activate.ps1
269+
> .\PoP_venv\Scripts\activate.ps1
264270
265271
Obviously, you would use the folder name of your venv instead of
266-
`my_venv`. In either case, your command prompt will change to indicate
272+
`PoP_venv`. In either case, your command prompt will change to indicate
267273
that you are now using the venv. It might look something like:
268274

269275
.. code-block:: console
270276
271-
(my_venv) $
277+
(PoP_venv) $
272278
273279
Any subsequent invocations of Python commands such as `python3` will
274280
now use the version from the venv, with access to whatever packages
@@ -285,8 +291,16 @@ for the correct activation command.
285291
286292
> Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
287293
288-
For further information, see :doc:`the official Python venv documentation
289-
<library/venv>`.
294+
.. only:: not book
295+
296+
For further information, see :doc:`the official Python venv documentation
297+
<library/venv>`.
298+
299+
.. only:: book
300+
301+
For further information, see the official Python venv documentation.
302+
[#venv]_
303+
290304

291305
.. hint::
292306

@@ -305,13 +319,13 @@ Python package :doc:`Pip <pip:index>`, which you will usually find
305319
pre-installed in your Python installation. Pip has many usage options, which
306320
enable a large number of different installation configurations. However, for
307321
most users most of the time, a few simple pip commands suffice. As with
308-
:term:`venv` creation, package installation is best accomplished from the
322+
venv creation, package installation is best accomplished from the
309323
terminal and not from within Python itself. Don't forget to activate the venv!
310324

311325
.. _install-from-pypi:
312326

313327
Installing packages from PyPI
314-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
328+
.............................
315329

316330
`PyPI <https://pypi.org>`__ is the Python Package Index. It is the
317331
official download location for publicly released Python packages which
@@ -324,7 +338,7 @@ terminal command:
324338

325339
.. code-block:: console
326340
327-
(my_venv) $ python -m pip install numpy
341+
(PoP_venv) $ python -m pip install numpy
328342
329343
It is also possible to invoke pip directly using the command `pip3`,
330344
but there are some circumstances where that might result in pip using
@@ -338,7 +352,7 @@ Pip can also be used to upgrade a package to the latest version:
338352

339353
.. code-block:: console
340354
341-
(my_venv) $ python -m pip install --upgrade numpy
355+
(PoP_venv) $ python -m pip install --upgrade numpy
342356
343357
Glossary
344358
--------
@@ -389,3 +403,10 @@ Glossary
389403
.. :ref:`Live Share instructions <vscode-liveshare>`.
390404
.. Ensure that each of you can start a Live Share session and have the other
391405
.. successfully join, and that all of you can edit files.
406+
407+
.. only:: book
408+
409+
.. rubric:: Footnotes
410+
411+
.. [#venv] `https://docs.python.org/3/library/venv.html
412+
<https://docs.python.org/3/library/venv.html>`__

doc/source/2_programs_in_files.rst

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ active, we can install it by running:
6767

6868
.. code-block:: console
6969
70-
(my_venv) $ python -m pip install ipython
70+
(PoP_venv) $ python -m pip install ipython
7171
7272
IPython can now be run by simply typing:
7373

7474
.. code-block:: console
7575
76-
(my_venv) $ ipython
76+
(PoP_venv) $ ipython
7777
7878
This will result in output simiar to the following:
7979

@@ -159,8 +159,8 @@ systems, you would type the following:
159159

160160
.. code-block:: console
161161
162-
(my_venv) $ cd src
163-
(my_venv) $ python hello.py
162+
(PoP_venv) $ cd src
163+
(PoP_venv) $ python hello.py
164164
165165
The first of these commands,
166166
`cd` (*change directory*) switches the current folder to :file:`src`. The
@@ -608,7 +608,7 @@ you would type:
608608

609609
.. code-block:: console
610610
611-
(my_venv) $ python -m pip install -e folder/
611+
(PoP_venv) $ python -m pip install -e folder/
612612
613613
replacing `folder` with the name of the top-level folder of your
614614
repository: the folder containing :file:`setup.py`. The option flag `-e`
@@ -708,7 +708,7 @@ your current environment using:
708708

709709
.. code-block:: console
710710
711-
(my_venv) $ python -m pip install pytest
711+
(PoP_venv) $ python -m pip install pytest
712712
713713
Pytest tests
714714
~~~~~~~~~~~~
@@ -767,8 +767,8 @@ We can then invoke the tests from the shell:
767767

768768
.. code-block:: console
769769
770-
(my_venv) $ cd fibonacci
771-
(my_venv) $ pytest tests
770+
(PoP_venv) $ cd fibonacci
771+
(PoP_venv) $ pytest tests
772772
========================== test session starts ===========================
773773
platform darwin -- Python 3.7.7, pytest-5.4.1, py-1.8.1, pluggy-0.13.1
774774
rootdir: /Users/dham/docs/object-oriented-programming, inifile: setup.cfg
@@ -784,7 +784,7 @@ instead see something like:
784784

785785
.. code-block:: console
786786
787-
(my_venv) $ pytest tests
787+
(PoP_venv) $ pytest tests
788788
========================== test session starts ===========================
789789
platform darwin -- Python 3.7.7, pytest-5.4.1, py-1.8.1, pluggy-0.13.1
790790
rootdir: /Users/dham/docs/object-oriented-programming, inifile: setup.cfg
@@ -821,14 +821,14 @@ that file as the argument to Pytest. For example:
821821

822822
.. code-block:: console
823823
824-
(my_venv) $ pytest tests/test_fibonacci.py
824+
(PoP_venv) $ pytest tests/test_fibonacci.py
825825
826826
It is even possible to select an individual test to run, using a double colon
827827
`::` followed by the test name:
828828

829829
.. code-block:: console
830830
831-
(my_venv) $ pytest tests/test_fibonacci.py::test_fibonacci_values
831+
(PoP_venv) $ pytest tests/test_fibonacci.py::test_fibonacci_values
832832
833833
Often if one test fails then the same problem in your code will cause a whole
834834
series of tests to fail, resulting in a very long list of error messages which
@@ -837,7 +837,7 @@ tells Pytest to stop after the first test fail. For example:
837837

838838
.. code-block:: console
839839
840-
(my_venv) $ pytest -x tests
840+
(PoP_venv) $ pytest -x tests
841841
842842
The tests are often arranged in increasing order of sophistication, so the
843843
earlier tests are likely to catch the most basic errors in your code. For this
@@ -925,19 +925,23 @@ Glossary
925925
Exercises
926926
---------
927927

928-
.. panels::
929-
:card: quiz shadow
928+
Before attempting the exercises, ensure that you have obtained the software
929+
tools described in :numref:`tools` and set up a working folder and
930+
:term:`virtual environment` as described in :numref:`venv`.
930931

931-
.. link-button:: https://bb.imperial.ac.uk/webapps/assessment/take/launchAssessment.jsp?course_id=_25965_1&content_id=_2054443_1&mode=cpview
932-
:text: This week's quiz
933-
:classes: stretched-link
932+
.. .. panels::
933+
.. :card: quiz shadow
934934
935-
.. proof:exercise::
935+
.. .. link-button:: https://bb.imperial.ac.uk/webapps/assessment/take/launchAssessment.jsp?course_id=_25965_1&content_id=_2054443_1&mode=cpview
936+
.. :text: This week's quiz
937+
.. :classes: stretched-link
938+
939+
.. .. proof:exercise::
936940

937-
Follow the :ref:`instructions on the Faculty of Natural Sciences Python
938-
installation page <fons:python_folders>` to create the folder structure
939-
you will use for this course on your computer. Start with an overall folder
940-
for the module, and create a virtual environment in that module.
941+
.. Follow the :ref:`instructions on the Faculty of Natural Sciences Python
942+
.. installation page <fons:python_folders>` to create the folder structure
943+
.. you will use for this course on your computer. Start with an overall folder
944+
.. for the module, and create a virtual environment in that module.
941945
942946
.. _course_repo:
943947

@@ -951,7 +955,7 @@ Exercises
951955

952956
.. code-block:: console
953957
954-
(my_venv) $ pytest tests/test_fibonacci.py
958+
(PoP_venv) $ pytest tests/test_fibonacci.py
955959
956960
You could also run iPython, import :mod:`fibonacci` and try out
957961
:func:`fibonacci.fib <fibonacci.fibonacci.fib>` yourself.
@@ -976,7 +980,7 @@ Exercises
976980

977981
.. code-block:: console
978982
979-
(my_venv) $ pytest tests/test_exercise_2_4.py
983+
(PoP_venv) $ pytest tests/test_exercise_2_4.py
980984
981985
Then push your code to GitHub and check that the tests pass there too.
982986

0 commit comments

Comments
 (0)