Skip to content

Commit d10511e

Browse files
committed
Website build
1 parent 359c66f commit d10511e

File tree

9 files changed

+435
-41
lines changed

9 files changed

+435
-41
lines changed

2_programs_in_files.html

Lines changed: 60 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,20 @@ <h3><span class="section-number">2.4.3. </span>When not to use scripts<a class="
289289
</div>
290290
<div class="section" id="modules">
291291
<span id="id2"></span><h2><span class="section-number">2.5. </span>Modules<a class="headerlink" href="#modules" title="Permalink to this headline"></a></h2>
292-
<p>A module is, like a script, a plain text file containing Python
292+
<details class="sphinx-bs dropdown card mb-3">
293+
<summary class="summary-title card-header">
294+
Video: a first Python module.<div class="summary-down docutils">
295+
<svg version="1.1" width="24" height="24" class="octicon octicon-chevron-down" viewBox="0 0 24 24" aria-hidden="true"><path fill-rule="evenodd" d="M5.22 8.72a.75.75 0 000 1.06l6.25 6.25a.75.75 0 001.06 0l6.25-6.25a.75.75 0 00-1.06-1.06L12 14.44 6.28 8.72a.75.75 0 00-1.06 0z"></path></svg></div>
296+
<div class="summary-up docutils">
297+
<svg version="1.1" width="24" height="24" class="octicon octicon-chevron-up" viewBox="0 0 24 24" aria-hidden="true"><path fill-rule="evenodd" d="M18.78 15.28a.75.75 0 000-1.06l-6.25-6.25a.75.75 0 00-1.06 0l-6.25 6.25a.75.75 0 101.06 1.06L12 9.56l5.72 5.72a.75.75 0 001.06 0z"></path></svg></div>
298+
</summary><div class="summary-content card-body docutils">
299+
<div class="vimeo docutils container">
300+
<iframe src="https://player.vimeo.com/video/486845755"
301+
frameborder="0" allow="autoplay; fullscreen"
302+
allowfullscreen></iframe></div>
303+
<p class="card-text">Imperial students can also <a class="reference external" href="https://imperial.cloud.panopto.eu/Panopto/Pages/Viewer.aspx?id=972f92c6-6b55-4510-9c2c-ac8600fca11a">watch this video on Panopto</a></p>
304+
</div>
305+
</details><p>A module is, like a script, a plain text file containing Python
293306
code. Modules must have names ending in <code class="file docutils literal notranslate"><span class="pre">.py</span></code>. So far, that’s
294307
identical to a script. Indeed, it’s sometimes possible (though not
295308
always advisable) to use the same file as both a script and a
@@ -348,7 +361,7 @@ <h3><span class="section-number">2.5.1. </span>Importing and namespaces<a class=
348361
<p>Namespaces are a simple but fundamental concept in programming. To
349362
quote one of the key developers of the Python language:</p>
350363
<blockquote>
351-
<div><p>Namespaces are one honking great idea – let’s do more of those! <a class="footnote-reference brackets" href="#peters" id="id3">1</a></p>
364+
<div><p>Namespaces are one honking great idea – let’s do more of those! <a class="footnote-reference brackets" href="#peters" id="id4">1</a></p>
352365
</div></blockquote>
353366
<div class="admonition note">
354367
<p class="admonition-title">Note</p>
@@ -426,7 +439,20 @@ <h3><span class="section-number">2.5.2. </span>Other forms of import<a class="he
426439
</div>
427440
<div class="section" id="packages">
428441
<h2><span class="section-number">2.6. </span>Packages<a class="headerlink" href="#packages" title="Permalink to this headline"></a></h2>
429-
<p>Modules are the principal mechanism for storing code which is intended
442+
<details class="sphinx-bs dropdown card mb-3">
443+
<summary class="summary-title card-header">
444+
Video: a first Python package.<div class="summary-down docutils">
445+
<svg version="1.1" width="24" height="24" class="octicon octicon-chevron-down" viewBox="0 0 24 24" aria-hidden="true"><path fill-rule="evenodd" d="M5.22 8.72a.75.75 0 000 1.06l6.25 6.25a.75.75 0 001.06 0l6.25-6.25a.75.75 0 00-1.06-1.06L12 14.44 6.28 8.72a.75.75 0 00-1.06 0z"></path></svg></div>
446+
<div class="summary-up docutils">
447+
<svg version="1.1" width="24" height="24" class="octicon octicon-chevron-up" viewBox="0 0 24 24" aria-hidden="true"><path fill-rule="evenodd" d="M18.78 15.28a.75.75 0 000-1.06l-6.25-6.25a.75.75 0 00-1.06 0l-6.25 6.25a.75.75 0 101.06 1.06L12 9.56l5.72 5.72a.75.75 0 001.06 0z"></path></svg></div>
448+
</summary><div class="summary-content card-body docutils">
449+
<div class="vimeo docutils container">
450+
<iframe src="https://player.vimeo.com/video/487003753"
451+
frameborder="0" allow="autoplay; fullscreen"
452+
allowfullscreen></iframe></div>
453+
<p class="card-text">Imperial students can also <a class="reference external" href="https://imperial.cloud.panopto.eu/Panopto/Pages/Viewer.aspx?id=c4b0aedd-02a8-45d1-946b-ac86015b6d0b">watch this video on Panopto</a></p>
454+
</div>
455+
</details><p>Modules are the principal mechanism for storing code which is intended
430456
to be used by other code. However, putting all of the code for a
431457
complex area of mathematics in a single huge Python file is not a
432458
great idea. Readers of that code will struggle to see the logical
@@ -487,7 +513,7 @@ <h2><span class="section-number">2.6. </span>Packages<a class="headerlink" href=
487513
</dd>
488514
</dl>
489515
<div class="section" id="importing-packages">
490-
<span id="id4"></span><h3><span class="section-number">2.6.1. </span>Importing packages<a class="headerlink" href="#importing-packages" title="Permalink to this headline"></a></h3>
516+
<span id="id6"></span><h3><span class="section-number">2.6.1. </span>Importing packages<a class="headerlink" href="#importing-packages" title="Permalink to this headline"></a></h3>
491517
<p>The system for importing packages is the same as that described in
492518
<a class="reference internal" href="#modules"><span class="std std-numref">Section 2.5</span></a>, though the nested nature of packages makes the
493519
process somewhat more involved. Importing a package also imports all
@@ -595,15 +621,28 @@ <h3><span class="section-number">2.6.3. </span>Installing a package from local c
595621
</div>
596622
<div class="section" id="testing-frameworks">
597623
<h2><span class="section-number">2.7. </span>Testing frameworks<a class="headerlink" href="#testing-frameworks" title="Permalink to this headline"></a></h2>
598-
<p>Attempting to establish whether a program correctly implements the
624+
<details class="sphinx-bs dropdown card mb-3">
625+
<summary class="summary-title card-header">
626+
Video: introducing Pytest.<div class="summary-down docutils">
627+
<svg version="1.1" width="24" height="24" class="octicon octicon-chevron-down" viewBox="0 0 24 24" aria-hidden="true"><path fill-rule="evenodd" d="M5.22 8.72a.75.75 0 000 1.06l6.25 6.25a.75.75 0 001.06 0l6.25-6.25a.75.75 0 00-1.06-1.06L12 14.44 6.28 8.72a.75.75 0 00-1.06 0z"></path></svg></div>
628+
<div class="summary-up docutils">
629+
<svg version="1.1" width="24" height="24" class="octicon octicon-chevron-up" viewBox="0 0 24 24" aria-hidden="true"><path fill-rule="evenodd" d="M18.78 15.28a.75.75 0 000-1.06l-6.25-6.25a.75.75 0 00-1.06 0l-6.25 6.25a.75.75 0 101.06 1.06L12 9.56l5.72 5.72a.75.75 0 001.06 0z"></path></svg></div>
630+
</summary><div class="summary-content card-body docutils">
631+
<div class="vimeo docutils container">
632+
<iframe src="https://player.vimeo.com/video/486987209"
633+
frameborder="0" allow="autoplay; fullscreen"
634+
allowfullscreen></iframe></div>
635+
<p class="card-text">Imperial students can also <a class="reference external" href="https://imperial.cloud.panopto.eu/Panopto/Pages/Viewer.aspx?id=c636383d-6125-4a7c-bad7-ac86015b6d4c">watch this video on Panopto</a></p>
636+
</div>
637+
</details><p>Attempting to establish whether a program correctly implements the
599638
intended algorithm is core to effective programming, and programmers
600639
often spend more time correcting bugs than writing new code. We will
601640
turn to the question of how to debug in <a class="reference internal" href="9_debugging.html#debugging"><span class="std std-numref">Section 9</span></a>. However,
602641
right from the start, we need to test the code we write, so we will cover
603642
the practical details of including tests in your code here.</p>
604643
<p>There are a number of Python packages which support code testing. The
605644
concepts are largely similar so rather than get bogged down in the
606-
details of multiple frameworks, we will introduce <a class="reference external" href="https://docs.pytest.org/en/latest/index.html" title="(in pytest v0.1.dev212+g64bb5f2)"><span class="xref std std-doc">pytest</span></a>, which is one of the most widely used.</p>
645+
details of multiple frameworks, we will introduce <a class="reference external" href="https://docs.pytest.org/en/latest/index.html" title="(in pytest v0.1.dev244+g902739c)"><span class="xref std std-doc">pytest</span></a>, which is one of the most widely used.</p>
607646
<div class="section" id="pytest-tests">
608647
<h3><span class="section-number">2.7.1. </span>Pytest tests<a class="headerlink" href="#pytest-tests" title="Permalink to this headline"></a></h3>
609648
<p>A Pytest test is simply a function whose name starts with <code class="xref py py-obj docutils literal notranslate"><span class="pre">test_</span></code>. In
@@ -757,7 +796,7 @@ <h2><span class="section-number">2.8. </span>Writing code to a specified interfa
757796
right names, accepting arguments of the correct type and so on. If it does not,
758797
then the tests will simply fail. Changing the tests to suit your preferred
759798
interface is not an acceptable answer, your code needs to comply with the
760-
interface specified in the tests <a class="footnote-reference brackets" href="#interface-errors" id="id5">2</a>.</p>
799+
interface specified in the tests <a class="footnote-reference brackets" href="#interface-errors" id="id8">2</a>.</p>
761800
<p>This requirement to code to a published specification is not an artifact of the
762801
testing framework: it is often the case that code written in a research or
763802
business setting needs to conform with a standard or other published interface
@@ -797,7 +836,7 @@ <h2><span class="section-number">2.10. </span>Exercises<a class="headerlink" hre
797836
<p class="admonition-title">Note</p>
798837
<p>Put a link to the first week quiz here.</p>
799838
</div>
800-
<div class="proof proof-type-exercise" id="id6">
839+
<div class="proof proof-type-exercise" id="id9">
801840

