Thursday, September 17, 2020

Python Bytes: #199 Big news for a very small Python runtime

<p>Sponsored by us! Support our work through:</p> <ul> <li>Our <a href="https://training.talkpython.fm/"><strong>courses at Talk Python Training</strong></a></li> <li><a href="https://pragprog.com/titles/bopytest/python-testing-with-pytest/"><strong>Python Testing with pytest</strong></a></li> </ul> <p><strong>Michael #1:</strong> <a href="https://twitter.com/matt_trentini/status/1302980818877390849"><strong>micropython updated</strong></a></p> <ul> <li>via Matt Trentini</li> <li>v1.13 is packed with features and bugfixes including solid asyncio support and tasty BLE improvements. Heck, we've even got the walrus operator.</li> <li>a new implementation of the uasyncio module which aims to be more compatible with CPython's asyncio module.</li> <li>The main change is to use a Task object for each coroutine, allowing more flexibility to queue tasks in various places, eg the main run loop, tasks waiting on events, locks or other tasks.</li> <li>It no longer requires pre-allocating a fixed queue size for the main run loop.</li> <li>Most code in this repository is now auto-formatted using uncrustify for C code and Black for Python code.</li> <li>BlueKitchen BTstack bindings have been added for the ubluetooth module, as an optional alternative to the NimBLE stack. The unix port can now be built with BLE support using these bindings</li> <li>Other Bluetooth additions include: new events for service/characteristic/ descriptor discovery complete; new events for read done and indicate acknowledgement; and support for active scanning in BLE.gap_scan().</li> <li>PEP 526 has been (Walrus)</li> <li>There has been an important bug fix when importing ARM machine code from an .mpy file: the system now correctly tracks the executable memory allocated to the machine code so this memory is not reclaimed by the garbage collector.</li> <li>For testing, a multi-instance test runner has been added (see tests/run-multitests.py) which allows running a synchronised test across two or more MicroPython targets.</li> <li>There are breaking changes</li> <li>First release since Dec 19, 2019</li> </ul> <p><strong>Brian #2:</strong> <a href="https://lundberg.github.io/respx/"><strong>respx: A utility for mocking out the Python HTTPX library</strong></a></p> <ul> <li>When using <a href="https://requests.readthedocs.io/en/master/">requests</a>, you can mock it with <a href="https://github.com/getsentry/responses">responses</a>.</li> <li>When using <a href="https://github.com/encode/httpx">httpx</a>, mock with <a href="https://lundberg.github.io/respx/">respx</a>.</li> <li>Quick start:</li> </ul> <pre><code> import httpx import respx @respx.mock def test_something(): request = respx.post("https://foo.bar/baz/", status_code=201) response = httpx.post("https://foo.bar/baz/") assert request.called assert response.status_code == 201 </code></pre> <ul> <li>Documentation includes examples of using respx with both pytest and unittest, including how to set up mocked_api fixtures for pytest.</li> <li>There’s call statistics you can assert on.</li> <li>Ability to raise exceptions, return non-200 status codes, set custom return content.</li> <li>Content can be generated in a callback method.</li> <li>JSON content can be returned</li> <li>Tons of nice options to help test your httpx based application.</li> </ul> <p><strong>Michael #3:</strong> <a href="https://github.com/atom-moyer/getpy"><strong>GetPy - A Vectorized Python Dict/Set</strong></a></p> <ul> <li>The goal of GetPy is to provide the highest performance python dict/set that integrates into the python scientific ecosystem.</li> <li>GetPy is a thin binding to the Parallel Hashmap (https://ift.tt/35KQuKB) which is the current state of the art unordered map/set with minimal memory overhead and fast runtime speed.</li> <li>The binding layer is supported by PyBind11 (https://ift.tt/2ZJzrVl> <li>The gp.Dict and gp.Set objects are designed to maintain a similar interface to the corresponding standard python objects.</li> <li>Simple example:</li> - </ul> <pre><code> import getpy as gp key_type = np.dtype('u8') value_type = np.dtype('u8') keys = np.random.randint(1, 1000, size=10**2, dtype=key_type) values = np.random.randint(1, 1000, size=10**2, dtype=value_type) gp_dict = gp.Dict(key_type, value_type) gp_dict[keys] = values </code></pre> <p><strong>Brian #4:</strong> <strong>isort and black now play nice together easily</strong></p> <ul> <li>Contributed by John Hagen</li> <li><code>isort</code> “sorts your imports, so you don’t have to”</li> <li><code>black</code> reformats all of your code to a consistent code style, including import statements</li> <li>There is a <a href="https://black.readthedocs.io/en/stable/compatible_configs.html#isort">config page on black documentation that shows how to set isort to be compatible with black</a>. It also shows how to make flake8 and pylint play nice with black, but they are less complicated.</li> <li>Now, however, with <a href="https://pycqa.github.io/isort/docs/major_releases/introducing_isort_5/">isort 5 introduction of built in profiles</a>, you can just use <code>isort</code> <code>--``profile black .</code> and the profile sets everything for you.</li> <li>There’s a <a href="https://pycqa.github.io/isort/docs/configuration/profiles/">profile page for isort</a> that describes all that it does. </li> <li>Other profiles include: django, pycharm, google, open_stack, plone, attrs, hug</li> <li>And as always, you can configure your own with config files.</li> </ul> <p><strong>Michael #5:</strong> <a href="https://www.theverge.com/2020/8/6/21355674/human-genes-rename-microsoft-excel-misreading-dates"><strong>Scientists rename human genes to stop Microsoft Excel from misreading them as dates</strong></a></p> <ul> <li>Via Chris Moffitt</li> <li>There are tens of thousands of genes in the human genome</li> <li>Each gene is given a name and alphanumeric code, known as a symbol, which scientists use to coordinate research.</li> <li>Over the past year or so, some 27 human genes have been renamed, all because Microsoft Excel kept misreading their symbols as dates.</li> <li>Excel is regularly used by scientists to track their work and even conduct clinical trials.</li> <li>But its default settings were designed with more mundane applications in mind, so when a user inputs a gene’s alphanumeric symbol into a spreadsheet, like MARCH1 — short for “Membrane Associated Ring-CH-Type Finger 1” — Excel converts that into a date: 1-Mar.</li> <li>One study from 2016 examined genetic data shared alongside 3,597 published papers and found that roughly one-fifth had been affected by Excel errors.</li> <li>See 12 of the Biggest Spreadsheet Fails in History for more examples: https://ift.tt/2RIgzBH> <li>The scientific body in charge of standardizing the names of genes, the HUGO Gene Nomenclature Committee, published new guidelines for gene naming. From now on human genes and the proteins they expressed will be named with one eye on Excel’s auto-formatting.</li> <li>Check out the <a href="https://talkpython.fm/excel"><strong>Excel to Python course</strong></a> and <a href="https://talkpython.fm/excel-webcast"><strong>webcast</strong></a> to escape this.</li> </ul> <p><strong>Brian #6:</strong> <a href="https://glyph.twistedmatrix.com/2020/08/never-run-python-in-your-downloads-folder.html"><strong>Never Run ‘python’ In Your Downloads Folder</strong></a></p> <ul> <li>by Glyph</li> <li>This is really a nice, short tutorial on how <code>sys.path</code> is populated, why you should care, and why you need to make sure it’s only trusted locations.</li> <li>“downloads” is definitely not trusted.</li> <li>So never, ever, ever run <code>python</code> from the downloads directory, even with <code>python -m something</code>, as that adds the download dir to the include path.</li> <li>Example includes a demonstration of malicious js code that downloads a fake <code>pip.py</code> to your downloads folder, so when you call <code>python -m pip install ./legit_package.whl</code> you get the fake pip.</li> <li>Further examples show how you need to be vigilant to check your dot files for weird PYTHONPATH extensions and additions. </li> </ul> <p>Extras:</p> <p>Michael:</p> <ul> <li>We recently passed 5,000,000 downloads of the audio files over at Python Bytes and are the 130th most popular tech podcast in the world. Thank you everyone!</li> <li>Got a new <a href="https://ift.tt/3c8r7ne WiFi 6 mesh router</strong></a>, and wow, highly recommended.</li> </ul> <p>Joke</p> <p>Are you a real programmer? <a href="https://xkcd.com/378/"><strong>Check with XKCD</strong></a> to find out.</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...