Wednesday, September 1, 2021

Python Bytes: #248 while True: stand up, sit down

<p><strong>Watch the live stream:</strong></p> <a href='https://www.youtube.com/watch?v=eIEGTZnsyCg' 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>Paul Everitt</strong></p> <p><strong>Brain #1:</strong> <a href="https://threeofwands.com/why-i-use-attrs-instead-of-pydantic/"><strong>Why I use attrs instead of pydantic</strong></a></p> <ul> <li><strong>Tin Tvrtković,</strong> <a href="https://twitter.com/tintvrtkovic">@tintvrtkovic</a></li> <li>attrs vs dataclasses <ul> <li>Since dataclasses are a strict subset of attrs functionality. Recommend using attrs in most cases over dataclasses</li> <li>attrs is faster, has more features, releases more frequently, offers over a wider range of Python versions.</li> </ul></li> <li>attrs vs Pydantic <ul> <li>attrs is a library for generating the boring parts of writing classes; <ul> <li>Pydantic is that but also</li> <li>a complex validation library.</li> <li>a structuring/unstructuring library, ex converting to json and back</li> </ul></li> <li>attrs has opt-in validation that you have more control over</li> <li>cattrs can be used for structuring/unstructuring</li> <li>converters are opt-in for attrs, built into Pydantic, and can be wrong. <ul> <li>example using Pendulum that Pydantic mishandles</li> </ul></li> </ul></li> <li>Summary <ul> <li>attrs + cattrs + validators where necessary, converters where necessary</li> <li>will be faster</li> <li>you’ll have more control</li> <li>Kind of a “small, sharp, specialized tools” vs “swiss army knife” comparison.</li> </ul></li> </ul> <p><strong>Michael #2:</strong> <a href="https://twitter.com/whereismyjetpac/status/1430694757320347648"><strong>mclfy</strong></a></p> <ul> <li>via __dann__</li> <li>Mcfly is an incredible Ctrl+r replacement</li> <li>McFly replaces your default <code>ctrl-r</code> shell history search with an intelligent search engine that takes into account your working directory and the context of recently executed commands. </li> <li>McFly's suggestions are prioritized in real time with a small neural network.</li> <li>Features <ul> <li>Rebinds <code>ctrl-r</code> to bring up a full-screen reverse history search prioritized with a small neural network.</li> <li>Augments your shell history to track command exit status, timestamp, and execution directory in a SQLite database.</li> <li>Maintains your normal shell history file as well so that you can stop using McFly whenever you want.</li> <li>Includes a simple action to scrub any history item from the McFly database and your shell history files.</li> <li>Designed to be extensible for other shells in the future.</li> <li>Written in Rust, so it's fast and safe.</li> </ul></li> </ul> <p><strong>Paul #3: Textual and</strong> <a href="https://twitter.com/willmcgugan/status/1426267903733768193"><strong>boilerplate removal</strong></a></p> <ul> <li>In the race to make Textual the most talked-about package in Python Bytes history…</li> <li>I’d like to zoom in on a Twitter discussion he had about removing boilerplate</li> <li>I have traditionally been opposed to the convention-over-configuration approach that most successful Python projects have taken</li> <li>I dislike magic variable and file names, prefer explicit is better than implicit, actual <em>symbols</em></li> <li>Lately, because of…tooling</li> <li>But Will’s approach to “boilerplate removal” is compelling, as it remains mypy friendly</li> <li>Still, I find it flawed…code meant to be read 2 years from now…that stuff that is implied-away, worries me</li> <li>Will is great at working-in-the-open, being a gentle, encouraging public figure</li> </ul> <p><strong>Brian #4:</strong> <a href="https://github.com/Erotemic/xdoctest"><strong>xdoctest</strong></a> </p> <ul> <li>“The <code>xdoctest</code> package is a re-write of Python's builtin <code>doctest</code> module. It replaces the old regex-based parser with a new abstract-syntax-tree based parser (using Python's <code>ast</code> module). The goal is to make doctests easier to write, simpler to configure, and encourage the pattern of test driven development.”</li> <li>“The main enhancements <code>xdoctest</code> offers over <code>doctest</code> are: <ol> <li>All lines in the doctest can now be prefixed with <code>&gt;&gt;&gt;</code>. Old-style doctests with <code>...</code> are still valid.</li> <li>Additionally, the multi-line strings don't require any prefix (but its ok if they do have either prefix).</li> <li>Tests are executed in blocks, rather than line-by-line, thus comment-based directives (e.g. <code># doctest: +SKIP</code>) are now applied to an entire block, rather than just a single line.</li> <li>Tests without a "want" statement will ignore any stdout / final evaluated value. This makes it easy to use simple assert statements to perform checks in code that might write to stdout.</li> <li>If your test has a "want" statement and ends with both a value and stdout, both are checked, and the test will pass if either matches.</li> <li>Output from multiple sequential print statements can now be checked by a single "got" statement. (new in 0.4.0).”</li> </ol></li> <li>Features I love <ul> <li>“The new got/want tester is very permissive by default; it ignores differences in whitespace”</li> <li>You can make doctest normalize whitespace, but why should you have to?</li> </ul></li> </ul> <p><strong>Michael #5:</strong> <a href="https://medium.com/@davidkongfilm/how-i-hacked-my-standing-desk-with-a-raspberry-pi-a50ed14c7f6f"><strong>Automate the standing desk with python</strong></a></p> <ul> <li>via Joe Riedley, by David Kong</li> <li>“When I first started using it, I was very excited, but I quickly found myself sitting all day, in spite of the fancy desk.”</li> <li>I took off a few screws and … voila! A row of pins neatly exposed right in front.</li> <li>The pins in my control box, when connected correctly, simulate the pressing of the buttons on the front of the box.</li> <li><a href="https://www.raspberrypi.org/products/raspberry-pi-zero/"><strong>Raspberry Pi Zero</strong></a>, the simplest, most basic version. It doesn’t have all the bells and whistles, but it does everything I needed for this simple project, and it’s just $5(!).</li> <li>And the code</li> </ul> <pre><code> from gpiozero import LED # The LED library allows easy pin control from time import sleep import randomrelay = LED(17) # I connected the relay to pin 17 and groundwhile True: relay.on() sleep(1) relay.off() sleep(random.randint(45, 60) * 60) </code></pre> <p><strong>Paul #6:</strong> <a href="https://cookiecutter-hypermodern-python.readthedocs.io/en/2021.4.15/"><strong>Hypermodern Python Cookiecutter</strong></a></p> <ul> <li>I’ve been noodling with some code the last two years about bringing frontend DX to Python web dev</li> <li>Learning and talking more than adoption</li> <li>Running a modern Python project is a LOT of housekeeping</li> <li>Hypermodern Python Cookiecutter from Claudio Jolowicz teleported me to a state of the art I was looking for</li> <li>Poetry, Nox, GHA, pre-commit, flake8, PyPI uploads from CI, release drafter, Black, prettier, pytest, mypy, Sphinx and friends, GitHub labeler</li> <li>It’s NOT AT ALL just a cookiecutter</li> <li>The best part…it’s an enormously-detailed user guide, some blog posts with the “why”, it’s actively maintained</li> <li>The PR workflow is really well explained and wired up</li> <li>This could be…a course, a webinar</li> <li>Thanks Claudio</li> </ul> <p><strong>Extras</strong></p> <p>Michael:</p> <ul> <li><a href="https://www.surveymonkey.com/r/secure-your-supply-chain"><strong>ActiveState's 2021 Software Supply Chain Security Survey</strong></a></li> <li><a href="https://pythoninsider.blogspot.com/2021/08/python-397-and-3812-are-now-available.html"><strong>Python 3.9.7 and 3.8.12 are now available</strong></a></li> <li>From Shlomi Lanton, on your #2 Brian talked about having a history of all files to find the ones that were updated last, so I created <a href="https://github.com/shlomiLan/grampa"><strong>granpa</strong></a> </li> <li>caffinate: you mentioned the MacOS <code>/usr/bin/caffeinate</code> tool on "<a href="https://ift.tt/38zvxTe". Follow <code>caffeinate</code> with long-running command to keep awake until done (<code>caffeinate python -c 'import time; time.sleep(10)'</code>), or <code>caffeinate -w "$PID"</code> for an already running task. - via <a href="https://twitter.com/n8henrie">Nathan Henrie</a></li> <li>Also: <a href="https://github.com/np-8/wakepy"><strong>wakepy</strong></a> now works correctly on macOS</li> </ul> <p><strong>Joke:</strong> <a href="https://twitter.com/ismonkeyuser/status/1430413027950612481/"><strong>Meaning</strong></a></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...