802841
<div class="proof-title">
803842
<span class="proof-type">Exercise 2.1</span>
@@ -807,7 +846,7 @@ <h2><span class="section-number">2.10. </span>Exercises<a class="headerlink" hre
807846
installation page</span></a> to create the folder structure
808847
you will use for this course on your computer. Start with an overall folder
809848
for the module, and create a virtual environment in that module.</p>
810-
</div></div><div class="proof proof-type-exercise" id="id7">
849+
</div></div><div class="proof proof-type-exercise" id="id10">
811850

812851
<div class="proof-title">
813852
<span class="proof-type">Exercise 2.2</span>
@@ -816,14 +855,18 @@ <h2><span class="section-number">2.10. </span>Exercises<a class="headerlink" hre
816855
<p>Visit the <a class="reference external" href="https://github.com/object-oriented-python/object-oriented-programming">GitHub repository for these notes</a>.
817856
Clone that git repository into your course folder, and install the Python
818857
package it contains into your virtual environment. Check that it has
819-
installed correctly by running IPython, importing <a class="reference internal" href="fibonacci.html#module-fibonacci" title="fibonacci"><code class="xref py py-mod docutils literal notranslate"><span class="pre">fibonacci</span></code></a> and
820-
trying out <a class="reference internal" href="fibonacci.html#fibonacci.fibonacci.fib" title="fibonacci.fibonacci.fib"><code class="xref py py-func docutils literal notranslate"><span class="pre">fibonacci.fib</span></code></a>.</p>
858+
installed correctly by installing pytest, and running:</p>
859+
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp">$</span> pytest tests/test_fibonacci.py
860+
</pre></div>
861+
</div>
862+
<p>You could also run iPython, import <a class="reference internal" href="fibonacci.html#module-fibonacci" title="fibonacci"><code class="xref py py-mod docutils literal notranslate"><span class="pre">fibonacci</span></code></a> and try out
863+
<a class="reference internal" href="fibonacci.html#fibonacci.fibonacci.fib" title="fibonacci.fibonacci.fib"><code class="xref py py-func docutils literal notranslate"><span class="pre">fibonacci.fib</span></code></a> yourself.</p>
821864
</div></div><div class="admonition note">
822865
<p class="admonition-title">Note</p>
823866
<p>The first GitHub classroom assignment for this module will be released at
824867
the start of term.</p>
825868
</div>
826-
<div class="proof proof-type-exercise" id="id8">
869+
<div class="proof proof-type-exercise" id="id11">
827870

