FLOSS Project Planets

Real Python: Python Basics Exercises: Scopes

Planet Python - Tue, 2024-04-23 10:00

On your Python journey, you’ve worked with functions and loops. To fully understand functions and loops in Python, you need to be familiar with the issue of scope.

In this Python Basics Exercises video course, you’ll practice:

  • Identifying the scope of objects
  • Working with the global keyword
  • Exploring the LEGB rule for scope resolution
  • Using the return statement in a function

Scope can be one of the more difficult programming concepts to understand, so in this video course, you’ll get additional practice working with it.

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. If you’re just getting started, then you might want to check out Python Basics: Setting Up Python before diving into 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

Django Weblog: DjangoCon US 2024 CFP Last Call

Planet Python - Tue, 2024-04-23 10:00

Hey Django enthusiasts!

Have you submitted your talk or tutorial for DjangoCon US 2024, in beautiful Durham, North Carolina, USA?

Time flies, and we're fast approaching the deadline (April 24, 2024 at 12 PM EDT) for DjangoCon US 2024 Call for Proposals (CFP). If you've been pondering sharing your Django journey, showcasing your innovative projects, or imparting your expertise to fellow developers, now is the perfect moment to seize the opportunity!

Here's why you should take action and submit your proposals before the clock runs out:

  • Share Your Knowledge: DjangoCon US isn't just a conference; it's a platform for sharing insights, discoveries, and lessons learned. Your unique experiences could be just what someone else needs to overcome a hurdle or spark a new idea.
  • Join the Community: DjangoCon US isn't just about talks; it's about building connections. By presenting at the conference, you become an integral part of the vibrant Django community, exchanging ideas, and forging new friendships with like-minded developers.
  • Boost Your Profile: Whether you're a seasoned speaker or a first-time presenter, DjangoCon US offers a valuable opportunity to elevate your profile in the tech industry. Showcase your expertise, gain visibility, and enhance your professional credibility among peers and potential employers.
  • Contribute to Diversity: DjangoCon US values diversity and inclusion. Your perspective matters, and by sharing your voice, you contribute to creating a more inclusive and representative tech community.

Submitting a proposal is easy! Just head over to the DjangoCon US website, fill out the submission form, and share your compelling idea with us. Whether it's a deep dive into a technical topic, a case study of your latest project, or a discussion on the future of Django, we want to hear from you.

Remember, the deadline for CFP submissions is fast approaching, so don't wait until the last minute. Take this opportunity to inspire, educate, and connect with your fellow Django enthusiasts at DjangoCon US 2024!

See you at the conference!

If you have questions feel free to contact us.

Categories: FLOSS Project Planets

DrupalEasy: cspell and drupalorg CLI: two useful tools for Drupal contrib module maintainers

Planet Drupal - Tue, 2024-04-23 08:34

While preparing the recent Markdown Easy 1.0.1 release, I utilized a couple of tools that I hadn't used before in order to help improve code quality as well as the quality of the release notes.

cspell

cspell is a Node.js spell-checker for code that was made available to the default Drupal GitLab templates in February, 2024. There is a new SKIP_CSPELL variable that can be set if you'd like your project to completely ignore cspell (it is enabled by default.) Documentation on using cspell in Drupal GitLab pipelines is available. I'd wager that most Drupal contrib maintainers will have the need for a custom word list (as I did,) so I took a few minutes to learn a bit more about it.

Cspell uses its default wordlist along with a few add-on dictionaries related to Drupal development (anecdotally, words like "mglaman," "gloop," "skynet," and "vampirize" are included) for checking the spelling of both variable names as well as code comments, but luckily, additional words (and patterns) can be added on a per-project basis in order to achieve a clean cspell report in GitLab pipelines. While there are several methods to add a list of custom words, the way I felt was most elegant (and easy for me to remember in the future!) was to add a .cspell-project-words.txt file on the project root (in this case, the contrib module is the project.) This file then includes a list of words that cspell should not flag as misspellings. For the Markdown Easy project, I went with "Anello," "~commonmark," and "~ultimike" (possibly for obvious reasons.) The ~ modifier indicates those words are case-insensitive (additional modifiers are available.) With that change, Markdown Easy now earns a passing score from the cspell pipeline. 

drupalorg CLI

drupalorg is a command-line interface maintained by (who else?) Matt Glaman. I actually learned about this tool a few years ago after Matt blogged about it, but for whatever reason, I only thought about installing and (finally) using it recently. The general idea is to provide a command line tool for contributors to interact with drupal.org. It's available commands are:

help Displays help for a command list Lists commands cache cache:clear (cc) Clears caches ci drupalci drupalci:list (ci:l) Lists test results for an issue drupalci:watch (ci:w) Watches a Drupal CI job issue issue:apply Applies the latest patch from an issue. issue:branch Creates a branch for the issue. issue:interdiff Generate an interdiff for the issue from local changes. issue:link Opens an issue issue:patch Generate a patch for the issue from committed local changes. maintainer maintainer:issues (mi) Lists issues for a user, based on maintainer. maintainer:release-notes (rn, mrn) Generate release notes. project project:issues (pi) Lists issues for a project. project:kanban Opens project kanban project:link Opens project page project:release-notes (prn) View release notes for a release project:releases Lists available releases tci travisci travisci:list (tci:l) Lists Travis Ci builds for a Drupal project travisci:watch (tci:w) Watches a Travis CI job

The maintainer:release-notes command is especially helpful to automatically generate release notes for a new version of a Drupal contrib project. Here's how I installed and used this tool to generate the release notes for Markdown Easy 1.0.1:

  1. I downloaded the drupalorg.phar to a new ~/sites/drupalorg/ directory on my local, and renamed the file to just drupalorg.
  2. I then gave execute permission to this file via chmod u+x ~/sites/drupalorg/drupalorg
  3. I use zsh, so I added the following to my ~/.zshrc file and then restarted my terminal:

    # drupalorg command line tool export PATH="/Users/michael/sites/drupalorg:$PATH"
  4. Here's the important part - I then navigated to my local, working copy of the Markdown Easy module. In my case cd ~/sites/d10/web/modules/contrib/markdown_easy 
  5. I then ran the following command to generate the release notes: drupalorg maintainer:release-notes 1.0.0  

I assumed at first that I should use the current release (1.0.1) as the argument, but after reading the documentation, I discovered that the command will generate release notes from the tag provided in the argument.

I also originally assumed that the command would take a contrib module's machine name as an argument, but after a few minutes of poking around the documentation, I realized that the command must be run from the module's directory.

You can see the automatically generated release notes here.

Summary

Both of these tools were rather easy to implement (once I read just a little bit of documentation) and seem like they'll be useful for just about any Drupal contrib maintainer. 

Categories: FLOSS Project Planets

PyPy: PyPy v7.3.16 release

Planet Python - Tue, 2024-04-23 08:22
PyPy v7.3.16: release of python 2.7, 3.9, and 3.10

