Feeds

Real Python: Python Basics Exercises: Lists and Tuples

Planet Python - Tue, 2024-02-06 09:00

In Python Basics: Lists and Tuples, you learned that Python lists resemble real-life lists in many ways. They serve as containers for organizing and storing collections of objects, allowing for the inclusion of different data types. You also learned about tuples, which are also collections of objects. However, while lists are mutable, tuples are immutable.

In this Python Basics Exercises course, you’ll test and reinforce your knowledge of Python lists and tuples. Along the way, you’ll also get experience with some good programming practices that will help you solve future challenges.

In this video course, you’ll practice:

  • Defining and manipulating lists and tuples in Python
  • Leveraging the unique qualities of lists and tuples
  • Determining when you should use lists vs tuples

By the end of this course, you’ll have an even stronger grasp of Python lists and tuples. You’ll be equipped with the knowledge to effectively incorporate them into your own programming projects.

This video course is part of the Python Basics series, which accompanies Python Basics: A Practical Introduction to Python 3. You can also check out the other Python Basics courses.

Note that you’ll be using IDLE to interact with Python throughout this course.

[ 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 ]

Categories: FLOSS Project Planets

Tag1 Consulting: Gander Automated Performance Testing - Video Demo with Catch

Planet Drupal - Tue, 2024-02-06 08:41

In this second part (check the first part!) of our Tag1 Team Talk on Gander, the new Automated Performance Testing Framework integrated into Drupal Core, we get a live demo from Nat Catchpole (aka. Catch), the lead developer on the project. Nat takes us on a tour through this high-impact tool developed by Tag1 in collaboration with the Google Chrome Team, showing you how you can get up and running with automated performance testing for your projects. Gander is poised to significantly impact Drupal's user experience, performance and Core Web Vitals by creating visibility into how Drupal performs on the front and back end. Catch shares his expert insights into the development and application of Gander and shows how easy it is for developers to start extending and using this today on their projects! Whether you're a Drupal developer looking to improve your project's performance or simply curious about the latest in Drupal technology, this episode offers valuable knowledge and practical advice on getting your Drupal website to perform optimally. With discussions on Gander's immediate benefits and future potential in the Drupal community, this episode is a must-watch for anyone interested in taking their projects to the next level...

Read more Mariano Tue, 02/06/2024 - 05:41
Categories: FLOSS Project Planets

Robert McQueen: Flathub: Pros and Cons of Direct Uploads

Planet Debian - Tue, 2024-02-06 05:57

I attended FOSDEM last weekend and had the pleasure to participate in the Flathub / Flatpak BOF on Saturday. A lot of the session was used up by an extensive discussion about the merits (or not) of allowing direct uploads versus building everything centrally on Flathub’s infrastructure, and related concerns such as automated security/dependency scanning.

My original motivation behind the idea was essentially two things. The first was to offer a simpler way forward for applications that use language-specific build tools that resolve and retrieve their own dependencies from the internet. Flathub doesn’t allow network access during builds, and so a lot of manual work and additional tooling is currently needed (see Python and Electron Flatpak guides). And the second was to offer a maybe more familiar flow to developers from other platforms who would just build something and then run another command to upload it to the store, without having to learn the syntax of a new build tool. There were many valid concerns raised in the room, and I think on reflection that this is still worth doing, but might not be as valuable a way forward for Flathub as I had initially hoped.

Of course, for a proprietary application where Flathub never sees the source or where it’s built, whether that binary is uploaded to us or downloaded by us doesn’t change much. But for an FLOSS application, a direct upload driven by the developer causes a regression on a number of fronts. We’re not getting too hung up on the “malicious developer inserts evil code in the binary” case because Flathub already works on the model of verifying the developer and the user makes a decision to trust that app – we don’t review the source after all. But we do lose other things such as our infrastructure building on multiple architectures, and visibility on whether the build environment or upload credentials have been compromised unbeknownst to the developer.

There is now a manual review process for when apps change their metadata such as name, icon, license and permissions – which would apply to any direct uploads as well. It was suggested that if only heavily sandboxed apps (eg no direct filesystem access without proper use of portals) were permitted to make direct uploads, the impact of such concerns might be somewhat mitigated by the sandboxing.

However, it was also pointed out that my go-to example of “Electron app developers can upload to Flathub with one command” was also a bit of a fiction. At present, none of them would pass that stricter sandboxing requirement. Almost all Electron apps run old versions of Chromium with less complete portal support, needing sandbox escapes to function correctly, and Electron (and Chromium’s) sandboxing still needs additional tooling/downstream patching to run inside a Flatpak. Buh-boh.