828871
<div class="proof-title">
829872
<span class="proof-type">Exercise 2.3</span>
@@ -832,7 +875,7 @@ <h2><span class="section-number">2.10. </span>Exercises<a class="headerlink" hre
832875
<p>Accept the <a class="reference internal" href="not_released.html"><span class="doc">first Github Classroom assignment for this module</span></a> and clone it into your course folder. The assignment
833876
repository just contains a <code class="file docutils literal notranslate"><span class="pre">README</span></code> and some tests. Your job in the
834877
following exercises will be to populate it with the remaining content.</p>
835-
</div></div><div class="proof proof-type-exercise" id="id9">
878+
</div></div><div class="proof proof-type-exercise" id="id12">
836879

837880
<div class="proof-title">
838881
<span class="proof-type">Exercise 2.4</span>
@@ -861,7 +904,7 @@ <h2><span class="section-number">2.10. </span>Exercises<a class="headerlink" hre
861904
about how to do any of these, refer back the <a class="reference external" href="https://imperial-fons-computing.github.io/git.html#github-classroom-exercise" title="(in Installation instructions for FoNS v2020.0)"><span class="xref std std-ref">Faculty of Natural Sciences
862905
Git instructions</span></a>.</p>
863906
</div>
864-
</div></div><div class="proof proof-type-exercise" id="id10">
907+
</div></div><div class="proof proof-type-exercise" id="id13">
865908

