Today I learned that the conda package manager for python supports preprocessing selectors in its environment yaml files to add/delete lines for certain platforms.
A prime example is the installation of pytorch via the following environment.yml:
```
dependencies:
- python
- pip
- pip:
- --index-url https://download.pytorch.org/whl/cu128 # [win] # Only relevant for Windows systems
- --extra-index-url https://pypi.org/simple # [win]
```
This will use the pytorch package index on Windows but use PyPi on all other systems.
#TIL #python #conda #yaml #dependencies #pytorch
Just released! 🚀
After one sequential-only CI failure, two artifacts builds, one GitHub outage, two fixes for the Windows installer build, four Windows builds, and a NuGet outage:
🐍 Python 3.15 alpha 2!
🔬 PEP 799: A new high-frequency statistical sampling profiler
💬 PEP 686: Python now uses UTF-8 as the default encoding
🌊 PEP 782: A new PyBytesWriter C API to create a Python bytes object
⚠️ Better error messages
https://discuss.python.org/t/python-3-15-0a2/104948?u=hugovk
#Python #Python315 #CPython #release #PEP799 #PEP686
Uma reflexão sobre a má prática de usar argumentos mutáveis em callables:
https://bolha.blog/riverfount/desvendando-a-armadilha-dos-argumentos-mutaveis-como-default-em-python
#Python #Callables #ArgumentosMutaveis #BoasPraticas
[Plotly] 3D散布図で外れ値を強調する:外れ値・異常点を"立体"で見抜く
https://qiita.com/Tadataka_Takahashi/items/af924a3096addf8d073d?utm_campaign=popular_items&utm_medium=feed&utm_source=popular_items
#qiita #Python #plotly #散布図 #colaboratory
Beware that all dictionary merge options in standard python aren't good. They don't work if structures repeat internally.
The only way to really make it work is to use pypi's deepmerge.
Note: the other options should be removed since they don't really work and can mislead you to believe they do.
⏰ time-machine v3 is out! 🕰️
This package helps you accurately mock time-related functions in your tests. v3 cleans up some warts from previous versions, including removing the breaks-many-things mocking of time.monotonic().
Come back to the future with me!
https://time-machine.readthedocs.io/en/latest/changelog.html
Nouvelle édition du projet #NSI "Art-léatoire"
Édition 2024-2025 : https://www.ateliernumerique.net/art-leatoire-2025
#Python + #Pillow + #Random
Going build-free with native JavaScript modules
For the last decade and more, we've been bundling CSS and JavaScript files. These build tools allowed us to utilize new browser capabilities in CSS and JS while still supporting older browsers. They also helped with client-side network performance, minimizing the content to be as small as possible and combining files into one large bundle to reduce network handshakes. We've gone through a lot of build tools iterations in the process; from Grunt (2012) to Gulp (2013) to Webpack (2014) to Parcel (2017) to esbuild (2020) and Vite (2020).
And with modern browser technologies there is less need for these build tools.
- Modern CSS supports many of the features natively that the build tools were created for. CSS nesting to organize code, variables, @supports for feature detection.
- JavaScript ES6 / ES2015 was a big step forward, and the language has been progressing steadily ever since. It now has native module support with the import / export keywords
- Meanwhile, with HTTP/2 performance improvements, parallel requests can be made over the same connection, removing the constraints of the HTTP/1.x protocol.
These build processes are complex, particularly for beginners to Django. The tools and associated best practices move quickly. There is a lot to learn and you need to understand how to utilize them with your Django project. You can build a workflow that stores the build results in your static folder, but there is no core Django support for a build pipeline, so this largely requires selecting from a number of third party packages and integrating them into your project.
The benefit this complexity adds is no longer as clear cut, especially for beginners. There are still advantages to build tools, but you can can create professional results without having to use or learn any build processes.
Build-free JavaScript tutorial
To demonstrate modern capabilities, let's expand Django’s polls tutorial with some newer JavaScript. We’ll use modern JS modules and we won’t require a build system.
To give us a reason to need JS let's add a new requirement to the polls; to allow our users to add their own suggestions, instead of only being able to vote on the existing options. We update our form to have a new option under the selection code:
or add your own <input type="text" name="choice_text" maxlength="200" />
Now our users can add their own options to polls if the existing ones don't fit. We can update the voting view to handle this new option. We add a new choice_text input, and if there is no vote selection we will potentially handle adding the new option, while still providing an error message if neither is supplied. We also provide an error if both are selected.
def vote(request, question_id): if request.POST['choice'] and request.POST['choice_text']: return render(request, 'polls/detail.html', { 'question': question, 'error_message': "You can't vote and provide a new option.", })
<span class="n">question</span> <span class="o">=</span> <span class="n">get_object_or_404</span><span class="p">(</span><span class="n">Question</span><span class="p">,</span> <span class="n">pk</span><span class="o">=</span><span class="n">question_id</span><span class="p">)</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">selected_choice</span> <span class="o">=</span> <span class="n">question</span><span class="o">.</span><span class="n">choice_set</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">pk</span><span class="o">=</span><span class="n">request</span><span class="o">.</span><span class="n">POST</span><span class="p">[</span><span class="s1">'choice'</span><span class="p">])</span>
<span class="k">except</span> <span class="p">(</span><span class="ne">KeyError</span><span class="p">,</span> <span class="n">Choice</span><span class="o">.</span><span class="n">DoesNotExist</span><span class="p">):</span>
<span class="k">if</span> <span class="n">request</span><span class="o">.</span><span class="n">POST</span><span class="p">[</span><span class="s1">'choice_text'</span><span class="p">]:</span>
<span class="n">selected_choice</span> <span class="o">=</span> <span class="n">Choice</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">create</span><span class="p">(</span>
<span class="n">question</span><span class="o">=</span><span class="n">question</span><span class="p">,</span>
<span class="n">choice_text</span><span class="o">=</span><span class="n">request</span><span class="o">.</span><span class="n">POST</span><span class="p">[</span><span class="s1">'choice_text'</span><span class="p">],</span>
<span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">return</span> <span class="n">render</span><span class="p">(</span><span class="n">request</span><span class="p">,</span> <span class="s1">'polls/detail.html'</span><span class="p">,</span> <span class="p">{</span>
<span class="s1">'question'</span><span class="p">:</span> <span class="n">question</span><span class="p">,</span>
<span class="s1">'error_message'</span><span class="p">:</span> <span class="s2">"You didn't select a choice or provide a new one."</span><span class="p">,</span>
<span class="p">})</span>
<span class="n">selected_choice</span><span class="o">.</span><span class="n">votes</span> <span class="o">+=</span> <span class="mi">1</span>
<span class="n">selected_choice</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>
<span class="k">return</span> <span class="n">HttpResponseRedirect</span><span class="p">(</span><span class="n">reverse</span><span class="p">(</span><span class="s1">'polls:results'</span><span class="p">,</span> <span class="n">args</span><span class="o">=</span><span class="p">(</span><span class="n">question</span><span class="o">.</span><span class="n">id</span><span class="p">,)))</span>
Now that our logic is a bit more complex it would be nicer if we had some JavaScript to do this. We can build a script that handles some of the form validation for us.
function noChoices(choices, choice_text) { return ( Array.from(choices).some((radio) => radio.checked) || (choice_text[0] && choice_text[0].value.trim() !== "") ); }
function allChoices(choices, choice_text) { return ( !Array.from(choices).some((radio) => radio.checked) && choice_text[0] && choice_text[0].value.trim() !== "" ); }
export default function initFormValidation() { document.getElementById("polls").addEventListener("submit", function (e) { const choices = this.querySelectorAll('input[name="choice"]'); const choice_text = this.querySelectorAll('input[name="choice_text"]');
if (!noChoices(choices, choice_text)) { e.preventDefault(); alert("You didn't select a choice or provide a new one."); } if (!allChoices(choices, choice_text)) { e.preventDefault(); alert("You can't select a choice and also provide a new option."); } }); }
Note how we use export default in the above code. This means form_validation.js is a JavaScript module. When we create our main.js file, we can import it with the import statement:
import initFormValidation from "./form_validation.js";
initFormValidation();
Lastly, we add the script to the bottom of our details.html file, using Django’s usual static template tag. Note the type="module" this is needed to tell the browser we will be using import/export statements.
<script type="module" src="{% static 'polls/js/main.js' %}"></script>
That’s it! We got the modularity benefits of modern JavaScript without needing any build process. The browser handles the module loading for us. And thanks to parallel requests since HTTP/2, this can scale to many modules without a performance hit.
In production
To deploy, all we need is Django's support for collecting static files into one place and its support for adding hashes to filenames. In production it is a good idea to use ManifestStaticFilesStorage storage backend. It stores the file names it handles by appending the MD5 hash of the file’s content to the filename. This allows you to set far future cache expiries, which is good for performance, while still guaranteeing new versions of the file will make it to users’ browsers.
This backend is also able to update the reference to form_validation.js in the import statement, with its new versioned file name.
Future work
ManifestStaticFilesStorage works, but a lot of its implementation details get in the way. It could be easier to use as a developer.
import/export with hashed files is not very robust.We discussed those possible improvements at the Django on the Med 🏖️ sprints and I’m hopeful we can make progress.
I built django-manifeststaticfiles-enhanced to attempt to fix all these. The core work is to switch to a lexer for CSS and JS, based on Ned Batchelder’s JsLex that was used in Django previously. It was expanded to cover modern JS and CSS by working with Claude Code to do the grunt work of covering the syntax.
It also switches to using a topological sort to find dependencies, whereas before we used a more brute force approach of repeated processing until we saw no more changes, which lead to more work, particularly on storages that used the network. It also meant we couldn't handle circular dependencies.
To validate it works, I ran a performance benchmark on 50+ projects, it’s been tested issues and with similar (often improved) performance. On average, it’s about 30% faster.
While those improvements would be welcome, do go ahead with trying build-free JavaScript and CSS in your Django projects today! Modern browsers make it possible to create great frontend experiences without the complexity.
https://www.djangoproject.com/weblog/2025/nov/19/going-build-free-with-native-javascript-modules/
🌗 macOS 系統呼叫追蹤工具 strace-macos
➤ macOS 上的 strace 替代方案:基於 LLDB 的系統呼叫追蹤
✤ https://github.com/Mic92/strace-macos
這是一個為 macOS 設計的 strace 指令克隆工具,名為 strace-macos。它利用 macOS 內建的 LLDB 除錯器 API,無需禁用 SIP 即可運作。此工具以純 Python 編寫,支援多種輸出格式(JSON Lines、strace 相容文字),並提供系統呼叫過濾、符號解碼、彩色輸出及摘要統計等功能。安裝可透過 Nix Flakes 或手動安裝。
+ 太好了!一直以來都在找 macOS 的 strace 替代品,這個聽起來很有潛力。
+ SIP 啟用也能用實在太方便了,不像 dtruss 還要關閉保護。希望 regex 過濾和路徑過濾能盡快加入。
#macOS #系統工具 #strace #LLDB #Python
Suis-je en train de dessiner des tamis de Sierpiński avec le module Turtle de #Python ? Vous n'en avez pas la preuve. Mais si je le fait, c'est uniquement pour des raisons pédagogiques.
From Python Basics to AI-Powered Data Engineering!
Every step you take pushes your data career forward 🚀
📊 Python → Data Engineering → Cloud → GenAI + Automation
Real innovation happens when data meets AI!
#DataEngineering #Python #CloudComputing #GenAI #Automation #AICommunity #TechCareer #Upskilling #DataScience #MachineLearning