I think for established projects who already ship their own binaries from their own centralised/trusted infrastructure, and for developers who have understandable sensitivities about binary integrity such such as encryption, password or financial tools, it’s a definite improvement that we’re able to set up direct uploads with such projects with less manual work. There are already quite a few applications – including verified ones – where the build recipe simply fetches a binary built elsewhere and unpacks it, and if this already done centrally by the developer, repeating the exercise on Flathub’s server adds little value.

However for the individual developer experience, I think we need to zoom out a bit and think about how to improve this from a tools and infrastructure perspective as we grow Flathub, and as we seek to raise funds for different sources for these improvements. I took notes for everything that was mentioned as a tooling limitation during the BOF, along with a few ideas about how we could improve things, and hope to share these soon as part of an RFP/RFI (Request For Proposals/Request for Information) process. We don’t have funding yet but if we have some prospective collaborators to help refine the scope and estimate the cost/effort, we can use this to go and pursue funding opportunities.

Categories: FLOSS Project Planets

Qt Wayland, Supercharged

Planet KDE - Tue, 2024-02-06 05:00

One of the key components to using a Plasma Wayland session is obviously the Qt Wayland Client module for running Qt applications in a Wayland environment. While it has been successfully deployed to millions of devices over the years, there’s still a few areas that feel like they haven’t been touched much since its inception as part of the Qt Lighthouse project, what turned into QPA, the Qt Platform Abstraction.

WIP: Qt Wayland client-side decoration with a proper drop shadow and all Improving the SHM Backing Store

Fushan Wen complained about abysmal performance when using Kolourpaint (a faithful re-creation of the original MS Paint, just better) under Wayland. Thanks to Hotspot (my favorite profiler front-end) we found a bottleneck in Qt’s Wayland SHM (Shared Memory) Backing Store, the infrastructure that provides software-rendered applications with a canvas to draw into. The way Wayland works is basically that an application creates a wl_buffer, fills it with content, and “sends” it to the compositor. Once the compositor is done processing it (e.g. after having uploaded it to the GPU) the client may re-use that buffer again.

If we pick a different buffer to draw into because we want to start drawing before the compositor is done with the previous one, any previous content needs to be transferred over since Qt expects to see the contents it drew previously. This is where we found the choke point: Even though the application reported the correct region that changed (when drawing with a brush only the new splodges of color need to be rendered after all), Qt Wayland copied the entire buffer. Therefore, I replaced the original memcpy with proper damage tracking which significantly sped up rendering. Many thanks to Ilya Fedin for continued support while implementing this.

I then did more profiling and found that when painting on a window with alpha channel, Qt first clears the region to be painted. While there’s not much we can optimize about a “fill with color” call, we can skip doing that entirely if we have just created a new buffer, like is done repeatedly as you resize the window. The new buffer is initialized with zeroes already, therefore we can just start painting on it. Last but not least, I added support for “scrolling” the backing store, which is something Qt might ask us to do when scrolling through a view, such as a text editor or terminal window, and then have the application just fill in a small gap that’s left.

Prettified “Bradient” Decoration Kolourpaint running under Weston with client-side decorations

I very much dislike client-side decorations for their inconsistencies and burden they put on application developers but I nevertheless grew tired of seeing how hideous Qt applications looked on colleague’s computers running Gnome Shell. That is why I spent some time on making Qt’s “Bradient” decoration plug-in not stick out like a sore thumb. While it’s a massive improvement over the blue decoration Qt Wayland originally shipped, there is still a lot to be desired.

I believe it’s quite detrimental that Mutter doesn’t support server-side decorations at all under Wayland. There’s plenty of applications that display non-application content and don’t care much about providing any decoration. For example, even running kwin_wayland under Gnome for development purposes gives you a window with no title bar or window border whatsoever.

Qt likewise relies on the desktop environment to provide a window frame and its drawing of client-side decorations under Wayland is if anyting a massive band-aid. Currently, Qt’s backing store just adds a window decoration around it and then returns the application a region inside the image that excludes the decoration again. It also lacks several features that one would expect from a window title bar, like double click to maximize or clicking the icon to bring up the window manager menu. In the future I am looking forward to putting the decoration into a sub-surface (or even using libdecor) which hopefully fixes many issues related to input and format handling.

Opening the window menu by clicking the icon, just as you would expect

