Thursday, August 12, 2021

Python Bytes: #246 Love your crashes, use Rich to beautify tracebacks

<p><strong>Watch the live stream:</strong></p> <a href='https://www.youtube.com/watch?v=I_F9YSiLSaI' 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: <a href="https://twitter.com/davidouglasmit"><strong>David Smit</strong></a></p> <p><strong>Brain #1:</strong> <a href="https://github.com/koaning/mktestdocs"><strong>mktestdocs</strong></a></p> <ul> <li><a href="https://twitter.com/fishnets88">Vincent D. Warmerdam</a></li> <li><a href="https://calmcode.io/labs/mktestdocs.html">Tutorial with videos</a></li> <li>Utilities to check for valid Python code within markdown files and markdown formatted docstrings.</li> <li>Example:</li> </ul> <pre><code> import pathlib import pytest from mktestdocs import check_md_file @pytest.mark.parametrize('fpath', pathlib.Path("docs").glob("**/*.md"), ids=str) def test_files_good(fpath): check_md_file(fpath=fpath) </code></pre> <ul> <li>This will take any codeblock that starts with <em>```python</em> and run it, checking for any errors that might happen. </li> <li>Putting <code>assert</code> statements in the code block will actually check things.</li> <li>Other examples in README.md for markdown formatted docstrings from functions and classes.</li> <li>Suggested usage is for code in mkdocs documentation.</li> <li>I’m planning on trying it with blog posts.</li> </ul> <p><strong>Michael #2:</strong> <a href="https://twitter.com/shacker/status/1242509337517580288">Redis powered queues</a> (QR3)</p> <ul> <li><a href="https://twitter.com/shacker/status/1242509337517580288">via Scot Hacker</a></li> <li>QR queues store serialized Python objects (using <a href="http://docs.python.org/library/pickle.html">cPickle</a> by default), but that can be changed by setting the serializer on a per-queue basis.</li> <li>There are a few constraints on what can be pickled, and thus put into queues</li> <li>Create a queue:</li> <li><code>bqueue = Queue('brand_new_queue_name', host='localhost', port=9000)</code></li> <li>Add items to the queue</li> </ul> <pre><code> &gt;&gt; bqueue.push('Pete') &gt;&gt; bqueue.push('John') &gt;&gt; bqueue.push('Paul') &gt;&gt; bqueue.push('George') </code></pre> <ul> <li>Getting items out</li> </ul> <pre><code> &gt;&gt; bqueue.pop() 'Pete' </code></pre> <ul> <li>Also supports <strong>deque</strong>, or double-ended queue, capped collections/queues, and <strong>priority queues</strong>.</li> </ul> <p><strong>David #3:</strong> <strong><a href="https://towardsdatascience.com/25-pandas-functions-you-didnt-know-existed-p-guarantee-0-8-1a05dcaad5d0">25 Pandas Functions You Didn’t Know Existed</a></strong></p> <ul> <li>Bex T</li> <li>So often, I come across a pandas method or function that makes me go “AH!” because it saves me so much time and simplifies my code <ul> <li>Example: Transform</li> </ul></li> <li>Don’t normally like these articles, but this one had several “AH” moments <ul> <li>between</li> <li>styler</li> <li>options</li> <li>convert dtypes</li> <li>mask</li> <li>nasmallest, nalargest</li> <li>clip</li> <li>attime</li> </ul></li> </ul> <p><strong>Brian #4:</strong> <a href="https://blog.hay-kot.dev/fastapi-and-rich-tracebacks-in-development/"><strong>FastAPI and Rich Tracebacks in Development</strong></a></p> <ul> <li><a href="https://twitter.com/kot_hay">Hayden Kotelman</a></li> <li>Rich has, among other cool features, beautiful tracebacks and logging.</li> <li>FastAPI makes it easy to create web API’s</li> <li>This post shows how to integrate the two for API’s that are easy to debug.</li> <li>It’s really only a few simple steps <ul> <li>Create a dataclass for the logger config.</li> <li>Create a function that will either install rich as the handler (while not in production) or use the production log configuration.</li> <li>Call <code>logging.basicConfig()</code> with the new settings.</li> <li>And possibly override the logger for Uvicorn.</li> </ul></li> <li>Article contains all code necessary, including examples of the resulting logging and tracebacks.</li> </ul> <p><strong>Michael #5:</strong> <a href="https://lukasz.langa.pl/1c78554f-f81d-43d0-9c89-a602cafc4c5a/"><strong>Dev in Residence</strong></a></p> <ul> <li><a href="https://lukasz.langa.pl/a072a74b-19d7-41ff-a294-e6b1319fdb6e/">I am the new CPython Developer in Residence</a></li> <li><a href="https://lukasz.langa.pl/1c78554f-f81d-43d0-9c89-a602cafc4c5a/">Report on first week</a></li> <li>Ɓukasz Langa: “<em>When the PSF first announced the Developer in Residence position, I was immediately incredibly hopeful for Python. I think it’s a role with transformational potential for the project. In short, I believe the mission of the Developer in Residence (DIR) is to accelerate the developer experience of everybody else.</em>”</li> <li>The DIR can: <ul> <li>providing a steady review stream which helps dealing with PR backlog;</li> <li>triaging issues on the tracker dealing with issue backlog;</li> <li>being present in official communication channels to unblock people with questions;</li> <li>keeping CI and the test suite in usable state which further helps contributors focus on their changes at hand;</li> <li>keeping tabs on where the most work is needed and what parts of the project are most important.</li> </ul></li> </ul> <p><strong>David #6:</strong> <a href="https://dagster.io/"><strong>Dagster</strong></a></p> <ul> <li>Dagster is a data orchestrator for machine learning, analytics, and ETL</li> <li>Great for local development that can be deployed on Kubernetes, etc</li> <li>Dagit provides a rich UI to monitor the execution, view detailed logs, etc</li> <li>Can deploy to Airflow, Dask, etc </li> <li>Quick demo?</li> <li>References <ul> <li><a href="https://www.dataengineeringpodcast.com/dagster-data-applications-episode-104/">https://www.dataengineeringpodcast.com/dagster-data-applications-episode-104/</a></li> <li><a href="https://softwareengineeringdaily.com/2019/11/15/dagster-with-nick-schrock/">https://softwareengineeringdaily.com/2019/11/15/dagster-with-nick-schrock/</a></li> </ul></li> </ul> <p><strong>Extras</strong></p> <p>Michael: </p> <ul> <li>Get a vaccine, please.</li> <li>Python 3.10 Type info ---- er <a href="https://www.python.org/dev/peps/pep-0585/">Make the 3.9</a>, thanks John Hagen. Here is a quick example. All of these are functionally equivalent to PyCharm/mypy:</li> </ul> <pre><code> # Python 3.5-3.8 from typing import List, Optional def fun(l: Optional[List[str]]) -&gt; None: # Python 3.9+ from typing import Optional def fun(l: Optional[list[str]]) -&gt; None: # Python 3.10+ def fun(l: list[str] | None) -&gt; None: </code></pre> <p>Note how with 3.10 we no longer need any imports to represent this type.</p> <p>David:</p> <ul> <li><a href="https://winand.at/sql-slides-for-developers">Great SQL resource</a></li> </ul> <p><strong>Joke:</strong> <strong><a href="https://geek-and-poke.com/geekandpoke/2013/10/20/hope">Pray</a></strong></p>

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...