Wednesday, July 14, 2021

Python Bytes: #242 from lib import * but less

<p><strong>Watch the live stream:</strong></p> <a href='https://www.youtube.com/watch?v=rrpRqdeSw_8' style='font-weight: bold;'>Watch on YouTube</a><br> <br> <p><strong>About the show</strong></p> <p>Sponsored by <strong>us:</strong></p> <ul> <li>Check out the <a href="https://training.talkpython.fm/courses/all"><strong>courses over at Talk Python</strong></a></li> <li>And <a href="https://pythontest.com/pytest-book/"><strong>Brian’s book too</strong></a>!</li> </ul> <p>Special guest: <strong>Al Sweigart</strong></p> <p><strong>Brain #1:</strong> <a href="https://github.com/casey/just"><strong>just</strong></a></p> <ul> <li><a href="https://twitter.com/webology/status/1415304388969705482?s=20">From a tweet by Jeff Triplett</a></li> <li>“<code>just</code> is a handy way to save and run project-specific commands.</li> <li>Commands, called recipes, are stored in a file called <code>justfile</code> with syntax inspired by <code>make</code></li> <li>Just is a command runner, not a build system, so it avoids much of Make’s complexity and idiosyncrasies. No need for .PHONY recipes!</li> <li>Linux, MacOS, and Windows are supported with no additional dependencies.”</li> <li>It’s written in Rust.</li> <li>My favorite differences: <ul> <li>a couple spaces is fine, no need for tabs</li> <li>Recipes can accept command line arguments</li> <li>Recipes can be <a href="https://github.com/casey/just#listing-available-recipes">listed from the command line</a>.</li> <li>Recipes can be written in <a href="https://github.com/casey/just#writing-recipes-in-other-languages">arbitrary languages</a>, </li> </ul></li> </ul> <pre><code>like Python hello: echo "Hello World!" pyhello: #!/usr/bin/env python3 print('Hello from python!') </code></pre> <p><strong>Michael #2:</strong> <a href="https://twitter.com/roman_the_right/status/1403077836693544966"><strong>Strong Typing</strong></a></p> <ul> <li>via Roman Right (Beanie)</li> <li>Decorator which checks whether the function is called with the correct type of parameters.</li> <li>Decorator which <strong>checks at Runtime</strong> whether the function is called with the correct type of parameters.</li> <li><strong><em>Raises</em></strong> <strong>TypeMisMatch</strong> if the used parameters in a function call where invalid.</li> </ul> <p><strong>Al #3:</strong></p> <ul> <li>New book: <a href="https://inventwithpython.com/bigbookpython/">“The Big Book of Small Python Projects”</a></li> <li>New book: <a href="https://inventwithpython.com/beyond/">“Beyond the Basic Stuff with Python”</a></li> </ul> <p><strong>Brian #4:</strong> <a href="https://testbook.readthedocs.io/en/latest/index.html#"><strong>testbook</strong></a></p> <ul> <li><a href="https://twitter.com/nicholdav/status/1415329582014767106?s=20">Suggested by David Nicholson</a> <ul> <li>Write conventional unit tests for Jupyter Notebooks</li> <li><a href="https://testbook.readthedocs.io/en/latest/usage/index.html#using-execute-to-control-which-cells-are-executed-before-test">Execute all or some specific cells before unit test</a></li> <li><a href="https://testbook.readthedocs.io/en/latest/usage/index.html#share-kernel-context-across-multiple-tests">Share kernel context across multiple tests</a> (using pytest fixtures)</li> <li><a href="https://testbook.readthedocs.io/en/latest/usage/index.html#support-for-patching-objects">Support for patching objects</a></li> <li>Inject code into Jupyter notebooks</li> <li>Works with any unit testing library, unittest, pytest, etc.</li> </ul></li> <li>example <code>foo.ipynb</code>:</li> </ul> <pre><code> def foo(a, b): return a + b </code></pre> <ul> <li><code>test_foo.py</code>:</li> </ul> <pre><code> from testbook import testbook @testbook('foo.ipynb', execute=True) def test_foo(tb): foo = tb.ref("foo") assert foo(1, 2) == 3 </code></pre> <p><strong>Michael #5:</strong> <a href="https://github.com/jongracecox/auto-all"><strong>auto-all</strong></a></p> <ul> <li>Automatically manage the __all__ variable in Python modules. <ul> <li>Easily populate the <code>__all__</code> variable in modules.</li> <li>Easily exclude imported objects</li> <li>Clearly differentiate between internal and external facing objects.</li> <li>Use simple, intuitive code.</li> <li>Never worry about forgetting to add new objects to <code>__all__</code>.</li> <li>Help Python IDE's differentiate between internal and external facing objects.</li> </ul></li> <li>Can use “regions” via <code>start_all()</code> and <code>end_all()</code></li> <li>I prefer the decorator (functions only, seems ripe for a PR for classes)</li> </ul> <pre><code> @public def a_public_function(): pass </code></pre> <p><strong>Al #6:</strong></p> <ul> <li>Next book: Untitled Recursion Book</li> </ul> <p><strong>Extras</strong></p> <p>Michael:</p> <ul> <li><a href="https://twitter.com/feoh/status/1413678332743495682"><strong>OhMyPosh + auto env</strong></a></li> <li><a href="https://academic.oup.com/sleep/article/44/1/zsaa168/5905594"><strong>A scalable method of determining physiological endotypes of sleep apnea from a polysomnographic sleep study</strong></a></li> <li>Email, inbox woes, and catching up</li> <li><a href="https://news.microsoft.com/2021/07/14/microsoft-unveils-windows-365-ushering-in-a-new-category-of-computing/"><strong>Microsoft unveils Windows 365</strong></a></li> <li><a href="https://9to5mac.com/2021/07/14/facebook-tracking-app-tracking-data/"><strong>Facebook and its advertisers are ‘panicking’ as the majority of iPhone users opt out of tracking</strong></a></li> </ul> <p><strong>Al</strong></p> <ul> <li><a href="https://github.com/asweigart/pyautogui">GitHub repo for PyAutoGUI</a></li> </ul>

from Planet Python
via read more

No comments:

Post a Comment

TestDriven.io: Working with Static and Media Files in Django

This article looks at how to work with static and media files in a Django project, locally and in production. from Planet Python via read...