To start off, the easiest change I did was using the correct mouse cursors for resizing the window. I then found that mouse input wasn’t properly translated when the window border was too thick, something that wasn’t noticeable with the default 3px border but surely would become a problem once we added a large shadow. Next, I fixed it not updating live when system colors changed, e.g. when enabling “Dark Mode”. Additionally, the title bar now includes the application name to be consistent with the title it sends to the compositor for display in task bar and window switchers.

Still, adding a proper drop shadow is work in progress: the most important part is to actually remove the window border and rounded corners altogether when the window is maximized or tiled and to adjust the button layout machinery to cope with changing margins. However, I also need to move the qt_blurImage function which creates the drop shadow texture into a place where I can use it without Qt Graphics Views or Qt Widgets (it’s currently used internally by QGraphicsBlurEffect).

Drag’n’Drop

Furthermore, I improved drag and drop handling: Qt Wayland now tries to decode URLs as UTF-8 – Chrome sometimes sends them like this – rather than just UTF-16. I also had it ignore the mysterious “DELETED” format Firefox sends that is likely a remnant from the XDnd specification. The latter fixes dropping an image to the desktop to set it as a wallpaper since Firefox doesn’t actually let anyone read this entry and Plasma gets stuck on it until it runs into a socket timeout.

Dragging a folder using the correct “Copy” cursor rather than the generic “Grabbing Hand” it had previously

The mouse now also uses the proper drag cursors. While the compositor may overrule the preferred action, we still want the default to match other desktop environments. I also fixed keyboard modifier propagation during drag and drop. While Wayland sends an explicit keyboard modifier change (Shift/Alt/Meta pressed or released), it does so after sending the actual key press. Qt on the other hand only updates its internal modifier state in response to an actual key presses. This meant that Qt doesn’t properly update its internal state when pressing a modifier when starting to drag a file and then holding Shift to initiate a “Move” operation. To fix that, Qt Wayland emits drag and drop events (and others) using the Wayland-internal modifier state rather than the one in QGuiApplication.

Categories: FLOSS Project Planets

Update: xdg-toplevel-drag merged

Planet KDE - Tue, 2024-02-06 04:00

In the last post I talked about making things like detachable tabs or widgets work in a Wayland work. The protocol I submitted has now been merged into wayland-protocols!

Following I quickly switched Qt and KWin to use the now standardized protocol. KWin will support it with the initial 6.0 release. The Qt patch has been picked all the way down to the 6.6 branch which means it should be in the 6.6.3 release.

I am also happy to see that Robert Mader is working on making Chrome use the standard protocol, picking up my proof-of-concept level patch. Thank you!

Happy dragging!

Categories: FLOSS Project Planets

Python Bytes: #370 Your Very Own Heroku