The PyPy team is proud to release version 7.3.16 of PyPy.

This release includes security fixes from upstream CPython, and bugfixes to the garbage collector, described in a gc bug-hunt blog post.

The release includes three different interpreters:

  • PyPy2.7, which is an interpreter supporting the syntax and the features of Python 2.7 including the stdlib for CPython 2.7.18+ (the + is for backported security updates)

  • PyPy3.9, which is an interpreter supporting the syntax and the features of Python 3.9, including the stdlib for CPython 3.9.19.

  • PyPy3.10, which is an interpreter supporting the syntax and the features of Python 3.10, including the stdlib for CPython 3.10.14.

The interpreters are based on much the same codebase, thus the multiple release. This is a micro release, all APIs are compatible with the other 7.3 releases. It follows after 7.3.15 release on Jan 15, 2024

We recommend updating. You can find links to download the v7.3.16 releases here:

https://pypy.org/download.html

We would like to thank our donors for the continued support of the PyPy project. If PyPy is not quite good enough for your needs, we are available for direct consulting work. If PyPy is helping you out, we would love to hear about it and encourage submissions to our blog via a pull request to https://github.com/pypy/pypy.org

We would also like to thank our contributors and encourage new people to join the project. PyPy has many layers and we need help with all of them: bug fixes, PyPy and RPython documentation improvements, or general help with making RPython's JIT even better.

If you are a python library maintainer and use C-extensions, please consider making a HPy / CFFI / cppyy version of your library that would be performant on PyPy. In any case, both cibuildwheel and the multibuild system support building wheels for PyPy.

What is PyPy?

PyPy is a Python interpreter, a drop-in replacement for CPython It's fast (PyPy and CPython 3.7.4 performance comparison) due to its integrated tracing JIT compiler.

We also welcome developers of other dynamic languages to see what RPython can do for them.

We provide binary builds for:

  • x86 machines on most common operating systems (Linux 32/64 bits, Mac OS 64 bits, Windows 64 bits)

  • 64-bit ARM machines running Linux (aarch64).

  • Apple M1 arm64 machines (macos_arm64).

  • s390x running Linux

PyPy support Windows 32-bit, Linux PPC64 big- and little-endian, and Linux ARM 32 bit, but does not release binaries. Please reach out to us if you wish to sponsor binary releases for those platforms. Downstream packagers provide binary builds for debian, Fedora, conda, OpenBSD, FreeBSD, Gentoo, and more.

What else is new?

For more information about the 7.3.16 release, see the full changelog.

Please update, and continue to help us make pypy better.

Cheers, The PyPy Team

Categories: FLOSS Project Planets

Real Python: Python Sequences: A Comprehensive Guide

Planet Python - Tue, 2024-04-23 08:00

In this quiz, you’ll test your understanding of Python sequences.

By working through this quiz, you’ll revisit the basic characteristics of a sequence, operations common to most sequences, special methods associated with sequences, and how to create user-defined mutable and immutable sequences.

