Quantcast
Channel: Planet Python
Viewing all articles
Browse latest Browse all 23197

Python Bytes: #279 Autocorrect and other Git Tricks

$
0
0
<p><strong>Watch the live stream:</strong></p> <a href='https://www.youtube.com/watch?v=RXqP1q8Yp1g' style='font-weight: bold;'>Watch on YouTube</a><br> <br> <p><strong>About the show</strong></p> <p>Sponsored by Datadog: <a href="http://pythonbytes.fm/datadog"><strong>pythonbytes.fm/datadog</strong></a></p> <p>Special guest: Brian Skinn (<a href="https://twitter.com/btskinn">Twitter</a> | <a href="https://github.com/bskinn">Github</a>)</p> <p><strong>Michael #1:</strong> <a href="https://www.openbb.co"><strong>OpenBB wants to be an open source challenger to Bloomberg Terminal</strong></a></p> <ul> <li>OpenBB Terminal provides a modern Python-based integrated environment for investment research, that allows an average joe retail trader to leverage state-of-the-art Data Science and Machine Learning technologies.</li> <li>As a modern Python-based environment, OpenBBTerminal opens access to numerous Python data libraries in <ul> <li>Data Science (Pandas, Numpy, Scipy, Jupyter)</li> <li>Machine Learning (Pytorch, Tensorflow, Sklearn, Flair)</li> <li>Data Acquisition (Beautiful Soup, and numerous third-party APIs)</li> </ul></li> <li>They have a discord community too</li> <li>BTW, seem to be a successful open source project: <a href="https://finance.yahoo.com/news/openbb-raises-8-5m-seed-160000637.html">OpenBB Raises $8.5M in Seed Round Funding Following Open Source Project Gamestonk Terminal's Success</a></li> <li>Great <a href="http://">graphics / gallery</a> here.</li> <li>Way more affordable than the $1,900/mo/user for the Bloomberg Terminal</li> </ul> <p><strong>Brian #2:</strong> <strong>Python f-strings</strong></p> <ul> <li><a href="https://fstring.help/"><strong>https://fstring.help</strong></a> <ul> <li>Florian Bruhin</li> <li>Quick overview of cool features of f-strings, made with Jupyter</li> </ul></li> <li><a href="https://towardsdatascience.com/python-f-strings-are-more-powerful-than-you-might-think-8271d3efbd7d"><strong>Python f-strings Are More Powerful Than You Might Think</strong></a> <ul> <li>Martin Heinz</li> <li>More verbose discussion of f-strings</li> </ul></li> <li>Both are great to up your string formatting game.</li> </ul> <p><strong>Brian S. #3: pyproject.toml and PEP 621 Support in setuptools</strong></p> <ul> <li><a href="https://peps.python.org/pep-0621/">PEP 621: “Storing project metadata in pyproject.toml”</a> <ul> <li>Authors: Brett Cannon, Dustin Ingram, Paul Ganssle, Pradyun Gedam, Sébastien Eustace, Thomas Kluyver, Tzu-ping Chung (Jun-Oct 2020)</li> <li>Covers build-tool-independent fields (<code>name</code>, <code>version</code>, <code>description</code>, <code>readme</code>, <code>authors</code>, etc.)</li> </ul></li> <li>Various tools had already implemented pyproject.toml support, but not setuptools <ul> <li>Including: Flit, Hatch, PDM, Trampolim, and Whey (h/t: <a href="https://scikit-hep.org/developer/pep621">Scikit-HEP</a>)</li> <li>Not Poetry yet, though it's <a href="https://github.com/python-poetry/poetry/issues/3332">under discussion</a></li> </ul></li> <li>setuptools support had been <a href="https://github.com/pypa/setuptools/issues/1688">discussed pretty extensively</a>, and had been included on the PSF’s list of <a href="https://github.com/psf/fundable-packaging-improvements/blob/master/FUNDABLES.md#add-support-for-pyprojecttoml-as-a-way-to-configure-setuptools">fundable packaging improvements</a></li> <li>Initial experimental implementation spearheaded by <a href="https://github.com/abravalheri">Anderson Bravalheri</a>, recently completed <ul> <li>Seeking testing and bug reports from the community (<a href="https://discuss.python.org/t/help-testing-experimental-features-in-setuptools/13821">Discuss thread</a>)</li> <li>I tried it on one of my projects — it mostly worked, but revealed a <a href="https://github.com/pypa/setuptools/issues/3244">bug</a> that Anderson fixed super-quick (proper handling of a dynamic <code>long_description</code>, defined in <code>setup.py</code>)</li> </ul></li> <li>Related tools (all early-stage/experimental AFAIK) <ul> <li><a href="https://github.com/abravalheri/ini2toml">ini2toml</a> (Anderson Bravalheri) — Can convert setup.cfg (which is in INI format) to pyproject.toml <ul> <li>Mostly worked well for me, though I had to manually fix a couple things, most of which were due to limitations of the INI format <ul> <li>INI has no list syntax!</li> </ul></li> </ul></li> <li><a href="https://github.com/abravalheri/validate-pyproject">validate-pyproject</a> (Anderson Bravalheri) — Automated pyproject.toml checks</li> <li><a href="https://github.com/tox-dev/pyproject-fmt">pyproject-fmt</a> (Bernát Gábor) — Autoformatter for pyproject.toml</li> </ul></li> <li>Don’t forget to use it with <code>build</code>, instead of via a <code>python setup.py</code> invocation! <ul> <li><code>$ pip install build</code> <code>$ python -m build</code></li> </ul></li> <li>Will also want to constrain your <code>setuptools</code> version in the <code>build-backend.requires</code> key of <code>pyproject.toml</code> (you <em>are</em> using PEP517/518, right??)</li> </ul> <p><strong>Michael #4:</strong> <a href="https://jwt.io">JSON Web Tokens @ jwt.io</a></p> <ul> <li>JSON Web Tokens are an open, industry standard <a href="https://tools.ietf.org/html/rfc7519"><strong>RFC 7519</strong></a> method for representing claims securely between two parties.</li> <li>Basically a visualizer and debugger for JWTs <ul> <li>Enter an encoded token</li> <li>Select a decryption algorithm</li> <li>See the payload data</li> <li>verify the signature</li> </ul></li> <li><a href="https://jwt.io/libraries">List of libraries</a>, grouped by language</li> </ul> <p><strong>Brian #5:</strong> <a href="https://waylonwalker.com/til/git-config-help-autocorrect/"><strong>Autocorrect</strong></a> <strong>and other Git Tricks</strong></p> <pre><code>- Waylon Walker - Use `git config --global help.autocorrect 10` to have git automatically run the command you meant in 1 second. The `10` is 10 x 1/10 of a second. So `50` for 5 seconds, etc. </code></pre> <p></p> <ul> <li>Automatically set upstream branch if it’s not there <ul> <li><code>git config --global push.default current</code></li> <li>You may NOT want to do this if you are not careful with your branches.</li> <li>From https://stackoverflow.com/a/22933955</li> </ul></li> <li><code>git commit -a</code> <ul> <li>Automatically “add” all changed and deleted files, but not untracked files.</li> <li>From https://git-scm.com/docs/git-commit#Documentation/git-commit.txt--a </li> </ul></li> <li>Now most of my interactions with git CLI, especially for quick changes, is: $ git checkout main $ git pull $ git checkout -b okken_something $ git commit -a -m 'quick message' $ git push</li> <li>With these working, with autocorrect $ git chkout main $ git pll $ git comit -a -m 'quick message' $ git psh</li> </ul> <p><strong>Brian S. #6: jupyter-tempvars</strong></p> <ul> <li>Jupyter notebooks are great, and the global namespace of the Python kernel backend makes it super easy to flow analysis from one cell to another</li> <li>BUT, that global namespace also makes it super easy to footgun, when variables leak into/out of a cell when you don’t want them to</li> <li><a href="https://github.com/bskinn/jupyter-tempvars">jupyter-tempvars</a> notebook extension <ul> <li>Built on top of the <a href="https://github.com/bskinn/tempvars">tempvars</a> library, which defines a <code>TempVars</code> context manager for handling temporary variables <ul> <li>When you create a <code>TempVars</code> context manager, you provide it patterns for variable names to treat as temporary</li> <li>In its simplest form, <code>TempVars</code> (1) clears matching variables from the namespace on entering the context, and then (2) clears them <em>again</em> upon exiting the context, and restoring their prior values, if any</li> <li><code>TempVars</code> works great, but it’s cumbersome and distracting to manually include it in every notebook cell where it’s needed</li> </ul></li> <li>With <code>jupyter-tempvars</code>, you instead apply tags with a specific format to notebook cells, and the extension automatically wraps each cell’s code in a <code>TempVars</code> context before execution</li> </ul></li> <li>Javascript adapted from existing extensions <ul> <li>Patching <code>CodeCell.execute</code>, from the <code>jupyter_contrib_nbextensions</code> ‘<a href="https://github.com/ipython-contrib/jupyter_contrib_nbextensions/blob/a186b18efaa1f55fba64f08cd9d8bf85cba56d25/src/jupyter_contrib_nbextensions/nbextensions/execution_dependencies/execution_dependencies.js#L31-L33">Execution Dependencies</a>’ extension, to <a href="https://github.com/bskinn/jupyter-tempvars/blob/491babaca4f48c8d453ce4598ac12aa6c5323181/src/jupyter_tempvars/extension/jupyter_tempvars.js#L127-L143">enclose the cell code with the context manager</a></li> <li>Listening for the ‘kernel ready’ event, from <code>[jupyter-black](https://github.com/drillan/jupyter-black/blob/d197945508a9d2879f2e2cc99cafe0cedf034cf2/kernel_exec_on_cell.js#L347-L350)</code>, to <a href="https://github.com/bskinn/jupyter-tempvars/blob/491babaca4f48c8d453ce4598ac12aa6c5323181/src/jupyter_tempvars/extension/jupyter_tempvars.js#L42-L46">import the</a> <code>[TempVars](https://github.com/bskinn/jupyter-tempvars/blob/491babaca4f48c8d453ce4598ac12aa6c5323181/src/jupyter_tempvars/extension/jupyter_tempvars.js#L42-L46)</code> <a href="https://github.com/bskinn/jupyter-tempvars/blob/491babaca4f48c8d453ce4598ac12aa6c5323181/src/jupyter_tempvars/extension/jupyter_tempvars.js#L42-L46">context manager upon kernel (re)start</a></li> </ul></li> <li>See the <a href="https://github.com/bskinn/jupyter-tempvars/blob/main/README.md">README</a> (with animated GIFs!) for installation and usage instructions <ul> <li>It’s on PyPI: <code>$ pip install jupyter-tempvars</code></li> <li>And, I made a shortcut install script for it: <code>$ jupyter-tempvars install &amp;&amp; jupyter-tempvars enable</code></li> </ul></li> <li>Please try it out, <a href="https://github.com/bskinn/jupyter-tempvars/issues">find/report bugs, and suggest features</a>!</li> <li>Future work <ul> <li>Publish to conda-forge (definitely)</li> <li>Adapt to JupyterLab, VS Code, etc. (pending interest)</li> </ul></li> </ul> <p><strong>Extras</strong> </p> <p>Brian:</p> <ul> <li>Ok. <a href="https://discuss.python.org/t/github-issues-are-now-live">Python issues are now on GitHub.</a> Seriously. <a href="https://github.com/python/cpython/issues">See for yourself.</a></li> <li><a href="https://www.lipsum.com/">Lorem Ipsum is more interesting than I realized.</a></li> <li><a href="https://dev.to/rly">O RLY Cover Generator</a></li> <li>Example: <br /> <img src="https://paper-attachments.dropbox.com/s_E9964F8854B7AC3C00CC5A9D2E286CD011C21B235E0D7DEA457256E82F09C5FE_1649825870185_100_percent_coverage 2.png" alt="" /></li> </ul> <p>Michael:</p> <ul> <li>New course: <a href="https://talkpython.fm/fastapi-azure-ad">Secure APIs with FastAPI and the Microsoft Identity Platform</a></li> <li><a href="https://github.com/seth-c-stenzel/Pyenv-Virtualenv-for-Windows-Sorta-ish">Pyenv Virtualenv for Windows</a> <a href="http://">(Sorta'ish)</a></li> <li><a href="https://hipsum.co/">Hipster Ipsum</a></li> </ul> <p>Brian S.: </p> <ul> <li>PSF staff is expanding <ul> <li><a href="https://www.python.org/jobs/6261/">PSF hiring an Infrastructure Engineer</a> <ul> <li>Link now 404s, perhaps they’ve made their hire?</li> </ul></li> <li>Last year’s <a href="https://pyfound.blogspot.com/2021/08/shamika-mohanan-has-joined-psf-as.html">hire of the Packaging Project Manager</a> (Shamika Mohanan)</li> <li>Steering Council <a href="https://github.com/encukou/steering-council/blob/a9185ebe4de915b59290a1ebb380e93e6a8d3c4f/updates/2022-03-steering-council-update.md#2022-03-07">supports PSF hiring a second developer-in-residence</a></li> </ul></li> <li>PSF has <a href="https://twitter.com/ThePSF/status/1512078490689961993">chosen</a> its new Executive Director: <a href="https://twitter.com/baconandcoconut">Deb Nicholson</a>!</li> <li><a href="https://www.pyohio.org/2022/speaking/call-for-proposals/">PyOhio 2022 Call for Proposals</a> is open</li> <li>Teaser <a href="https://twitter.com/samuel_colvin/status/1512872630696747022">tweet</a> for performance improvements to pydantic </li> </ul> <p><strong>Jokes:</strong> </p> <p><a href="https://twitter.com/CaNerdIan/status/1512628780212396036">https://twitter.com/CaNerdIan/status/1512628780212396036</a></p> <p><a href="https://www.reddit.com/r/ProgrammerHumor/comments/tuh06y/i_guess_we_all_have_been_there/">https://www.reddit.com/r/ProgrammerHumor/comments/tuh06y/i_guess_we_all_have_been_there/</a></p> <p><a href="https://twitter.com/PR0GRAMMERHUM0R/status/1507613349625966599">https://twitter.com/PR0GRAMMERHUM0R/status/1507613349625966599</a></p>

Viewing all articles
Browse latest Browse all 23197

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>