Planet Python - Tue, 2024-02-06 03:00
<strong>Topics covered in this episode:</strong><br> <ul> <li><a href="https://dokku.com"><strong>Dokku</strong></a></li> <li><a href="https://www.nicholashairs.com/posts/major-changes-between-python-versions/"><strong>Summary of Major Changes Between Python Versions</strong></a></li> <li>How to check Internet Speed via Terminal? <a href="https://github.com/sivel/speedtest-cli">speedtest-cli</a></li> <li><strong>Blogs: We all should blog more</strong></li> <li><strong>Extras</strong></li> <li><strong>Joke</strong></li> </ul><a href='https://www.youtube.com/watch?v=1P-XjiHzSNU' style='font-weight: bold;'data-umami-event="Livestream-Past" data-umami-event-episode="370">Watch on YouTube</a><br> <p><strong>About the show</strong></p> <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://courses.pythontest.com/p/the-complete-pytest-course"><strong>The Complete pytest Course</strong></a></li> <li><a href="https://www.patreon.com/pythonbytes"><strong>Patreon Supporters</strong></a></li> </ul> <p><strong>Connect with the hosts</strong></p> <ul> <li>Michael: <a href="https://fosstodon.org/@mkennedy"><strong>@mkennedy@fosstodon.org</strong></a></li> <li>Brian: <a href="https://fosstodon.org/@brianokken"><strong>@brianokken@fosstodon.org</strong></a></li> <li>Show: <a href="https://fosstodon.org/@pythonbytes"><strong>@pythonbytes@fosstodon.org</strong></a></li> </ul> <p>Join us on YouTube at <a href="https://pythonbytes.fm/stream/live"><strong>pythonbytes.fm/live</strong></a> to be part of the audience. Usually Tuesdays at 11am PT. Older video versions available there too.</p> <p><strong>Michael #1:</strong> <a href="https://dokku.com"><strong>Dokku</strong></a></p> <ul> <li>An open source PAAS alternative to Heroku.</li> <li>Dokku helps you build and manage the lifecycle of applications from building to scaling.</li> <li>Powered by Docker, you can install Dokku on any hardware.</li> <li>Once it's set up on a host, you can push Heroku-compatible applications to it via Git. </li> <li>Rich <a href="https://dokku.com/docs/community/plugins/">plug in architecture</a>.</li> </ul> <p><strong>Brian #2:</strong> <a href="https://www.nicholashairs.com/posts/major-changes-between-python-versions/"><strong>Summary of Major Changes Between Python Versions</strong></a></p> <ul> <li>Nicholas Hairs</li> <li>Changes between versions &amp; Tools &amp; utilities to help with switching</li> <li>Hopefully you’re already at least at 3.8, but come on, 3.11 &amp; 3.12 are so fun!</li> <li>Useful things <ul> <li><code>pyupgrade</code> can automatically upgrade code base <ul> <li>(However, I frequently just upgrade and run tests and let my old code be as-is until it bugs me. - Brian)</li> </ul></li> <li><code>black</code> checks <code>pyproject.toml</code> <code>requires-python</code> setting and uses version specific rules.</li> </ul></li> <li>Versions (way more highlights listed in the article) <ul> <li>3.8 <ul> <li>Assignment expressions <code>:=</code> walrus</li> <li><code>f"{variable=}"</code> now works</li> </ul></li> <li>3.9 <ul> <li>Typing has built in generics like <code>dict[]</code>, so no more <code>from typing import Dict</code></li> <li>Dict union operator</li> <li>Strings can <code>removeprefix</code> and <code>removesuffix</code></li> </ul></li> <li>3.10 <ul> <li>Structural pattern matching <code>match/case</code></li> <li>Typing: Union using pipe <code>|</code></li> <li>Dataclasses support <code>slots=True</code> and <code>kw_only=True</code></li> </ul></li> <li>3.11 <ul> <li><code>tomllib</code> included as a standard TOMP parser</li> <li>Exception groups</li> <li>Exception Notes <code>add_note()</code></li> <li>Typing: A <code>Self</code> type</li> <li>Star unpacking expressions allowed in <code>for</code> statements: <code>for x in *a, *b:</code></li> </ul></li> <li>3.12 <ul> <li>f-strings can re-use quotes</li> <li>Typing: better type parameter syntax</li> <li>Typing: <code>@override</code> decorator ensures a method being overridden by a child class actually exists.</li> </ul></li> </ul></li> </ul> <p><strong>Michael #3:</strong> How to check Internet Speed via Terminal? <a href="https://github.com/sivel/speedtest-cli">speedtest-cli</a></p> <ul> <li>Command line interface for testing internet bandwidth using speedtest.net</li> <li>Just <code>pipx install speedtest-cli</code></li> <li>Has a <a href="https://github.com/sivel/speedtest-cli/wiki">Python API</a> too</li> </ul> <p><strong>Brian #4:</strong> <strong>Blogs: We all should blog more</strong></p> <ul> <li>Jeff Triplett is attempting one post per day in February <ul> <li>Feb 1: <a href="https://micro.webology.dev/2024/02/01/choosing-the-right.html">Choosing the Right Python and Django Versions for Your Projects</a></li> <li>Feb 2: <a href="https://micro.webology.dev/2024/02/02/my-first-mac.html">My First Mac</a> <ul> <li>Which also links to a quite interesting Personal: <a href="https://jefftriplett.com/2023/default-apps-2023/">Default Apps 2023</a></li> </ul></li> <li>Feb 3: <a href="https://micro.webology.dev/2024/02/03/whats-your-goto.html">What’s Your Go-to Comfort Media? [rough cut]</a></li> <li>Feb 4: <a href="https://micro.webology.dev/2024/02/04/the-django-apps.html">The Django apps I actually use (rough cut)</a></li> <li>Feb 5: <a href="https://micro.webology.dev/2024/02/05/how-to-test.html">How to test with Django and pytest fixtures</a></li> </ul></li> <li>Need ideas? <ul> <li>Check out <a href="https://hamatti.org/posts/build-an-idea-bank-and-never-run-out-of-blog-ideas/">Build an idea bank and never run out of blog ideas</a></li> </ul></li> <li>Not using AI? Thanks. We appreciate that. <ul> <li>Maybe tag it as <a href="https://notbyai.fyi/">Not By AI</a></li> </ul></li> </ul> <p><strong>Extras</strong> </p> <p>Brian:</p> <ul> <li>If upgrading to pytest 8, be aware that running individual tests with parametrization will result in a reverse order. <ul> <li>It shouldn’t matter. <a href="https://podcast.pythontest.com/episodes/211-stamp-out-test-dependencies-with-pytest-plugins">You shouldn’t be depending on test order.</a></li> <li>But it was surprising to me.</li> <li><a href="https://github.com/pytest-dev/pytest/issues/11937">Issue has been logged</a></li> </ul></li> </ul> <p>Michael:</p> <ul> <li><a href="https://orbstack.dev">Orbstack</a> follow up</li> </ul> <p><strong>Joke:</strong> <a href="https://workchronicles.com/white-lies/">White Lies</a></p>
Categories: FLOSS Project Planets