866909
<div class="proof-title">
867910
<span class="proof-type">Exercise 2.5</span>
@@ -870,7 +913,7 @@ <h2><span class="section-number">2.10. </span>Exercises<a class="headerlink" hre
870913
<p>Following <a class="reference internal" href="#installable-packages"><span class="std std-numref">Section 2.6.2</span></a>, create a <code class="file docutils literal notranslate"><span class="pre">setup.py</span></code> file in
871914
your exercise repository, so that the <code class="xref py py-mod docutils literal notranslate"><span class="pre">math_utils</span></code> <a class="reference internal" href="#term-package"><span class="xref std std-term">package</span></a> is
872915
installable.</p>
873-
</div></div><div class="proof proof-type-exercise" id="id11">
916+
</div></div><div class="proof proof-type-exercise" id="id14">
874917

875918
<div class="proof-title">
876919
<span class="proof-type">Exercise 2.6</span>
@@ -883,10 +926,10 @@ <h2><span class="section-number">2.10. </span>Exercises<a class="headerlink" hre
883926
</div>
884927
</div></div><p class="rubric">Footnotes</p>
885928
<dl class="footnote brackets">
886-
<dt class="label" id="peters"><span class="brackets"><a class="fn-backref" href="#id3">1</a></span></dt>
929+
<dt class="label" id="peters"><span class="brackets"><a class="fn-backref" href="#id4">1</a></span></dt>
887930
<dd><p>Tim Peters, <a class="reference external" href="https://www.python.org/dev/peps/pep-0020/">“PEP 20 – The Zen Of Python” (2004)</a></p>
888931
</dd>
889-
<dt class="label" id="interface-errors"><span class="brackets"><a class="fn-backref" href="#id5">2</a></span></dt>
932+
<dt class="label" id="interface-errors"><span class="brackets"><a class="fn-backref" href="#id8">2</a></span></dt>
890933
<dd><p>Of course if you find a case where it appears that the
891934
tests don’t honour the interface published in the exercise, you should raise
892935
an issue reporting this.</p>

0 commit comments

Comments
 (0)