[ 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

Programiz: Getting Started with Python

Planet Python - Tue, 2024-04-23 07:22
In this tutorial, you will learn to write your first Python program.
Categories: FLOSS Project Planets

qtatech.com blog: Drupal 9 to 10 Transition Made Simple: Real Code Insights

Planet Drupal - Tue, 2024-04-23 05:31
Drupal 9 to 10 Transition Made Simple: Real Code Insights kanapatrick Tue, 04/23/2024 - 10:31

Have you found yourself gearing up for the transition from Drupal 9 to Drupal 10, only to be met with complexities and uncertainties along the way? You're not alone in this journey. Making the switch between major versions of a CMS can feel like navigating through a maze of code and updates, leaving you puzzled and overwhelmed.

Categories: FLOSS Project Planets

Python Bytes: #380 Debugging with your eyes

Planet Python - Tue, 2024-04-23 04:00
<strong>Topics covered in this episode:</strong><br> <ul> <li><a href="https://pirsquared.org/blog/numfocus-concerns.html"><strong>NumFOCUS concerns</strong></a></li> <li><a href="https://github.com/leapingio/leaping">leaping pytest debugger llm</a></li> <li><strong>Extra, Extra, Extra,</strong></li> <li><a href="https://blog.pypi.org/posts/2023-11-14-1-pypi-completes-first-security-audit/">PyPI has completed its first security audit</a></li> <li><strong>Extras</strong></li> <li><strong>Joke</strong></li> </ul><a href='https://www.youtube.com/watch?v=axdty2K79v8' style='font-weight: bold;'data-umami-event="Livestream-Past" data-umami-event-episode="380">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>Finally, if you want an artisanal, hand-crafted digest of every week of </p> <p>the show notes in email form? Add your name and email to <a href="https://pythonbytes.fm/friends-of-the-show">our friends of the show list</a>, we'll never share it.</p> <p><strong>Brian #1:</strong> <a href="https://pirsquared.org/blog/numfocus-concerns.html"><strong>NumFOCUS concerns</strong></a></p> <ul> <li>Suggested by Pamphile Roy</li> <li>Write up of the current challenges faced by NumFOCUS, by Paul Ivanov (one of the OG of Scientific Python: Jupyter, Matplotlib, etc.) <ul> <li>Struggling to meet the needs of sponsored and affiliated projects.</li> <li>In February, NumFOCUS announced it is moving in a new direction.</li> <li>NumFOCUS initiated an effort to run an election for open board seats and proposed changing its governance structure.</li> <li>Some projects are considering and actively pursuing alternative venues for fiscal sponsorship.</li> <li>Quite a bit more detail and discussion in the article.</li> </ul></li> <li><a href="https://numfocus.org/sponsored-projects">NumFOCUS covers a lot of projects</a> <ul> <li>NumPy, Matplotlib, pandas, Jupyter, SciPy, Astropy, Bokeh, Dask, Conda, and so many more.</li> </ul></li> </ul> <p><strong>Michael #2:</strong> <a href="https://github.com/leapingio/leaping">leaping pytest debugger llm</a></p> <ul> <li>You can ask Leaping questions like: <ul> <li>Why am I not hitting function x?</li> <li>Why was variable y set to this value?</li> <li>What was the value of variable x at this point?</li> <li>What changes can I make to this code to make this test pass?</li> </ul></li> </ul> <p><strong>Brian #3:</strong> <strong>Extra, Extra, Extra,</strong></p> <ul> <li><a href="https://scientific-python.org/summits/developer/2024/">2024 Developer Summit</a> <ul> <li>Also suggested by Pamphile, related to Scientific Python</li> <li><em>The Second Scientific Python Developer Summit , June 3-5, Seattle, WA</em></li> <li>Lots of great work came out of the <a href="https://blog.scientific-python.org/scientific-python/dev-summit-1/">First Summit in 2023</a></li> </ul></li> <li><a href="https://github.com/tylerjereddy/pytest-regex">pytest-regex</a> - Use regexs to specify tests to run <ul> <li>Came out of the ’23 summit</li> <li>I’m not sure if I’m super happy about this or a little afraid that I probably could use this.</li> <li>Still, cool that it’s here.</li> </ul></li> <li><a href="https://jcarlosroldan.com/post/329/my-latest-tils-about-python">Cool short example of using </a><a href="https://jcarlosroldan.com/post/329/my-latest-tils-about-python">__init__</a><a href="https://jcarlosroldan.com/post/329/my-latest-tils-about-python"> and </a><a href="https://jcarlosroldan.com/post/329/my-latest-tils-about-python">__call__</a><a href="https://jcarlosroldan.com/post/329/my-latest-tils-about-python"> to hand-roll a decorator.</a></li> <li><a href="https://astral.sh/blog/ruff-v0.4.0">ruff got faster</a></li> </ul> <p><strong>Michael #4:</strong> <a href="https://blog.pypi.org/posts/2023-11-14-1-pypi-completes-first-security-audit/">PyPI has completed its first security audit</a></p> <ul> <li>Trail of Bits spent a total of 10 engineer-weeks of effort identifying issues, presenting those findings to the PyPI team, and assisting us as we remediated the findings.</li> <li>Scope: The audit was focused on "Warehouse", the open-source codebase that powers <a href="https://pypi.org">pypi.org</a></li> <li>As a result of the audit, Trail of Bits detailed 29 different advisories discovered across both codebases. When evaluating severity level of each advisory, 14 were categorized as "informational", 6 as "low", 8 as "medium" and zero as "high".</li> </ul> <p><strong>Extras</strong> </p> <p>Brian:</p> <ul> <li>pytest course community to try out Podia Communities.</li> <li>Anyone have a podia community running strong now? <ul> <li>If so, let me know through Mastodon: <a href="https://fosstodon.org/@brianokken">@brianokken@fosstodon.org</a></li> </ul></li> <li>Want to join the community when it’s up and running? <ul> <li>Same. Or join our <a href="https://pythonbytes.fm/friends-of-the-show">our friends of the show list</a>, and read our newsletter. I’ll be sure to drop a note in there when it’s ready.</li> </ul></li> </ul> <p>Michael:</p> <ul> <li><a href="https://www.youtube.com/watch?v=Jh24NVM2FDY">VS Code AMA @ Talk Python</a><a href="https://www.youtube.com/watch?v=Jh24NVM2FDY"> </a>[<a href="https://www.youtube.com/watch?v=Jh24NVM2FDY">video]</a></li> <li><a href="https://nvd.nist.gov/vuln/detail/CVE-2024-1135">Gunicorn CVE</a></li> <li>Talk submissions are now open for both remote and in-person talks at the 2024 PyConZA? The conference will be held on 3 and 4 October 2024 in Cape Town, South Africa. Details are on <a href="http://za.pycon.org">za.pycon.org</a>.</li> <li><a href="https://flaskcon.com/2024/">FlaskCon 2024</a> will be happening Friday, May 17 inside PyCon US 2024. Call for proposals are now live!</li> </ul> <p><strong>Joke:</strong> <a href="https://devhumor.com/media/debugging-with-your-eyes">Debugging with your eyes</a></p>
Categories: FLOSS Project Planets

Specbee: Improving Drupal SEO: How to Fix Duplicate Content with the Global Redirect Module

Planet Drupal - Tue, 2024-04-23 03:36
As a content writer, one thing that poses a serious concern for professionals in this field is plagiarism. It refers to the act of using someone else’s work and calling it your own. It can be frustrating and is ethically and legally unacceptable. Duplicate content is no less than plagiarism. In fact, it can cause concerns not only for content professionals but also for website owners and SEO professionals. Surprisingly, 25-30% of the content on the internet today is duplicated without people even realizing it. In this blog, we’ll talk about duplicate content, the significance of this issue in today’s metrics, and how Drupal helps you solve the problem with convenience. What is duplicate content Duplicate content simply means identical content that exists across various URLs on the internet. When identical content shows up on different URLs, search engines typically face confusion in determining which URL to prioritize in their search results. This leads to low-ranking issues for all the URLs that display similar content, while preference slides over to alternative web pages. Why is it a significant problem As mentioned earlier, duplicate content can cause issues for marketers, website owners, and SEO professionals. Let me categorize the types of issues it can bring you: For Search Engines Identification: Search engines struggle to determine which version(s) of content to include or exclude from their indexes. Link Metrics Distribution: They face uncertainty in distributing link metrics like trust, authority, anchor text, and link equity among multiple versions or a single page. Ranking Ambiguity: It becomes unclear which version(s) should rank for specific search queries. For Website Owners Search Engine Optimization: To enhance user experience, search engines tend to display only one version of duplicated content. This reduces the visibility of all duplicates. Link Equity Dilution: Inbound links are divided among duplicates rather than consolidating on one page. This disperses the link equity, affecting the search visibility of the content piece. Consequently, duplicated content fails to achieve the search visibility it could otherwise attain. What causes duplicate content Now that you’ve gathered some information about the seriousness of the issue of duplicate content, here are a few potential and technical causes that lead to content duplication. URL Parameters: This issue arises when you apply URL parameters or tracking in your website’s code. According to Google, these URL variations are created by pairing a key and a value which are separated by an equal sign, and linked by an ampersand. Consequently, although the URLs may seem distinct, users end up on the same page regardless of the link they click. Session IDs: Similar to applied URL parameters, session IDs are assigned different IDs within the URL to each user visiting your site. Multiple Versions of Your Site: This issue arises with websites that have both a www.example.com and an example.com version of their pages. It also applies to sites with an SSL certificate that maintain both HTTP and HTTPS versions of their site. Faceted Navigation: Faceted or filtered navigation allows users to refine details on your site to find the information they are looking for. It enables them to customize their search experience. However, search engines may perceive these filtered URL results as duplicated content. Types of duplicate content Duplicate content affects your SEO ranking. Having said that, in terms of search engine optimization, duplicate content is of two different types:    1. Site-wide/Cross-domain Duplicate Content Site-wide duplicate content occurs when identical or similar content is available across different pages within the same website or across multiple domains. For instance, some e-commerce platforms may use similar product descriptions on their primary domain (store.com), mobile version (m.store.com), or localized domain versions like store.ca. Such duplication of content challenges your SEO ranking.  If the duplicate content extends beyond a single website to multiple websites, determining the organic search result becomes a challenging task, requiring specific strategies to deal with the same.    2. Copied Content/Technical Problems This sounds like an oversight yet a major issue at that. Such duplicate content occurs from directly copying content to multiple locations or due to technical issues that result in the display of similar content on various URLs. This may be the case with URLs with parameters lacking canonical tags, duplicate pages without the no index directive, and copied content published without proper redirection.  When canonical tags or redirects are not appropriately set up, search engines may index and attempt to rank nearly identical versions of pages, leading to potential SEO complications. How Can Google Help Detect Duplicate Content One of the most popular and verified methods of assessing duplicate content is by simply selecting a few words from the site, enclosing them within quotes, and inputting them into Google search.  Ideally, this test on any page from your website should show your webpage in the search results, without other entries. However, if other websites also appear along with yours, Google considers the top results to be the original source of content. If you don’t find your webpage on top of the results, it might be a concern of duplicate content. You can repeat this procedure by testing several short, random sentences from your webpage using Google. Additionally, there are various free tools to check for duplicate content over the web, such as Copyscape, Plagspotter, Duplichecker, Smallseotools, and more. The Global Redirect Module: Fixing Duplicate Content SEO Issues in Drupal For those who’re unaware, Drupal is an open-source content management system that works towards simplifying development and creation processes for its global community. It offers many core and contributed modules that serve its purposes. One such module works towards fixing the issue of duplicate content - the Global Redirect Module.  The Global Redirect module is an SEO-friendly module that offers you a user-friendly interface to manage your URL path redirects. In Drupal, the alias system can sometimes lead to duplicate URLs, which can affect your website's search engine ranking. This Drupal module tackles this issue by checking for existing aliases and redirecting to the correct URL. Additionally, it manages URL formatting by removing trailing slashes, ensuring clean URL usage, and verifying node permissions and access. As per the module’s documentation source, here’s what it does to correct/fix duplicate content: Verifies if the current URL has an alias and performs a 301 redirect to it if it's not currently in use. Checks for a trailing slash in the current URL, then removes it if found, and repeats the first check with the updated request. Determines if the current URL matches the site's front page and redirects to the front page if there's a match. Ensures that Clean URLs are enabled and confirms whether the current URL is accessed using the clean method rather than the unclean method. Validates access to the URL; if the user lacks access to the path, no redirects occur. This feature helps protect private aliased nodes from exposure. Enforces the case sensitivity of the accessed URL to match the one set by the author/administrator. In non-technical interpretation of the above information, the Drupal Global Redirect module  Establishes fresh redirects. Detects faulty URL paths (ensure the “Redirect 4040” sub-module is activated for this feature). Configures redirects at the domain level (utilize the “Redirect Domain” sub-module for this purpose). Imports existing redirects. This way, you avoid the risk of having the very same content displayed on multiple URL paths. How to Configure the Global Redirect Module Before you configure the module, make sure to download it from https://www.drupal.org/project/globalredirect and then proceed with the following steps to configure the module to fix the issue of duplicate content on your Drupal site: Navigate to the Configuration page in your Drupal dashboard. In the Search and Metadata section, click on the URL redirects option. If you don’t find it, try clearing your Drupal cache and check again. On the URL redirects page, find the list of created redirects. Click on the +Add redirect button to add a new redirect. In the Path field, enter the old title or URL alias that you want to redirect from. In the To field, specify the relative internal path or the absolute external path that you want the old URL to redirect to. Choose the appropriate Redirect status from the drop-down menu. Click on Save at the bottom of the page to save the redirect configuration. Navigate to the Settings tab at the top of the page to access additional configuration options for the Global Redirect module. In the Settings tab, modify the default redirect status and adjust global redirect settings as needed.Click on Save Configuration to apply the new settings. Final Thoughts To wrap up, duplicate content affects your search engine rankings and impacts user experience as well as link equity distribution. It poses threatening challenges for content creators, website owners, and SEO professionals. Understanding the causes and types of duplicate content can help devise effective strategies to fix this issue. In Drupal, the Global Redirect module offers a convenient solution to manage URL redirects and prevent duplicity of content. While there are many other ways to boost your SEO ranking, Drupal users trust this module to work best in fixing duplicate content issues. It ensures clean URLs, proper redirection, and improved SEO performance on your Drupal site. So, employ effective measures to rank your Drupal website - avoid duplicate content, stick with Google algorithms, stay up-to-date with the latest technological measures, or you could connect with an expert Drupal development agency to enhance your Drupal SEO and boost your site’s search engine ranking.
Categories: FLOSS Project Planets

The Drop Times: A Conversation with Dominique de Cooman on Drupal, Mautic, Open DXP and Dropsolid

Planet Drupal - Tue, 2024-04-23 02:07
Join us as we delve into the realm of Dropsolid with Dominique de Cooman. Discover the driving forces behind their innovative integration of Drupal and open-source technology, and gain insights into the evolving landscape of digital experiences. From their founding principles to navigating Drupal's future, Dominique offers a candid exploration of Dropsolid's journey and its impact on the digital realm.
Categories: FLOSS Project Planets

PowerDevil in Plasma 6.0 and beyond

Planet KDE - Mon, 2024-04-22 20:00
Hi, I'm Jakob and this is my new KDE blog. Let's see how this goes as I haven't blogged for literally decades. I started working on Plasma code sometime last year and hope to play a tiny part in setting the stage for world domination improving user experiences like so many other awesome and dedicated contributors do every week.
Categories: FLOSS Project Planets

Django Weblog: An open letter regarding the DjangoCon Europe CfP

Planet Python - Mon, 2024-04-22 18:32

As many of you are not doubt aware there have recently been some community conversation regarding a license agreement that was published as part of the DjangoCon Europe Call for Proposals for organizers. I believe it is fair to characterize the reaction as negative, with expressions of anger, frustration, and confusion towards the DSF for placing burdensome and one sided requirements for hosting a DjangoCon Europe.

I want to state first and foremost that I added the licensing agreement to the CfP. My deepest apologies for everyone who felt betrayed by it. I hold our conference organizers in the highest regard, for the equity, effort, blood, sweat, and tears they put into creating amazing community events that bring us all together. I considered resigning from the board for the pain and confusion that I have caused. I have not because I want to be part of finding a way forward and keeping DjangoCon Europe the calendar event that so many of us eagerly await. It will be up to all of you if I can be part of that journey back.

The most difficulty accusation to face is that of a lack of transparency and surprising former and prospective organizers with the license. It is difficult for me because I honestly believed I was increasing the level of transparency to organizers. This licensing agreement is not a new document, though I now understand that it is new to, well, everyone. The license has existed in the DSF legal documents repository since at least 2016 and has been signed for at least one DjangoCon Europe. In my years on the board prior to my presidency on several occasions there were todos to have selected organizers "sign the organizer contract". In addition I know that DEFNA is party to an almost identical licensing contract with the DSF. It was my intention to provide to potential organizers with the contract prior to making a proposal so that when a proposal was selected the organizers would not be taken aback when being presented with the license.

I was mortified when I heard, first in private and then publicly, that no DjangoCon Europe organizers of current memory had ever signed the license. The group of some of our community's most dedicated volunteers felt like with the click of a keyboard had turned into an arms length transaction among lawyers. At the same time I was mortified at the potential legal jeopardy the DSF had unknowingly been in by not having license agreements in place for all DjangoCons.

I'd like to touch on several points brought up in the discussion that has come from this.

The first regards the time window of DjangoCon Europe as laid out in the CfP. The DSF has long standing agreements with the PSF, DEFNA, and EuroPython to not adversely impact each other's conferences by scheduling them too close together. The agreement specifies that no two conferences should be within a month of each other. The sentiment of the agreement is well placed, but I believe it is time to revisit it. With new conferences coming into the fold (it was rightly pointed out the DjangoCon Africa is not mentioned in the license), the ability for conferences to have meaningful remote participation, and a calendar that due to weather often has the four stated conferences vying for a 5-7 month slot the one month gap is difficult to plan around. I am publicly proposing here that the interested parties to this agreement modify it such that the one month window apply to either region or theme, but not both. That would have, for instance, DjangoCon US avoiding Pycon and DjangoCons Europe and Africa but not EuroPython and vice versa.

The second point is in regards to the requirement to not schedule against major religious and cultural holidays. While I did not write that, I embody it. My first DjangoCon was DjangoCon Europe. I was unable to attend DjangoCon US in Chicago while I was living in Chicago as it had been partly scheduled against Rosh Hashanah. So I convinced my boss to send me to France instead and fell in love with the Django community.

Finally to the comments that the DSF does not care about organizers and has no interest in helping them put on a conference. Unfortunately DSF does not have inherent knowledge of running conferences, no legal entity outside the US to bring to bear, or the finances to backstop a DjangoCon. We ask for your help every year to run DjangoCon Europe because, quite simply, we can't. There was a meeting in Edinburgh of former organizers to discuss how organizing a DjangoCon Europe coule be improved. That meeting was the start of the European Organizers Support working group. It did take time to get started. We have it now. It is the sincerest hope of all of us that it is the first step in improving the experience of European organizers, and hopefully others down the line. It is a slow process, but one I dearly hope bears fruit.

I sincerely hope that we can all together still work to make DjangoCon Europe 2025 a reality. I will do all that I can to make that happen, if you will continue to have me. I do not participate in social media, but have started a thread on the Django Forum to continue this discussion. For most of the next week I will be unavailable due to the Passover holiday but it was imperative to me that I get this message to you all as soon as I could.

Thank you for your time, and for letting me serve you, Chaim Kirby President, Django Software Foundation

Categories: FLOSS Project Planets

parallel @ Savannah: GNU Parallel 20240422 ('Børsen') [stable]

GNU Planet! - Mon, 2024-04-22 17:12

GNU Parallel 20240422 ('Børsen') has been released. It is available for download at: lbry://@GnuParallel:4

Quote of the month:

  I’m a big fan of GNU parallel!
    -- Scott Cain @scottjcain@twitter
 
New in this release:

  • Bug fixes and man page updates.


GNU Parallel - For people who live life in the parallel lane.

If you like GNU Parallel record a video testimonial: Say who you are, what you use GNU Parallel for, how it helps you, and what you like most about it. Include a command that uses GNU Parallel if you feel like it.


About GNU Parallel


GNU Parallel is a shell tool for executing jobs in parallel using one or more computers. A job can be a single command or a small script that has to be run for each of the lines in the input. The typical input is a list of files, a list of hosts, a list of users, a list of URLs, or a list of tables. A job can also be a command that reads from a pipe. GNU Parallel can then split the input and pipe it into commands in parallel.

If you use xargs and tee today you will find GNU Parallel very easy to use as GNU Parallel is written to have the same options as xargs. If you write loops in shell, you will find GNU Parallel may be able to replace most of the loops and make them run faster by running several jobs in parallel. GNU Parallel can even replace nested loops.

GNU Parallel makes sure output from the commands is the same output as you would get had you run the commands sequentially. This makes it possible to use output from GNU Parallel as input for other programs.

For example you can run this to convert all jpeg files into png and gif files and have a progress bar:

  parallel --bar convert {1} {1.}.{2} ::: *.jpg ::: png gif

Or you can generate big, medium, and small thumbnails of all jpeg files in sub dirs:

  find . -name '*.jpg' |
    parallel convert -geometry {2} {1} {1//}/thumb{2}_{1/} :::: - ::: 50 100 200

You can find more about GNU Parallel at: http://www.gnu.org/s/parallel/

You can install GNU Parallel in just 10 seconds with:

    $ (wget -O - pi.dk/3 || lynx -source pi.dk/3 || curl pi.dk/3/ || \
       fetch -o - http://pi.dk/3 ) > install.sh
    $ sha1sum install.sh | grep 883c667e01eed62f975ad28b6d50e22a
    12345678 883c667e 01eed62f 975ad28b 6d50e22a
    $ md5sum install.sh | grep cc21b4c943fd03e93ae1ae49e28573c0
    cc21b4c9 43fd03e9 3ae1ae49 e28573c0
    $ sha512sum install.sh | grep ec113b49a54e705f86d51e784ebced224fdff3f52
    79945d9d 250b42a4 2067bb00 99da012e c113b49a 54e705f8 6d51e784 ebced224
    fdff3f52 ca588d64 e75f6033 61bd543f d631f592 2f87ceb2 ab034149 6df84a35
    $ bash install.sh

Watch the intro video on http://www.youtube.com/playlist?list=PL284C9FF2488BC6D1

Walk through the tutorial (man parallel_tutorial). Your command line will love you for it.

When using programs that use GNU Parallel to process data for publication please cite:

O. Tange (2018): GNU Parallel 2018, March 2018, https://doi.org/10.5281/zenodo.1146014.

If you like GNU Parallel:

  • Give a demo at your local user group/team/colleagues
  • Post the intro videos on Reddit/Diaspora*/forums/blogs/ Identi.ca/Google+/Twitter/Facebook/Linkedin/mailing lists
  • Get the merchandise https://gnuparallel.threadless.com/designs/gnu-parallel
  • Request or write a review for your favourite blog or magazine
  • Request or build a package for your favourite distribution (if it is not already there)
  • Invite me for your next conference


If you use programs that use GNU Parallel for research:

  • Please cite GNU Parallel in you publications (use --citation)


If GNU Parallel saves you money:



About GNU SQL


GNU sql aims to give a simple, unified interface for accessing databases through all the different databases' command line clients. So far the focus has been on giving a common way to specify login information (protocol, username, password, hostname, and port number), size (database and table size), and running queries.

The database is addressed using a DBURL. If commands are left out you will get that database's interactive shell.

When using GNU SQL for a publication please cite:

O. Tange (2011): GNU SQL - A Command Line Tool for Accessing Different Databases Using DBURLs, ;login: The USENIX Magazine, April 2011:29-32.


About GNU Niceload


GNU niceload slows down a program when the computer load average (or other system activity) is above a certain limit. When the limit is reached the program will be suspended for some time. If the limit is a soft limit the program will be allowed to run for short amounts of time before being suspended again. If the limit is a hard limit the program will only be allowed to run when the system is below the limit.

Categories: FLOSS Project Planets

Talking Drupal: Talking Drupal #447 - Drupal Single Sign On

Planet Drupal - Mon, 2024-04-22 14:00
Today we are talking about Drupal Single Sign On, The Benefits it brings to the Drupal Community, and A new book called Fog & Fireflies with guest Tim Lehnen. We’ll also cover Drupal.org Username Field as our module of the week.

For show notes visit: www.talkingDrupal.com/447

Topics
  • What is Single Sign On (SSO)
  • Does Drupal already support SSO
  • Why is SSO on drupal.org important
  • Camps using SSO
  • Other possibilities
  • Gitlab login
  • Cloud IAM
  • Why did the Drupal Association choose Cloud IAM
  • How do you see the collaboration growing
  • Where are we now
  • What are the next steps
  • How far are we from this becoming a reality
  • What does onboarding look like
  • Will third party sites be able to use D.O SSO
  • Can the community help
  • Fog & Fireflies
    • First book
    • Can you buy it now
Resources Guests

Tim Lehnen - aspenthornpress.com hestenet

Hosts

Nic Laflin - nLighteneddevelopment.com nicxvan John Picozzi - epam.com johnpicozzi Matt Glaman - mglaman.dev mglaman

MOTW Correspondent

Martin Anderson-Clutz - mandclu

  • Brief description:
    • Have you ever wanted to have a field on user profiles specifically designed for drupal.org usernames? There’s a module for that
  • Module name/project name:
  • Brief history
    • How old: created in August 2019 by hussainweb AKA Hussain Abbas of Axelerant
    • Versions available: 2.0.0-beta4
  • Maintainership
    • Actively maintained, that release was made less than 6 months ago
    • Test coverage
    • Number of open issues: 8 open issues, none of which are bugs
  • Usage stats:
    • 1 site
  • Module features and usage
    • The module provides a new field type, along with its own widget and formatter
    • With a simple checkbox, you can get the module to validate that the provided username is registered on drupal.org
    • What’s really powerful about this module is that it can also pull other information from the drupal.org profile, such as first and last name, country, bio, and more
    • It does this by leveraging a Guzzle-based API client for drupal.org that Hussain created as part of a DrupalCon Asia developer contest
    • I believe the intended use of the modules is to use a provided drush command to copy the values from the drupal.org username field into other fields, where they would be displayed to site visitors
    • Although this module isn’t something that a lot of sites will need, I could see it being really useful for Drupal camp websites, to automatically collect a lot of the information that many such sites ask users to populate manually
    • I think it’s also an interesting use of the Drupal.org API, and could be a useful reference for anyone needing to implement a custom integration
Categories: FLOSS Project Planets

Contributing is more than just code

Planet KDE - Mon, 2024-04-22 12:00

When thinking about how to contribute to KDE, many people probably still think that you have to write actual code. While it’s true that C++ and QML is at the heart of our applications, it’s just one puzzle piece of many that make up a successful product. Besides donating money to KDE or developers like me individually, there’s much more you can do to support us: promo work, drawing icons, brainstorming ideas, writing documentation, triaging bug reports or writing new ones, or in this case sending the relevant piece of hardware to a developer. Every single contribution counts!

It’s been at least ten years since I last used an optical drive

A key ingredient to KDE’s cross-platform story is Solid, our device integration framework. It lets applications enumerate devices, such as hard drive partitions, USB thumb drives, but also batteries and peripherals, in a platform-independent way. When it comes to hardware, sometimes emulating its behavior is tough and even a virtual machine might not behave exactly the same as the real thing. Here’s the story of how the donation of a portable DVD drive let me unlock a massive performance boost.

On Linux, to enumerate storage devices it talks to UDisks2 on DBus. You can actually view all the information yourself by using qdbusviewer or d-feet and navigate to the org.freedesktop.UDisks2 service on the System Bus. The Places panel found in applications like Dolphin but also the Device Notifier applet in System Tray query Solid for interesting storage devices to display to the user.

On a typical system, there’s plenty of mount points (particularly Snap is notorious for creating lots of loop devices) which we don’t want to show. Nevertheless, we have to fetch them all to decide whether they’re interesting to us. For example, usually only storage devices explicitly listed in fstab, mounted from /media (your typical USB stick drive), or originating in the user’s home directory (an ISO image in your Downloads folder) are displayed.

Currently, owing to Solid’s modular nature and the fact that a lot of its original code was written in KDE 4 times where many API conveniences in DBus and UDisks didn’t exist yet, Solid uses the DBus Introspectable interface to enumerate all devices. This gives us an XML description of the available interfaces and object paths on the service. As you can imagine, receiving and processing that data string can be quite expensive. Furthermore, for every device that was enumerated, a Solid Device instance is created which then fetches all properties from all interfaces on the relevant object, which again can be slow. The DBus interfaces an object implements in UDisks gives us a good idea of what type of storage we’re dealing with, for example org.freedesktop.UDisks.Loop contains properties regarding loop devices, such as the original path of the image file that has been mounted, which in turn is also a org.freedesktop.UDisks.Block device, and so on.

Retrieving a mount point via DBus, eventually you realize that “47” is forward slash.

There must be a better way to do this, right? There is! It’s called org.freedesktop.DBus.ObjectManager. It lets you fetch all objects and their properties in a single call. This would allow Solid to query everything at once on startup and then only fetch individual properties when they get invalidated or a new device is plugged in at runtime.

Both encrypted drives and optical media are somewhat special in that they’re a drive (or container) containing the actual media or partition. While a USB stick just disappears entirely as you unplug it, a DVD drive will only have its media ejected. It means we need to monitor the drive and check its media availability and then announce the disc inside of it. However, when I asked fellow KDE developers to test my changes, the patch-set worked fine with the CD-ROM drive emulated in a virtual machine but failed miserably with a legit drive. The situation with Audio CDs was even worse since they don’t have a regular file system associated with. And guess what: there’s also CDs that contian both audio and data.

I asked around on KDE’s Matrix channels whether someone might have a spare USB CD-ROM drive and is willing to help. The other day MartinR approached me in the KDE neon channel and said he had a spare one he could mail somewhere. When it arrived a week later, I immediately tried it out (it’s been some time since I’ve seen a device with a USB Y cable) and it indeed let me iron out a bunch of remaining issues with the original patch-set. There’s other examples, too, where having the actual hardware is key. For instance, in order to properly develop HDR support in KWin, the developers need to have an actual screen capable of displaying it.

KWin Wayland running in HDR mode on a portable OLED screen, courtesy of Xaver (the picture of course doesn’t do it justice)

The change isn’t actually merged yet as I am in the process of writing a fake UDisks2 service for Solid. This would let us run a bunch of automated tests, particularly for the weird cases, and ensure that my refactor doesn’t cause any regressions. Solid has unit tests for its general working but not specifically to the way it interacts with UDisks2. A bug in Solid that renders your data accessible (sorry about that encrypted drives bug the other week) or causes the shell or some KDE background service to crash upon plugging in a device would be a disaster.

Having said all of that, let me thank you again very much, without your generous donation I would not have been able to realize this project. On my laptop, the time it took to initialize a KFilePlacesModel went down from 55–60 ms to just under 20 ms. The number of DBus calls it places to the UDisks2 service went down from around 60 “get all properties”, 45 “introspect”, and 15 “get this particular property” calls to a single “get all managed objects” call, and one “introspect” call I have yet to hunt down. I’m sure our users will very much appreciate a faster starting Dolphin and snappier file dialog! Also many thanks to Fabian Vogt and notably Jan R. for continued advice and testing.

If you have a KDE development setup (and if you don’t, go set one up), please test this Solid patch, and let me know if it causes any trouble for you!

Categories: FLOSS Project Planets

The Drop Times: Dialogues that Shape the Future.

Planet Drupal - Mon, 2024-04-22 11:37

Dear Readers,

At the core of any vibrant community lies the foundational practice of open and effective communication—where growth is nurtured, and innovation is sparked. For The DropTimes, our mission transcends beyond the basic dissemination of information; we actively facilitate a platform for dialogue, connecting the latest technological evolutions with an engaged readership. This integral role embodies our commitment to not only inform but also to catalyze conversation and change, ensuring that every voice can be heard and every insight can be shared, thereby driving Drupal's growth.

The vitality of these discussions within the Drupal community is observable. Whether debating the necessity of new modules for Drupal 10 or discussing the release dates for Drupal 11, each dialogue enriches our collective understanding and propels the platform forward. These conversations, highlighted in our articles and series, testify to the importance of discussing diverse perspectives and disseminating varied opinions. 

By engaging in such dynamic exchanges, the community not only addresses immediate needs and challenges but also shapes the future of the technology. This ongoing dialogue ensures that Drupal remains at the cutting edge, constantly evolving in response to the contributions and concerns of its global user base. With that, let's move on to last week's highlights.

Kazima Abbas, a sub-editor with The DropTimes [TDT]  in the second part of the "Drupal's Innovation & Future: 2024 and Beyond" series, takes a closer look at the thoughts and predictions of Drupal experts: Carlos Rincon Sanchez, Oscar Loria, Stella Power, Krishna R P, and Sinduri Guntupalli. The series aims to examine what might lie ahead for the Drupal platform with meticulous discussions.

In another interesting exchange, I had the opportunity to sit with Grzegorz Bartman, the CEO of Droptica, to discuss Droopler 4, the latest version of their Drupal distribution. Droopler is a Drupal distribution, a pre-built website that users can customize and manage to fit their requirements without having to start from scratch. Learn in-depth about Droopler 4 with this interview with Greg Bartman.

Last week's TDT Spotlight featured Gai Technologies, an organization rooted in the open-source ethos with more than 12 years of experience in web solutions. Elma John, our sub-editor, discussed the inception and journey of Gai Technologies, which is located in the serene setting of the Himalayas, with N. Krishnan, the CEO.

Pantheon, a leading SaaS-based WebOps platform, has entered into a strategic partnership with Lytics, a premier customer data platform (CDP) fully integrated with Google Cloud. Chris Yates, Pantheon’s vice president of products, and James McDermott elaborated on the technical synergies during a detailed discussion with The DropTimes. Read the detailed article to learn how this synergy will benefit Pantheon and Lytics' customers.

TDT is actively seeking volunteers to cover DrupalCon Portland 2024. Meanwhile, the insights from our DrupalCon Pittsburg 2023 volunteers can be read here. Aiden F Dean Dunn, a then-recent graduate from the University of Pittsburgh, provides a fresh perspective on the event in a conversation with Varun Baker, highlighting the welcoming and diverse nature of the Drupal community. Additionally, the regular registration window of DrupalCon Portland 2024 has ended; late registration is open today.

Drupalers can now win a free ticket to DrupalCon Barcelona 2024 with the promo video contest. All are encouraged to record a brief video—preferably in landscape mode—stating their name and country of origin and send it to the organizers. Participants are also urged to share their videos on social media to encourage others to join the campaign, which aims to highlight the Drupal community's global diversity. The deadline for submissions is April 24, 2024.

The Healthcare Summit at DrupalConPortland, scheduled for Thursday, May 9, is hailed as a must-attend event that will offer valuable insights for navigating the complexities of the healthcare industry in the digital age. Tickets are now available for Drupal Camping 2024 in Wolfsburg. Tickets, priced between 80 € and 100 €, offer access to four days of camping, chilling, swimming, barbecuing, and, of course, all things Drupal. 

There are Drupal events around the globe each week to keep Drupal enthusiasts engaged. A complete list of events for the week is available here.

Jeff Greenberg, a seasoned Drupal Architect at iFACTORY, recently sparked a discussion on LinkedIn about the apparent lack of a Drupal 10 module that enables users to subscribe by email to be notified when new content is posted. This query led to a broad response from various Drupal community experts, each offering insights or potential solutions. Dive into the discussion here.

The organizers of Splash Awards, Deutschland & Österreich, have announced the date for this year's Splash Awards 2024 Germany & Austria, set to take place on November 7 in Berlin. The Singapore Government Digital Services team has recently introduced Purple A11y, a comprehensive open-source accessibility testing tool designed to enhance website usability for persons with disabilities

The BAT API module, widely recognized for its robust booking and availability management capabilities, has officially launched support for Drupal 10. Baddy Sonja Breidert, CEO and Co-Founder of 1xINTERNET, recently discussed enhancements to the Frontend Editing module they designed to streamline the editor experience. 

In other news, Smile launched a new no-code Drupal profile named Sobki at DrupalCamp Rennes 2024 on March 27.

We acknowledge that there are more stories to share. However, due to selection constraints, we must pause further exploration for now.

To get timely updates, follow us on LinkedIn, Twitter and Facebook. Also, join us on Drupal Slack at #thedroptimes.

Thank you,
Sincerely
Alka Elizabeth
Sub-editor, The DropTimes.

Categories: FLOSS Project Planets

Real Python: Write Unit Tests for Your Python Code With ChatGPT

Planet Python - Mon, 2024-04-22 10:00

Having a good battery of tests for your code may be a requirement for many Python projects. In practice, writing unit tests is hard and can take a lot of time and effort. Therefore, some developers don’t like to write them. However, with large language models (LLMs) and tools like ChatGPT, you can quickly create robust and complete sets of tests for your Python code.

In Python, you can use multiple different tools for writing tests. The most commonly used tools include doctest, unittest, and pytest. ChatGPT can be of great help in writing tests with any of these tools.

In this tutorial, you’ll:

  • Prompt ChatGPT to create tests using doctest
  • Use ChatGPT to write unittest tests, fixtures, and suites
  • Craft ChatGPT prompts to write pytest tests and fixtures
  • Use alternative prompts for cases where the code isn’t available

To get the most out of this tutorial, you should set up a ChatGPT account and know the basics of interacting with this tool using prompt engineering. You should also know the basics of how to test code in Python.

Get Your Code: Click here to download the free sample code you’ll use to write unit tests for your Python code using ChatGPT.

Benefits of Using ChatGPT for Testing Python Code

Having good and up-to-date unit tests for your code is a must for any Python project. Poorly tested code or code without tests may end up being unreliable and weak. With automated tests, you can ensure and show that your code works correctly in different scenarios. So, having tests is important from the technical and commercial point of view.

Writing good tests is hard and can take a lot of time. That’s why some developers don’t like to write them at all. Using large language models (LLM) like ChatGPT can be a viable alternative for providing your projects and code with proper tests.

Note: You can use ChatGPT and other LLMs in many useful ways in the context of Python development. Check out the following resources for other use cases and useful insights:

Some of the benefits of using ChatGPT to write tests for your Python code include the following:

  • Efficiency and speed: It can generate unit tests based on specifications or code snippets. This possibility significantly reduces the time that you need to spend writing tests. So you can focus on writing application logic.
  • Coverage improvement: It can suggest tests for edge cases or scenarios that developers might not immediately consider. This way, you can improve your code’s test coverage.
  • Error reduction: It can reduce human error in writing repetitive or boilerplate test code.
  • Learning and onboarding: It can serve as an educational tool for developers who are new to testing frameworks or unfamiliar with best practices in unit testing. The generated tests can help developers learn about testing patterns, assertions, and ways to effectively write tests.

With ChatGPT, you can generate unit tests for your Python code in almost no time. However, you must note that even though the generated tests can look good, you should still review and possibly refine the generated tests.

Note: For this tutorial, you’ll use a free ChatGPT account that’s powered by the GPT-3.5 LLM. You can use this model for free with the default web interface by OpenAI. If you use a paid account with GPT-4, then your results might be more accurate and faster.

Additionally, you’ll use an individual chat thread for each major section in the tutorial. So you’ll use different threads for the doctest, unittest, and pytest sections.

Using a single chat thread to run all the examples in this tutorial may cause the chat to generate significantly different responses because of the past context, which includes previous prompts and responses.

In the following sections, you’ll learn the basics of using ChatGPT as an assistant for creating coherent unit tests for your Python projects using different test frameworks and libraries.

Writing doctest Tests With ChatGPT

Python’s doctest module provides a lightweight testing framework that you can use for test automation. It can read the test cases from your project’s documentation and your code’s docstrings. This framework comes with the Python interpreter, so you’ll have it at your disposal with any Python installation, which is great.

Note: To dive deeper into how to use the doctest module for testing your code, check out Python’s doctest: Document and Test Your Code at Once.

With doctest, you can write code that provides examples of how your code works, simulating REPL sessions. These examples work as documentation and also as test cases or unit tests. Each doctest test needs a statement or expression and an expected result.

You can use ChatGPT to help you out with writing doctest tests. First, you need some code to test. The following function tries to tackle the FizzBuzz challenge, where you return "fizz" for numbers divisible by three, "buzz" for those divisible by five, and "fizz buzz" for those divisible by both three and five.

Go ahead and create a fizzbuzz.py file and add the following code to it:

Python fizzbuzz.py def fizzbuzz(number): if number % 3 == 0: return "fizz" elif number % 5 == 0: return "buzz" elif number % 15 == 0: return "fizz buzz" else: return number Copied!

This function works okay for numbers divisible by 3 or 5. However, there is a slight issue with numbers that are divisible by both. Even though you know this, go ahead and start a new chat thread. Then, prompt ChatGPT to write doctest test for the function:

You: Write doctest tests for the following function:

Python def fizzbuzz(number): if number % 3 == 0: return "fizz" elif number % 5 == 0: return "buzz" elif number % 15 == 0: return "fizz buzz" else: return number Copied!

ChatGPT:

Certainly! The function you’ve provided implements a basic FizzBuzz algorithm but with a slight logical error. The check for divisibility by 15 should come before checks for 3 and 5, as every number divisible by 15 is also divisible by both 3 and 5, but your current order will never reach the "fizz buzz" case. Here’s a corrected version of your function with the logical order fixed, followed by doctest tests for it:

Python def fizzbuzz(number): """ Returns 'fizz' if number is divisible by 3, 'buzz' if number is divisible by 5, 'fizz buzz' if number is divisible by 15, and the number itself otherwise. >>> fizzbuzz(3) 'fizz' >>> fizzbuzz(5) 'buzz' >>> fizzbuzz(15) 'fizz buzz' >>> fizzbuzz(4) 4 >>> fizzbuzz(30) 'fizz buzz' >>> fizzbuzz(9) 'fizz' >>> fizzbuzz(10) 'buzz' >>> fizzbuzz(2) 2 """ if number % 15 == 0: return "fizz buzz" elif number % 3 == 0: return "fizz" elif number % 5 == 0: return "buzz" else: return number Copied!

To use these doctest tests, you’ll need to include them in the docstring of your function as shown above. Then, you can run the tests with the doctest module by adding the following to your script:

Python if __name__ == "__main__": import doctest doctest.testmod() Copied!

This code will automatically run the tests defined in the docstrings when you execute the Python file. Remember, the corrected order of conditions in the function ensures that numbers divisible by both 3 and 5 return "fizz buzz", which is crucial for the FizzBuzz logic.

Wow! That great! The chat not only wrote the doctest tests for you. It also fixed the issue, explained important concepts around doctest, and provided instructions on how to run the tests. Note that the tests cover both regular and edge cases, which is pretty convenient.

Read the full article at https://realpython.com/chatgpt-unit-tests-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 ]

Categories: FLOSS Project Planets

Bits from Debian: Debian Project Leader Election 2024, Andreas Tille elected.

Planet Debian - Mon, 2024-04-22 08:00

The voting period for the Debian Project Leader election has ended. Please join us in congratulating Andreas Tille as the new Debian Project Leader.

The new term for the project leader started on 2024-04-21.

369 of 1,010 Debian Developers voted using the Condorcet method.

More information about the results of the voting are available on the Debian Project Leader Elections 2024 page.

Many thanks all of our Developers for voting.

Categories: FLOSS Project Planets

Vincent Fourmond: QSoas version 3.3 is out

Planet Debian - Mon, 2024-04-22 06:50
Version 3.3 brings in new features, including reverse Laplace transforms and fits, pH fits, commands for picking points from a dataset, averaging points with the same X value, or perform singular value decomposition.

In addition to these new features, many previous commands were improved, like the addition of a bandcut filter in FFT filtering, better handling of the loading of files produced by QSoas itself, and a button to interrupt the processing of scripts.

There are a lot of other new features, improvements and so on, look for the full list there. About QSoas
QSoas is a powerful open source data analysis program that focuses on flexibility and powerful fitting capacities. It is released under the GNU General Public License. It is described in Fourmond, Anal. Chem., 2016, 88 (10), pp 5050–5052. Current version is 3.3. You can download for free its source code or precompiled versions for MacOS and Windows there. Alternatively, you can clone from the GitHub repository.
Categories: FLOSS Project Planets

Pages