Feeds
Zero to Mastery: Python Monthly Newsletter đ»đ
FSF News: Worldwide community of activists protest OverDrive and others forcing DRM upon libraries
Steinar H. Gunderson: Framework debt
Today's shower thought:
Taking on a dependency is assuming some amount of technical debt. Using a framework is taking on a dependency that is very hard to get rid of.
(All the usual properties of technical debt, positive and negative, apply)
PyCoderâs Weekly: Issue #605 (Nov. 28, 2023)
#605 â NOVEMBER 28, 2023
View in Browser »
Sabs wanted the ability to specify dependencies inside a single Python script, and although there are PEPs on this topic, their implementation is a ways off. Sabs decided to solve this problem directly: introducing pip.wtf a code snippet you copy into your script that does dependency loading through a function call.
PIP.WTF
In this step-by-step project, you’ll implement Conway’s Game of Life in Python. To make the game usable, you’ll create a user-friendly command-line interface (CLI) with several options that will allow you to run the game using different life patterns and configurations.
REAL PYTHON
Are you stuck in tutorial paralysis? Crush imposter syndrome with the 12-week Pybites PDM Program. Learn advanced Python, build impactful real world apps, and get 1:1 mentorship. Stand out in tech interviews and elevate your developer journey. Join a thriving Python community. Enroll today! đđ©âđ»
PYBITES sponsor
This article categorizes errors in your Python code into three groups: type-checking, import explosions, and runtime errors. Learn how each is treated differently and how to better handle them in your programs.
TIN
In this tutorial, you’ll learn how to create and render web content in Django with the simplicity and flexibility of the Markdown text formatting language.
REAL PYTHON
This opinion piece from Mensur addresses the wide gulf between what is learned in school and what is encountered in real world software development. He mentions topics ranging from the frequency of dealing with legacy code, to the reality of meetings and estimates. Associated HN discussion.
MENSUR DURAKOVIC
David is the maintainer of Flask and this list shows all that entails. Some things are obvious and others are things you might not be aware of. If you’re participating in the OSS community, it is good to know what is on here, if you just use libraries, appreciate all the work being done!
DAVID LORD
A collection of single-line Python snippets that cover common tasks in programming. Includes removing duplicates from lists, reversing strings, finding the most common element in a list, and much more.
MUHAMMAD RAZA
Love them or hate them, the daily stand-up is out there. It may have problems, but at its core, the three mains questions (what did you do? what are you planning? what is blocking you?) provide a tool for radiating information, and at core that’s a good idea.
JORGE MANRUBIA
Meta has a large collection of plug-ins for linting, which makes some of the usual solutions problematic at scale. This article introduces Fixit 2, an open source, pluggable linter.
AMETHYST REESE
This opinion piece by Bite Code states why developers new to the web space should use Django, even though Flask has the simpler “hello world” which makes it attractive.
BITE CODE
This multi-part post talks about how getting notified about all errors leads to error fatigue from false positives and a culture where errors get ignored. Long term this can have disastrous consequences.
RYAN CHELEY
In this video course, you’ll practice separating your code into modules, using the import statement to access another module’s namespace, and creating Python packages.
REAL PYTHON course
Are you a programmer looking to get better at Python? Learn some of Pythonâs features thatâll help you write more elegant and Pythonic code.
BALA PRIYA C âą Shared by Bala Priya C
This article covers the changes the Global Interpreter Lock has undergone since Python 3.9 and how that impacts the assumptions you can make in your code.
STEFAN MARR
This article covers 11 libraries that the author had fun playing with, including PyGame, Asciimatics, Arcade, and more.
MARINE GOSSELIN
Python 3.12 has deprecated utcnow() and utcfromtimestamp(). This article covers why and what to use instead.
MIGUEL GRINBERG
SAQ-PY.READTHEDOCS.IO âą Shared by Nickolas Grigoriadis
toga: A Python Native, OS Native GUI Toolkit lato: Microframework for Modular Monoliths hexabyte: A Modern, Modular, and Robust TUI Hex Editor error-links: Add Links to Search Google to Your TracebacksGITHUB.COM/RODRIGOGIRAOSERRAO âą Shared by Rodrigo GirĂŁo SerrĂŁo đđ
Events Weekly Real Python Office Hours Q&A (Virtual) November 29, 2023
REALPYTHON.COM
November 30, 2023
MEETUP.COM
December 2 to December 4, 2023
PYLADIES.COM
December 5 to December 6, 2023
XTREMEPYTHON.DEV
December 6 to December 9, 2023
PYDATA.ORG
December 9 to December 11, 2023
PYJAMAS.LIVE
December 9 to December 11, 2023
SCIWORK.DEV
Happy Pythoning!
This was PyCoder’s Weekly Issue #605.
View in Browser »
[ Subscribe to đ PyCoder’s Weekly đ â Get the best Python news, articles, and tutorials delivered to your inbox once a week >> Click here to learn more ]
FSF Events: Free Software Directory meeting on IRC: Friday, December 01, starting at 12:00 EST (17:00 UTC)
Off-Theme Presents: Shades of Purple
Tag1 Consulting: A Guide to Estimating Migrations - How Much Will My Drupal Migration Cost? Part 2/3
This podcast series focuses on the strategies involved in upgrading and migrating Drupal websites and applications.
Read more michaelemeyers Tue, 11/28/2023 - 06:00Real Python: Advent of Code: Solving Puzzles With Python
Advent of Code is an online Advent calendar where you’ll find new programming puzzles offered each day from December 1 to 25. While you can solve the puzzles at any time, the excitement when new puzzles unlock is really something special. You can participate in Advent of Code in any programming language—including Python!
With the help of this Code Conversation, you’ll be ready to start solving puzzles and earning your first gold stars.
In this video course, you’ll learn:
- What an online Advent calendar is
- How solving puzzles can advance your programming skills
- How you can participate in Advent of Code
Advent of Code puzzles are designed to be approachable by anyone with an interest in problem-solving. You don’t need a heavy computer science background to participate. Instead, Advent of Code is a great arena for learning new skills and testing out new features of Python.
[ Improve Your Python With đ Python Tricks đ â Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]
Open Source AI: Establishing a common ground
The current draft v. 0.0.3 of the Open Source AI Definition borrows wordings from the GNU Manifestoâs golden rule stating:
If I like a program, I must be able to share it with others who like it.
The GNU ManifestoThe GNU Manifesto refers to âprogramâ (not âAI systemâ), without the need to define it. When it was published in 1985, the definition of a program was pretty clear. Todayâs scene around artificial intelligence is not as clear and there are multiple definitions for AI systems floating around.
The process of finding a shared definition of Open Source AI is only in its infancy. I’m fully aware that for many of us here this is trivial and this phase is almost boring.
But the four workshops revealed that a significant number of people in the rooms did not know the 4 Freedoms nor had any idea that OSI has a formal Open Source Definition. And this happened also at two Open Source-focused events!
Which definition of AI system to adoptI don’t think the Open Source community should write its own definition of an AI system as there are too many dangers with doing that. Most importantly, adopting a vocabulary foreign to the AI world increases the risks of not being understood or accepted. It’s a lot more effective and will be more palatable to use a widely adopted definition.
The OECD definition of AI systemThe Organisation for Economic Co-operation and Development (OECD) published one in 2019 and updated it in November 2023. OECDâs definition has been adopted by the United Nations, NIST and the AI Act may use it too.Â
An AI system is a machine-based system that, for explicit or implicit objectives, infers, from the input it receives, how to generate outputs such as predictions, content, recommendations, or decisions that can influence physical or virtual environments. Different AI systems vary in their levels of autonomy and adaptiveness after deployment
Recommendation of the Council on Artificial Intelligence Adopted on: 22/05/2019; Amended on: 08/11/2023I discovered a 2022 document of the OECD with a slightly amended definition from the one of 2019.The 2022 OECD Framework for the Classification of AI systems removes the words “or decisions” from their previous definition, saying in the note #5:
Experts Working Group decided [âor decisionsâ] should be excluded here to clarify that an AI system does not make an actual decision, which is the remit of human creators and outside the scope of the AI system
2022 OECD Framework for the Classification of AI systemsThe updated definition used by the Experts WG is:
An AI system is a machine-based system that is capable of influencing the environment by producing recommendations, predictions or other outcomes for a given set of objectives. It uses machine and/or human-based inputs/data to:
- perceive environments;
- abstract these perceptions into models; and
- use the models to formulate options for outcomes.
AI systems are designed to operate with varying levels of autonomy (OECD, 2019f[2]).â
2022 OECD Framework for the Classification of AI systemsSurprisingly, the version amended in November 2023 by the OECD still uses the words âor decisionsâ.
The definition of AI system for US National Institute of Standards (NIST)NIST AI Risk Management Framework slightly modified the OECD definition that includes the word “outputs”:
The AI RMF refers to an AI system as an engineered or machine-based system that can, for a given set of objectives, generate outputs such as predictions, recommendations, or decisions influencing real or virtual environments. AI systems are designed to operate with varying levels of autonomy (Adapted from: OECD Recommendation on AI:2019; ISO/IEC 22989:2022)
AI Risk Management Framework The definition of AI system in EuropeTo complete the picture, I also looked at the EU. In a document from 2019, in the early days of the legislative process, the expert group on AI suggested: https://digital-strategy.ec.europa.eu/en/policies/european-approach-artificial-intelligence:
Artificial intelligence (AI) systems are software (and possibly also hardware) systems designed by humans that, given a complex goal, act in the physical or digital dimension by perceiving their environment through data acquisition, interpreting the collected structured or unstructured data, reasoning on the knowledge, or processing the information, derived from this data and deciding the best action(s) to take to achieve the given goal. AI systems can either use symbolic rules or learn a numeric model, and they can also adapt their behaviour by analysing how the environment is affected by their previous actions.
As a scientific discipline, AI includes several approaches and techniques, such as machine learning (of which deep learning and reinforcement learning are specific examples), machine reasoning (which includes planning, scheduling, knowledge representation and reasoning, search, and optimization), and robotics (which includes control, perception, sensors and actuators, as well as the integration of all other techniques into cyber-physical systems).
High-Level expert group on AI: Ethics guidelines for trustworthy AIIt’s worth noting that this definition is not used in the AI Act. The text of the EU Council suggests this one be used:
artificial intelligence systemâ (AI system) means a system that
- receives machine and/or human-based data and inputs,
- infers how to achieve a given set of human-defined objectives using learning, reasoning or modelling implemented with the techniques and approaches listed in Annex I, and
- generates outputs in the form of content (generative AI systems), predictions, recommendations or decisions, which influence the environments it interacts with;
which seems to be quite similar to the OECD text.
Why we need to adopt a definition of AI systemThere is agreement that the Open Source AI Definition needs to cover all AI implementations and not be specific to machine learning, deep learning, computer vision or other branches. That requires using a generic term. For software, the word âprogramâ covers everything, from assembly, interpreted to compiled languages. âAI systemâ is the equivalent in the context of artificial intelligence.
âProgramâ is to software as âAI systemâ is to artificial intelligence.
In the document What is Free Software, the GNU project describes four fundamental freedoms that the âprogramâ must carry to its users. Draft v. 0.0.3 similarly describes four freedoms that the AI system needs to deliver to its users.
In v. 0.0.3 draft there was debate on the wording of the freedom #3 â freedom to modify. For software, thatâs the freedom to modify the program to better serve userâs needs, fix bugs, etc. Draft v. 0.0.3 says:
Modify the system to change its recommendations, predictions or decisions to adapt to your needs.
Draft v.0.0.3The intention to specify what the object of the change is to establish the principle that anyone should have the right to modify the behavior of the AI system as a whole. The words ârecommendations, predictions or decisionsâ come from the definition of AI system: what does the âsystemâ do and what would I want to modify?
That’s why it’s important to say what it is we expect to have the right to modify. Tying that to an agreed-upon definition of what an AI system does is a way to make sure that all readers are on the same page.
We can change the wordings for that bullet point but I think the verb “modify” should refer to the whole system, not individual components.
Weâre trying to adopt a definition of an AI system that is widely understood and accepted, even though it’s not strictly correct scientifically. The Open Source AI Definition should align with other policy documents because many communities (legal, policy makers and even academia) will have to align too.
The newest definition of AI system from the OECD is the best candidate, without the words âor decisions.â
Next stepsI met with the Digital Public Goods Alliance in Addis Ababa on November 14. I expected to encounter a different assortment of competences than the ones I’ve met so far, and that was true. How far we are from consensus on basic principles is something Iâm contemplating before releasing draft v.0.0.4 and move on to the next phase of public conversations. For 2024 weâre planning a regular cadence of meetings (online and in- person) and a release roadmap leading to a v. 1.0 before the end of the year. More to come.
The post <span class='p-name'>Open Source AI: Establishing a common ground</span> appeared first on Voices of Open Source.
ListenData: How to Get Unique Values in a Column in Pandas DataFrame
This tutorial explains how to get unique values from a column in Pandas DataFrame, along with examples.
Find Unique Values in a Column df['columnName'].unique() To read this article in full, please click hereThis post appeared first on ListenDataEnrico Zini: Introducing Debusine
Debusine manages scheduling and distribution of Debian-related tasks (package build, lintian analysis, autopkgtest runs, etc.) to distributed worker machines. It is being developed by Freexian with the intention of giving people access to a range of pre-configured tools and workflows running on remote hardware.
Freexian obtained STF funding for a substantial set of Debusine milestones, so development is happening on a clear schedule. We can present where we are and, we're going to be, and what we hope to bring to Debian with this work.
Python Bytes: #362 You can deprecate a global variable?
Specbee: Handling Custom Drupal Migrations Using SqlBase
Agiledrop.com Blog: Interview with John Faber of Chapter Three: Next-Drupal & securing the future of Drupal
Greg Casamento: Objective-C end of life?? Not a chance...
The tiobe index seems to disagree. Itâs also important to remember that jetbrains recently had to take down their AppCode application (which sucked) since it didnât sell.
Jetbrains is the creator of the kotlin language so they have a vested interest in their android customers. I would take their âindexâ with a grain of salt to say the least.
While it is certain that Apple wonât be investing into thing beyond ObjC 2.0, it is foolhardy to think that ObjC is going away anytime soon since there is an enormous installed base of stable code, not the least of which is Foundation and AppKit themselves. Also consider CocoaPods.
So, no, not worried about it. Also⊠look at Java and COBOL. For years people have declared the end of both languages. Java is still popular, though not in vogue and COBOL while not one of the âcool kidsâ has literally billions of lines of code being maintained and new code being written every year. This (admittedly biased as it is by the CTO of MicroFocus) article gives some reasons whyâŠ.
Here is the article about COBOL...
Plus⊠Apple already has a mechanism for automatically allowing objc and swift to work together. Take a look at the frameworks in Xcode and youâll notice some files called *.apinotes. These are YAML files that are used by the compiler to allow easy integration into swift projects. So, essentially, if Apple writes an ObjC version of a framework they get the swift version for absolutely free (minus the cost of writing the YAML file). If they write a swift only version they donât get that benefit.
So, yeah, in conclusion⊠Yes, ObjC is NOT on the rise, but reports of its demise have been greatly exaggerated! ;)
PS. That being said, Apple dumping ObjC might spell a boom for us as all of the people who have installed codebases would suddenly need support for it either on macOS (on which we donât currently work) or on other platforms. Something to think aboutâŠ
PPS. All of the above being said. I admit I wouldnât be terribly shocked to hear from Apple that âwe have dropped support for the legacy objc language to provide you with the best support for our new swift language to make it the âgreatest developer experience in the worldââ or some grotesque BS like that. Lol
GC
Dirk Eddelbuettel: RcppCNPy 0.2.12 on CRAN: More Maintenance
A new (and again somewhat minor) maintenance release of the RcppCNPy package arrived on CRAN earlier today.
RcppCNPy provides R with read and write access to NumPy files thanks to the cnpy library by Carl Rogers along with Rcpp for the glue to R.
Recent changes in r-devel hone in on issues concerning printf format string inaccuracies the compiler can detect via the -Wformat -Wformat-security flags. Two fairly simplye ones were present here and have been addressed. In the time since the last release about twenty months ago two or three other minor packaging and setup details have also been taken care of, details are below.
Changes in version 0.2.12 (2022-11-27)The continuous integration workflow received a trivial update, twice.
The C++ compilation standard is now implicit per CRAN and R preference.
The CITATION file format has been updated for the current usage.
Two print format string issues reported by current R-devel have been addressed.
CRANberries also provides a diffstat report for the latest release. As always, feedback is welcome and the best place to start a discussion may be the GitHub issue tickets page.
If you like this or other open-source work I do, you can now sponsor me at GitHub.
This post by Dirk Eddelbuettel originated on his Thinking inside the box blog. Please report excessive re-aggregation in third-party for-profit settings.
François Marier: Automatically rebooting for kernel updates
I use reboot-notifier on most of my servers to let me know when I need to reboot them for kernel updates since I want to decide exactly when those machines go down. On the other hand, my home backup server has very predictable usage patterns and so I decided to go one step further there and automate these necessary reboots.
To do that, I first installed reboot-notifier which puts the following script in /etc/kernel/postinst.d/reboot-notifier to detect when a new kernel was installed:
#!/bin/sh if [ "$0" = "/etc/kernel/postinst.d/reboot-notifier" ]; then DPKG_MAINTSCRIPT_PACKAGE=linux-base fi echo "*** System restart required ***" > /var/run/reboot-required echo "$DPKG_MAINTSCRIPT_PACKAGE" >> /var/run/reboot-required.pkgsNote that unattended-upgrades puts a similar script in /etc/kernel/postinst.d/unattended-upgrades:
#!/bin/sh case "$DPKG_MAINTSCRIPT_PACKAGE::$DPKG_MAINTSCRIPT_NAME" in linux-image-extra*::postrm) exit 0;; esac if [ -d /var/run ]; then touch /var/run/reboot-required if ! grep -q "^$DPKG_MAINTSCRIPT_PACKAGE$" /var/run/reboot-required.pkgs 2> /dev/null ; then echo "$DPKG_MAINTSCRIPT_PACKAGE" >> /var/run/reboot-required.pkgs fi fiand so you only need one of them to be installed since they both write to /var/run/reboot-required. It doesn't hurt to have both of them though.
Then I created the following cron job (/etc/cron.daily/reboot-local) to actually reboot the server:
#!/bin/bash REBOOT_REQUIRED=/var/run/reboot-required if [ -s $REBOOT_REQUIRED ] ; then cat "$REBOOT_REQUIRED" | /usr/bin/mail -s "Rebooting $HOSTNAME" root /bin/systemctl reboot fiWith that in place, my server will send me an email and then automatically reboot itself.
This is a work in progress because I'd like to add some checks later on to make sure that no backup is in progress during that time (maybe by looking for active ssh connections?), but it works well enough for now. Feel free to leave a comment if you've got a smarter script you'd like to share.
PreviousNext: Drupal front-end nirvana with Vite, Twig and Storybook
We're proud to announce the release of vite-plugin-twig-drupal, a plugin for Vite that we hope will improve your workflow for front-end development with Drupal.
by lee.rowlands / 28 November 2023The problem spaceYou're working with Twig in a styleguide-driven-development process. You're writing isolated components that consist of CSS, Twig and JavaScript. You want to be able to use Twig to render your components for Storybook. You want fast refresh with Vite. You want Twig embeds, includes and extends to work. You want to use Drupal-specific twig features like create_attributes etc. You want compilation of PostCSS and SASS to CSS. You want Hot Module Reloading (HMR) so that you can see how your components look without needing to endlessly refresh.
Enter vite-plugin-twig-drupalThe Vite plugin Twig Drupal is a Vite plugin based on Twig JS for compiling Twig-based components into a JavaScript function so that they can be used as components with Storybook. It allows you to import Twig files into your story as though they are JavaScript files.
Comparison to other solutions- Vite plugin twig loader doesn't handle nested includes/embeds/extends. These are a fairly crucial feature of Twig when building a component library as they allow re-use and DRY principles
- Components library server requires you to have a running Drupal site. Whilst this ensures your Twig output is identical to that of Drupal (because Drupal is doing the rendering), it is a bit more involved to setup. If you're going to use single directory components or a similar Drupal module like UI patterns then this may be a better option for you.
This module is distributed via npm, which is bundled with node and should be installed as one of your project's devDependencies:
npm install --save-dev vite-plugin-twig-drupalYou then need to configure your vite.config.js.
import { defineConfig } from "vite" import twig from 'vite-plugin-twig-drupal'; import { join } from "node:path" export default defineConfig({ plugins: [ // Other vite plugins. twig({ namespaces: { components: join(__dirname, "/path/to/your/components"), // Other namespaces as required. }, // Optional if you are using React storybook renderer. The default is 'html' and works with storybook's html // renderer. // framework: 'react' }), // Other vite plugins. ], })With this config in place, you should be able to import Twig files into your story files.
ExamplesTo make use of a Twig file as a Storybook component, just import it. The result is a component you can pass to Storybook or use as a function for more complex stories.
// stories/Button.stories.js // Button will be a Javascript function that accepts variables for the twig template. import Button from './button.twig'; // Import stylesheets, this could be a sass or postcss file too. import './path/to/button.css'; // You may also have JavaScript for the component. import './path/to/some/javascript/button.js'; export default { title: 'Components/Button', tags: ['autodocs'], argTypes: { title: { control: { type: 'text' }, }, modifier: { control: { type: 'select' }, options: ['primary', 'secondary', 'tertiary'], }, }, // Just pass along the imported variable. component: Button, }; // Set default variables in the story. export const Default = { args: { title: 'Click me' }, }; export const Primary = { args: { title: 'Click me', modifier: 'primary' }, }; // Advanced example. export const ButtonStrip = { name: 'Button group', render: () => ` ${Button({title: 'Button 1', modifier: 'primary'})} ${Button({title: 'Button 2', modifier: 'secondary'})} ` }Here's how that might look in Storybook (example from the Admin UI Initiative storybook)
Dealing with Drupal.behaviorsIn cases where the JavaScript you import into your story file uses a Drupal behavior, you'll likely need some additional code in your Storybook configuration to handle firing the behaviors. Here at PreviousNext, we prefer to use a loadOnReady wrapper, which works with and without Drupal. However, if you're just using Drupal.behaviors something like this in your Storybook config in main.js (or main.ts) will handle firing the behaviors.
const config = { // ... existing config previewBody: (body) => ` window.Drupal = window.Drupal || {behaviors: {}}; window.drupalSettings = Object.assign(window.drupalSettings || {}, { // Mock any drupalSettings your behaviors need here. }); // Mock Drupal's once library too. window.once = (_, selector) => document.querySelectorAll(selector); document.addEventListener('DOMContentLoaded', () => { Object.entries(window.Drupal.behaviors).forEach(([key, object]) => object.attach(document)); }) ${body} ` // ... more config }Give it a tryWe're looking forward to using this plugin in client projects and are excited about the other possibilities Storybook provides us with, such as interaction and accessibility testing.
Thanks to early testers in the community, such as Ivan Berdinsky and Sean Blommaert, who've already submitted some issues to the github queue. We're really happy to see it in use in the Admin Initiative's work on a new toolbar.
Give it a try, and let us know what you think.
Tagged Storybook, Front End Development