Specbee: Style Made Simple with Acquia Site Studio’s Style Guide Manager

Planet Drupal - Tue, 2024-02-06 02:41
Ever wished you could tweak your web page’s header font or switch up your CTA color, but skipped it to save your developer from the hassle? With Acquia Site Studio’s Style Guide Manager, you don’t have to! Non-technical content marketers now have the power to make styling tweaks to their Drupal site theme via an intuitive interface. Are you interested in learning more? Come on in! What is Site Studio Style Guide Manager Previously Acquia Cohesion, Site Studio is a composable, low-code digital experience tool by Acquia that enables users to build and assemble pages with less to no code. Check out our previously written article about how to build component-based websites on Drupal using Site Studio.   Style Guide Manager is an optional module that you can enable within Site Studio. It centralizes the design elements like colors, typography, and components in one place, making it easier to maintain a cohesive look and feel throughout your site. It provides a set of style guides that are theme-specific. You can create style guide(s) to manage Site Studio styles within your Drupal theme settings. You can even override your theme styles using the Style guides. Advantages: Change the appearance of your Drupal website based on the active theme. Apply global styles and change the appearance with a simple-to-use interface. Create design systems for multi-brand and multi-sites. Style guide manager has two interfaces: Style guide builder Style guide Style Guide Builder The Style Guide Builder is a tool within Acquia Site Studio that allows you to actively create and manage the Style Guide. It streamlines the process of updating and maintaining the design standards. Changes made here are automatically applied throughout the site. Style guide The output of a Style Guide Builder - a set of design guidelines, is the Style Guide. The Style Guide is a collection of design rules, standards, and components that define the visual appearance of your website. Creating a Style Guide First, make sure you have installed Acquia Site Studio.  Navigate to /admin/cohesion/style_guides  Click on Add Style guide Add the Title Click the + button below the Style Guide form to add the form fields. Add the fields such as Font picker, Color picker, etc. with the combination of form layout fields such as Group accordion, and Tabs as per your requirement. Give a meaningful name for the Field Label so it will generate a meaningful token. This is how your Style Guide creation page will look like: You can also see the preview below of your Style Guide form builder and how it looks on the theme settings. Click on Save and Continue Managing your Styles Now that you have successfully created a Style Guide, let's see where and how you can manage your styles. Navigate to your theme appearance settings (here mine is: /admin/appearance/settings/techx) Add your values such as fonts, colors, etc., and save the configuration. This is how your style guide will look like after successfully saving the configuration. Now, you need to use the Style Guide tokens in the styles to see your styles on the front end as per the Style Guide values. Tokens are predefined variables or placeholders representing design elements such as colors, typography, spacing, and other visual properties. This is not just restricted to styles, you can use these tokens throughout your Site Studio like templates, or components as per your requirements. For example: Make sure you enable the token variable mode and then add your tokens. Implementing the Style Guide With Site Studio’s Style Guide Manager, you can create multiple style guides as per your requirements. You can see all of them in your theme settings as shown below This is what my front end looks like. You can change the values in the Style Guide per your requirements and verify the page/site accordingly. Final Thoughts Site Guide Manager is a very useful tool for non-technical users like content editors and marketers to see all the styles in one place with an easy-to-use user interface and modify them according to their choice. All of this without depending on a developer.        Are you looking to build highly engaging, omnichannel, and result-driven solutions with Acquia and Drupal? We are Acquia partners and we know what it takes to get you there. Talk to us today to find out more.        
Categories: FLOSS Project Planets

Pages