FLOSS Project Planets

GNU Taler news: Cómo Emitir una Moneda Digital del Banco Central

GNU Planet! - Mon, 2021-10-11 18:00
Nos complace anunciar la publicación de nuestro artículo sobre"Cómo Emitir una Moneda Digital del Banco Central"que es un trabajo conjunto con el Banque nationale suisse.
Categories: FLOSS Project Planets

The Python Coding Blog: Python Readability, the PEP 8 Style Guide, and Learning Latin

Planet Python - Mon, 2021-10-11 15:38

Over the past couple of years, I’ve decided to start ticking things off my lifetime to-do list. We all have things “we’d like to do at some point when we have time.” I finally started carving time out of my days to do these things. In the past two years, I’ve learned touch-typing (that’s right, I had never learned this), started learning and playing chess, and now I’ve started learning Latin. Yes, Latin! “What’s Latin got to do with Python readability and the PEP 8 style guide?” I can hear you ask.

Latin is a fascinating language. As someone who loves languages—the human ones and the computer ones—I’ve always wished I had learned Latin when I was at school. One of the many things I found intriguing is that there were no punctuation marks or spaces in the original form of the language. thereaderhadtoinferthewordsandpauseswhenreading. The language was mostly spoken in those days, and only scholars tended to read and write.

Over time, the need to make the text more readable became important. Punctuation was one of the tools that made its way into languages to help with this. This made the text easier to read. But it also ensured that the author’s thoughts and ideas were conveyed more precisely.

You can read more about the mysterious origin of punctuation, but in this article, I’m more interested in the similar path that coding took in the past decades as programs become more complex, more widespread, and the need to make them more readable by human beings become more important.

Coding In The Past

In the earlier days of computer programming, there were only a few programmers. The complexity of computer code was limited primarily by the hardware restrictions on memory and speed of execution. Code was rarely shared and read by others, and teams working on software were small and often consisted of just one person.

Certain habits made sense in those early days and a bit later too. Making sure the code was short had some benefits in early computer programs. So did using short variable names, preferably one or two letters long. In the very early days, code had to be converted into punch cards that were then fed into the computer!

Even as punch cards were no longer needed, the desire to be efficient often led to using short variable names and keeping the code as short as possible. Who wants to type in more when you can get away with less?

The Shift Towards More Readable Code

However, as computers became faster and included more memory, programs decame more complex. Programming languages also evolved to better suit these new, longer, more complex programs. Teams become larger and collaboration more common. And the need to maintain code become just as important, if not more important, than writing the code in the first place.

This evolution naturally led to computer code becoming more readable by humans, too. Python is one of those “newer” languages and it has readability built into its DNA. Python’s syntax makes Python code more similar to plain English than code in most other languages. But Python goes further than this. It also encourages Python programmers to write neat, readable code. It does this mainly through its style guide, PEP 8, which I’ll talk about shortly.

Not every programmer is entirely on board. Old habits die hard. Some programmers still don’t place a high level of importance on how readable computer code is. And that’s fine. Defining what’s best when writing code is subjective. However, the trend seems to be going away from the old style of writing code towards writing code that’s more readable.

Indeed, you can see this trend within the Python codebase itself. Consider some “old” functions in Python, such as randint() from the random module. Perhaps, if this function were written today it would have been called random_integer. And the worst offenders in the standard library when it comes to readability, or lack of it, are the pair of functions in the datetime module called strptime and strftime. You can also find similarly named functions in the time module, which predate the ones in datetime, but most people will be familiar with those in the datetime module.

These “badly-named” functions are rare in Python. More modern libraries and newer additions to the language are unlikely to have such unreadable names.

Why Is Python Readability Important?

Have a look at the following Python program, read through it, and try to understand what it does:

p = [3.5, 2.1, 9.8, 7] q = [2, 3, 1, 2] i = [x * y for x, y in zip(p, q)] t = sum(i) print(t)

This program outputs 37.1. As long as you’re familiar with python list comprehensions and the zip() built-in function, you probably didn’t have too many issues understanding this program. However, look at the code below:

prices = [3.5, 2.1, 9.8, 7] quantities = [2, 3, 1, 2] income = [price * quantity for price, quantity in zip(prices, quantities)] total_income = sum(income) print(total_income)

There are no additional comments in this version of the code compared to the previous one. In fact, the two programs are identical except for the choices of variable names (and the use of blank lines to separate sections of code). The second version is easier to understand because it provides the context of what the code is doing. The author of the first program knew that p stands for prices and q for quantities, and so on. But this is not obvious for a reader of the program. The author may also struggle to remember what the one-letter variables stand for six months later!

The example above is a simple one, perhaps even trivial. However, this concept becomes so much more important as programs become longer and more complex.

Another Example

Let’s have a look at another example. Can you figure out what’s the purpose of the code in this function? This is the same example used in the Snippets section of The Python Coding Book chapter on functions:

def ins(n): return n.split()[0][0].upper() + ". " + n.split()[1][0].upper() + "."

Take your time to work through this one-liner and understand what it does.

Once you’re done, you can try it out with:

print(ins("william shakespeare")) # Output: W. S.

The function returns the initials from a name. Even the person who writes this code will need a bit of time to digest it again a few months later. And if you want to make changes to this function, you’ll need to spend a bit of time making sure you understand each part of this one-line function very well.

Now, consider the following function:

def get_initials(full_name): """ Get initials from a full name with two parts, such as 'John Smith' :param full_name: str, full name containing one first name and one last name, separated by a space :return: str with initials in the form 'J. S.' """ full_name = full_name.upper() first_name, last_name = full_name.split() # Assumes full_name has two words return f"{first_name[0]}. {last_name[0]}." print(get_initials("william shakespeare")) # Output: W. S.

This function is ten lines long, rather than just two. It performs the same task as the ins() function above. However, note that it’s easier to understand what this function does. The main reasons are:

  • The function name clearly describes what the function does. This wasn’t the case in the first function
  • The parameter name n in the function signature was replaced by full_name in the second version. Again, the use of a descriptive name makes all the difference when reading and understanding the code
  • The get_initials() function has a docstring explaining what the function does and what input parameter is needed. The docstring also clarifies what data the function returns
  • The logic of the algorithm is separated into steps:
  • First, full_name is replaced with the uppercase version of the string
  • Then the two separate parts of the full name are split using the split() string method
  • Finally, the function returns the initials using an f-string and the variables defined in the previous line

Different programmers will make different decisions on how to write the code to make it more readable. However, Python offers some help with this. This help comes in the form of PEP 8.

The PEP 8 Style Guide and Python Readability

PEPs are Python Enhancement Proposals which, when accepted, become a part of the language. Often PEPs deal with new aspects of the language or its syntax. However, PEP 8 deals with the recommended coding style when coding in Python.

The PEP 8 style guide is a pragmatic document that makes opinionated suggestions without being too dogmatic. It ensures consistency among Python programmers and is one of the tools that help to make Python code more readable. It’s not the only tool, though. You can still write code that scores poorly on readability while adhering to PEP 8 perfectly. So, learning PEP 8 is a necessary but not a sufficient requirement to writing readable code.

For those who are new to programming or Python, it’s well worth a quick browse through the PEP 8 document, and then you can return to it later for a more thorough read.

Some of the points in it may initially look bizarre, but they all have a purpose! Yes, even the blank line at the end of a script is there for a reason! If you’re using an IDE such as PyCharm, you’re likely to be warned by your editor when you break PEP 8 guidelines.

I’ll finish this section with a couple of quotes directly from PEP 8:

One of Guido [van Rossum, Python’s creator]’s key insights is that code is read much more often than it is written. The guidelines provided here are intended to improve the readability of code and make it consistent across the wide spectrum of Python code. As PEP 20 says, “Readability counts”.

PEP 8 — Style Guide for Python Code

But also:

However, know when to be inconsistent — sometimes style guide recommendations just aren’t applicable. When in doubt, use your best judgment.

PEP 8 — Style Guide for Python Code

If you want to dive a bit more into the ethos of Python, you can read The Zen of Python by Tim Peters, which you can get by typing import this into a Python console.

Final Words

Just as punctuation came into written languages to make them more readable, programming has been undergoing a similar transition in recent years. In the case of readability in coding, it’s not the punctuation marks that make the difference but the coding style.

In Python, readability counts, as it says in the Zen of Python. And this concept is valid in all of modern programming and not just in the Python world. Even if you’re only writing code for yourself, it’s good to get into the habit of making readability count when coding. Modern IDEs help. The desire to keep variable names very short, for example, is no longer an issue when your editor will autocomplete longer variable and function names that are more descriptive, and therefore, more readable.

Always remember that you’re making your code more readable, not just for the sake of others who may read your code in the future. You’re also making life easier for your future self when you return to your code to make changes or enhancements. Spending a bit more time to make your code readable will save you a lot of time in the future trying to figure out what you wrote in the past!

Further Reading
  • A version of the Python style guide written ‘for humans’ is available at pep8.org
  • The standalone Chapter: The White Room: Understanding Programming in The Python Coding Book, is not about readability, but it’s worth a read if you’re learning to code in Python and you’d like to truly understand what’s happening behind the scenes
Get the latest blog updates

No spam promise. You’ll get an email when a new blog post is published

The post Python Readability, the PEP 8 Style Guide, and Learning Latin appeared first on The Python Coding Book.

Categories: FLOSS Project Planets

Python Morsels: Reading files line-by-line

Planet Python - Mon, 2021-10-11 11:00
Transcript

Let's talk about reading files line-by-line in Python.

Looping over file objects to read line-by-line

Here we're calling the read method on a file object (for a file called diary980.md):

>>> filename = "diary980.md" >>> with open(filename) as diary_file: ... contents = diary_file.read() ... >>> contents 'Python Log -- Day 980\n\nToday I learned about metaclasses.\nMetaclasses are a class\'s class.\nMeaning every class is an instance of a metaclass.\nThe default metaclass is "type".\n\nClasses control features (like string representations) of all their instances.\nMetaclasses can control similar features for their classes.\n\nI doubt I\'ll ever need to make a metaclass, at least not for production code.\n'

When you call the read method on a file object, Python will read the entire file into memory all at once. But that could be a bad idea if you're working with a really big file.

There's another common way to process files in Python: you can loop over a file object to read it line-by-line:

>>> filename = "diary980.md" >>> with open(filename) as diary_file: ... n = 1 ... for line in diary_file: ... print(n, line) ... n += 1 ...

Here, we're printing out a number (counting upward) in each line in our file:

1 Python Log -- Day 980 2 3 Today I learned about metaclasses. 4 Metaclasses are a class's class. 5 Meaning every class is an instance of a metaclass. 6 The default metaclass is "type". 7 8 Classes control features (like string representations) of all their instances. 9 Metaclasses can control similar features for their classes. 10 11 I doubt I'll ever need to make a metaclass, at least not for production code.

Notice that as we print, Python isn't just printing out the line, but an extra blank line in between each line in our file. By default, Python's print function prints a newline character (\n) after whatever else that it prints (see the print function's end argument). But each of our lines also end in a newline character, because newline characters are what separate lines in a file:

>>> line "I doubt I'll ever need to make a metaclass, at least not for production code.\n" Getting rid of the newline character when reading line-by-line

So we either need to suppress the newline character that the print function prints out or we need to remove the newline characters from each line in our file as we print them out:

>>> filename = "diary980.md" >>> with open(filename) as diary_file: ... n = 1 ... for line in diary_file: ... print(n, line.rstrip("\n")) ... n += 1 ... 1 Python Log -- Day 980 2 3 Today I learned about metaclasses. 4 Metaclasses are a class's class. 5 Meaning every class is an instance of a metaclass. 6 The default metaclass is "type". 7 8 Classes control features (like string representations) of all their instances. 9 Metaclasses can control similar features for their classes. 10 11 I doubt I'll ever need to make a metaclass, at least not for production code.

We're using the string lstrip method here to "strip" newline characters from the left-hand side (the beginning) of each of our line strings just before print each line.

File objects are lazy iterables

File objects in Python are lazy iterables, which means we can treat them pretty much the same way as any other iterable.

So instead of manually counting upward, we could pass our file object to the built-in enumerate function. The enumerate function could then do the counting for us as we loop:

>>> filename = "diary980.md" >>> with open(filename) as diary_file: ... for n, line in enumerate(diary_file, start=1): ... print(n, line.rstrip('\n'))

We've remove two lines of code but we get the same output as before:

1 Python Log -- Day 980 2 3 Today I learned about metaclasses. 4 Metaclasses are a class's class. 5 Meaning every class is an instance of a metaclass. 6 The default metaclass is "type". 7 8 Classes control features (like string representations) of all their instances. 9 Metaclasses can control similar features for their classes. 10 11 I doubt I'll ever need to make a metaclass, at least not for production code. Summary

Files are lazy iterables, and as we loop over a file object, we'll get lines from that file.

When Python reads a file line-by-line, it doesn't store the whole file in memory all at once. Instead, it stores a small buffer of upcoming lines in that file, so it's more memory-efficient.

That means looping over files line-by-line is especially important if you're working with really big files.

Categories: FLOSS Project Planets

Real Python: Representing Rational Numbers With Python Fractions

Planet Python - Mon, 2021-10-11 10:00

The fractions module in Python is arguably one of the most underused elements of the standard library. Even though it may not be well-known, it’s a useful tool to have under your belt because it can help address the shortcomings of floating-point arithmetic in binary. That’s essential if you plan to work with financial data or if you require infinite precision for your calculations.

Towards the end of this tutorial, you’ll see a few hands-on examples where fractions are the most suitable and elegant choice. You’ll also learn about their weaknesses and how to make the best use of them along the way.

In this tutorial, you’ll learn how to:

  • Convert between decimal and fractional notation
  • Perform rational number arithmetic
  • Approximate irrational numbers
  • Represent fractions exactly with infinite precision
  • Know when to choose Fraction over Decimal or float

The majority of this tutorial goes over the fractions module, which in itself doesn’t require in-depth Python knowledge other than an understanding of its numeric types. However, you’ll be in a good place to work through all the code examples that follow if you’re familiar with more advanced concepts such as Python’s built-in collections module, itertools module, and generators. You should already be comfortable with these topics if you want to make the most out of this tutorial.

Free Bonus: 5 Thoughts On Python Mastery, a free course for Python developers that shows you the roadmap and the mindset you’ll need to take your Python skills to the next level.

Decimal vs Fractional Notation

Let’s take a walk down memory lane to bring back your school knowledge of numbers and avoid possible confusion. There are four concepts at play here:

  1. Types of numbers in mathematics
  2. Numeral systems
  3. Notations of numbers
  4. Numeric data types in Python

You’ll get a quick overview of each of these now to better understand the purpose of the Fraction data type in Python.

Classification of Numbers

If you don’t remember the classification of numbers, here’s a quick refresher:

Types of Numbers

There are many more types of numbers in mathematics, but these are the most relevant in day-to-day life. At the very top, you’ll find complex numbers that include imaginary and real numbers. Real numbers are, in turn, comprised of rational and irrational numbers. Finally, rational numbers contain integers and natural numbers.

Numeral Systems and Notations

There have been various systems of expressing numbers visually over the centuries. Today, most people use a positional numeral system based on Hindu-Arabic symbols. You can choose any base or radix for such a system. However, while people prefer the decimal system (base-10), computers work best in the binary system (base-2).

Within the decimal system itself, you can represent some numbers using alternative notations:

  • Decimal: 0.75
  • Fractional: ¾

Neither of these is better or more precise than the other. Expressing a number in decimal notation is perhaps more intuitive because it resembles a percentage. Comparing decimals is also more straightforward since they already have a common denominator—the base of the system. Finally, decimal numbers can communicate precision by keeping the trailing and leading zeros.

On the other hand, fractions are more convenient in performing symbolic algebra by hand, which is why they’re mainly used in school. But can you recall the last time you used fractions? If you can’t, then that’s because decimal notation is central in calculators and computers nowadays.

The fractional notation is typically associated with rational numbers only. After all, the very definition of a rational number states that you can express it as a quotient, or a fraction, of two integers as long as the denominator is nonzero. However, that’s not the whole story when you factor in infinite continued fractions that can approximate irrational numbers:

Irrational numbers always have a non-terminating and non-repeating decimal expansion. For example, the decimal expansion of pi (π) never runs out of digits that seem to have a random distribution. If you were to plot their histogram, then each digit would have a roughly similar frequency.

On the other hand, most rational numbers have a terminating decimal expansion. However, some can have an infinite recurring decimal expansion with one or more digits repeated over a period. The repeated digits are commonly denoted with an ellipsis (0.33333…) in the decimal notation. Regardless of their decimal expansion, rational numbers such as the number representing one-third always look elegant and compact in the fractional notation.

Numeric Data Types in Python Read the full article at https://realpython.com/python-fractions/ »

[ 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

Talking Drupal: Talking Drupal #315 - Wordpress vs Drupal Communities

Planet Drupal - Mon, 2021-10-11 09:45

Today we are talking about What The Drupal & WordPress communities could learn from one another with Tara King.

TalkingDrupal.com/315

Topics
  • What makes the WP community different?
  • Automattic influence on the community.
  • What could the Drupal community learn from the WP community?
  • Is there a lot of crossover in people in each community?
  • Do you think there is anything the WP community could learn from Drupal?
  • What are some struggles shared across the two communities?
  • How does platform sustainability differ between the two communities?
  • Why do you think so many more people gravitate towards WP?
Module of the Week Resources Hosts

Nic Laflin - www.nLighteneddevelopment.com @nicxvan John Picozzi - www.epam.com @johnpicozzi Tara King - @sparklingrobots

Categories: FLOSS Project Planets

Qt Sensors in Qt 6.2

Planet KDE - Mon, 2021-10-11 07:58

The Qt Sensors module provides access to sensor devices such as accelerometer and gyroscope. The logical architecture separates the concrete sensor types (“accelerometer”) from the platforms providing them (“Android”). This is illustrated by the Figure below:

Categories: FLOSS Project Planets

Second Beta for Krita 5.0

Planet KDE - Mon, 2021-10-11 05:23

A bit later than planned — after a year and a half of isolation meeting people spreads really bad colds — we’re releasing the second beta of Krita 5.0.0! The same warnings we gave with beta 1 still hold! There are still some showstoppers, but there we’re also over 700 fixes closer to the final release.

This release also includes a reworked GPU accelerated canvas: especially on HiDPI screens and on macOS Krita should perform much better.

The new splash screen, by Tyson Tan

These are the most important fixes since Beta 1:

  • Dmitry Kazakov and Ivan Yossi implemented a new way of uploading image textures to the GPU, improving performance when painting especially on macOS.
  • Michał Chojnowski fixed a crash in the gamut mask toolbar (BUG:441122)
  • Alvin Wong improved the translatability of Krita a lot, and worked really hard on the traditional Chinese translation.
  • Tyson Tan also improved the translatability of Krita a lot, and worked really hard on the simplified Chinese translation.
  • Amyspark fixed a problem with Krita resetting its settings after using the G’Mic-Qt plugin. G’Mic has also been updated to the latest version.
  • Deif Lou fixed several issues in the filter brush engine
  • Amyspark reworked the layer metadata framework (BUG:410341)
  • Agata Cacko fixed the color history button layout (BUG:434915)
  • Alan North fixed working with shared curves in the brush editor
  • Agata Cacko made it possible to load Adobe Style Library files that have styles with conflicting unique id’s
  • Alvin Wong fixed the zoom level in the floating canvas message (BUG:429569)
  • Tom Tom Tom fixed a bug in the calligraphy tool
  • Eoin O’Neill fixed a crash in the storyboard docker (BUG:441592)
  • Emmet O’Neill improved the usability of the storyboard docker (BUG:441593)
  • Sharaf Zaman fixed the welcome page on Android/ChromeOS
  • Matthias Wein fixed several issues with the docker titlebars
  • Alvin Wong fixed issues with placing popup windows (BUG:441935)
  • Alvin Wong fixed the touch pan gesture breaking when moving too quickly (BUG:441706)
  • Wolthera van Hövell tot Westerflier fixed loading KPL palettes defined using the Lab colorspace (BUG:441139)
  • Alvin Wong fixed a performance issue in the overview docker (BUG:442075)
  • Wolthera van Hövell tot Westerflier fixed a crash in the channels docker (BUG:442117)
  • Matthias Wein fixed a performance issue in the channels docker
  • Alvin Wong improved the usability of Krita in MDI mode (BUG:441644)
  • Halla Rempt fixed a crash in the task set docker if disabled actions were executed (BUG:441638)
  • Halla Rempt fixed a bug in Qt’s font database where having a space between angular brackets in a font name would break the parser (BUG:430220)
  • Agata Cacko fixed the previews of several assistant shapes (BUG:441212)
  • Alvin Wong fixed an issue using Windows Ink or Wintab, where double tablet events might be sent by broken drivers, and where the second event then would activate a mouse event (BUG:441687)
  • Matthias Wein fixed an issue where the dimensions for a new image were calculated wrongly (BUG:442124)
  • Sharaf Zaman fixed incremental backup saving on Android (BUG:427042)
  • Halla Rempt fixed rotating the system log
  • Halla Rempt changed the default setting for undo steps from 30 to 200
  • Agata Cacko fixed updating the preview for a gradient after editing
  • Amyspark fixed 32 bit floating point RGB in LittleCMS (BUG:442004, BUG:439947, BUG:437429)
  • Wolthera van Hövell tot Westerflier fixed creating separations from the alpha channel (BUG:434288)
  • Halla Rempt added a default shortcut for creating a vector layer: Shift-Insert (BUG:442585)
  • Wolthera van Hövell tot Westerflier implemented loading a gimp brush or gimp imagehose brush as a color image when editing the brush as a Krita image and fixed saving these brushes  (BUG:442316)
  • Wolthera van Hövell tot Westerflier added a reset option to the autobrush widget (BUG:437006)
  • Halla Rempt fixed an issue where when a shortcuts definition file was missing, menu entries would turn out blank (BUG:428453)
  • Eoin O’Neill implemented a new export user interface for the storyboard docker
  • Eoin O’Neill fixed using the move tool on animated masks (BUG:441974)
  • Eoin O’Neill fixed the crop tool not working properly on cloned animation frames. (BUG:441369)
  • Wolthera van Hövell tot Westerflier made it possible to add color labels and pin to the timeline for masks (BUG:438124)
  • Wolthera van Hövell tot Westerflier fixed the task set docker’s appearance (BUG:442185)
  • Alvin Wong fixed issues when using fractional display scaling
  • Sharaf Zaman fixed issues with changing the cursor icon on Android (BUG:431859)
  • Reinold Rojas enabled color sample preview for the color sampler tool (BUG:396490)
  • Reinold Rojas fixed a problem with Krita’s fullscreen mode in canvas-only mode (BUG:437932)
  • Halla Rempt added a tool preview option combobox to the transform tool so users can switch between fast and in-stack preview
  • Black Cat fixed applying font styles in the text tool (BUG:392343)
  • Agata Cacko fixed the preview of local assistants (BUG:442619)
  • Wolthera van Hövell tot Westerflier fixed several issues in the crop tool (BUG:442827, BUG:442959)
  • Wolthera van Hövell tot Westerflier fixed flattening a clones array: the flattened layer now is in the correct position (BUG:437431)
  • Wolthera van Hövell tot Westerflier fixed a possible crash with color adjustment filter masks (BUG:428349)
  • Agata Cacko fixed thumbnails for gradients when creating a resource bundle
  • Agata Cacko fixed several issues with resource tagging
  • Dmitry Kazakov improved the performance of masking brushes
  • Halla Rempt implemented saving user-defined tags
  • Dmitry Kazakov improved the performance of starting a new stroke when the current brush tip is very big (BUG:436731)
  • Sharaf Zaman improved the usability of the text tool when using Android or ChromeOS
  • Dmitry Kazakov fixed updating shapes that belong to a transformed group (BUG:443161)
  • Dmitry Kazakov fixed canvas updates in wraparound mode (BUG:442796)
  • Dmitry Kazakov fixed artifacts in the hue sensor of the color smudge brush engine (BUG:441755)
  • Matthias Wein fixed a memory leak in the create new image dialog
  • Halla Rempt fixed an initialization issue in the Notifier scripting class
  • Agata Cacko improved the performance of the perspective assistant

We will continue fixing issues that come in from testing the beta and the nightly builds so we can release a solid Krita 5. Please consider supporting Krita’s development through the development fund:

Download Windows

If you’re using the portable zip files, just open the zip file in Explorer and drag the folder somewhere convenient, then double-click on the krita icon in the folder. This will not impact an installed version of Krita, though it will share your settings and custom resources with your regular installed version of Krita. For reporting crashes, also get the debug symbols folder.

Note that we are not making 32 bits Windows builds anymore.

Linux

The separate gmic-qt appimage is no longer needed.

(If, for some reason, Firefox thinks it needs to load this as text: to download, right-click on the link.)

macOS

Note: if you use macOS Sierra or High Sierra, please check this video to learn how to enable starting developer-signed binaries, instead of just Apple Store binaries.

Android

The Android releases are made from the release tarball, so there are translations. We consider Krita on ChromeOS and Android still beta. There are many things that don’t work and other things that are impossible without a real keyboard.

Source code md5sum

For all downloads:

Key

The Linux appimage and the source .tar.gz and .tar.xz tarballs are signed. You can retrieve the public key here. The signatures are here (filenames ending in .sig).

Support Krita

Krita is a free and open source project. Please consider supporting the project with donations or by buying training videos! With your support, we can keep the core team working on Krita full-time.

The post Second Beta for Krita 5.0 appeared first on Krita.

Categories: FLOSS Project Planets

Quansight Labs Blog: Re-Engineering CI/CD pipelines for SciPy

Planet Python - Mon, 2021-10-11 03:51

In this blog post I talk about the projects and my work during my internship at Quansight Labs. My efforts were geared towards re-engineering CI/CD pipelines for SciPy to make them more efficient to use with GitHub Actions. I also talk about the milestones that I achieved, along with the associated learnings and improvements that I made.

This blog post would assume a basic understanding of CI/CD and GitHub Actions. I will also assume a basic understanding of Python and the SciPy ecosystem.

Re-Engineering CI/CD pipelines for SciPy

Read more… (14 min remaining to read)

Categories: FLOSS Project Planets

Mike Driscoll: PyDev of the Week: Pedro Pregueiro

Planet Python - Mon, 2021-10-11 01:05

This week we welcome Pedro Pregueiro (@pedropregueiro) as our PyDev of the Week! Pedro is an entrepreneur who has co-founded several companies. He is also an author and contributor at Real Python.

If you have some time, check out Pedro's website. You can also see what he's up to over on GitHub or connect with Pedro on LinkedIn.

Let's spend some time getting to know Pedro better!

Can you tell us a little about yourself (hobbies, education, etc):

Hi there, my name is Pedro!

I was born in Braga, Portugal   and followed, what I believe is, a typical journey for developers. I took a BSc in Computer Science, followed by a MSc in language engineering, but quickly dropped the masters to start working at a small local company. After a year, I moved to Lisbon, to join a consulting firm and work with a big telco.

Soon enough, I got bored with the big company world and decided to work with startups instead. I ended up working with a London company, moving to Oslo soon after, then back to Lisbon. Now, I live in Stockholm.

After a decade of being a coder in multiple companies and at different levels (junior, lead, CTO), I decided it was time to start my own company. I moved to Stockholm to join a startup accelerator, where I met my co-founders, with whom I'm building Satchel today.

In my free time, I dust off my guitar now and then, but mostly I play video games to relax and have fun. I also enjoy playing online chess, especially bullet in between tasks.

Why did you start using Python?

By chance, I believe. After the mandatory boring Java consultancy gigs, I started playing a lot with Perl and Ruby (RoR).

I was super into web scraping, regex, and that kind of stuff, and at the time used mostly Perl for that. Also, Perl was pretty neat to create simple scripts to automate boring tasks. On the other hand, for web stuff, I was using RoR because using Perl for a web page felt a bit crazy at the time.

Then, I started using Python more often, at a new job. To start, I used it for building APIs, but soon realized that with Django (and later Bottle or Flask) I could get pretty close to the RoR easy-to-use feeling, while still using a language I felt was broader and more capable.

I don't know how it happened, but soon after that I just started building everything in Python and fell in love with it. The simplicity, the speed, the potential, it was just great. I'm not coding as much today, due to being a founder, but every time I need to do any coding to automate a task, I pick Python.

What other programming languages do you know and which is your favorite?

Not sure I have a favourite. I've been using JS a lot lately, and even thought I wasn't a huge fan of it, I think it has definitely matured quite a bit in the past years and, with the right framework, I think it's a really pleasant language to work with today.

I studied Haskell at uni and every now and then I still dabble a little bit in it. Every time I hear of a startup that is using Haskell on their stack, I wonder how cool it'd be to join them and try using it on my day-to-day, as a professional instead of a hobbyist.

What projects are you working on now?

Right now I'm not coding as much. I'm working on my own company and, apart from a few automation scripts and a little bits of JS work, I mostly spend my time in between customer support, operations and whatever is new and burning on any given week.

Which Python libraries are your favorite (core or 3rd party)?

I'm a big fan of the collections core library. One of my managers in the past showed me how to use the defaultdict and I've loved it ever since, and use it quite often.

I also use requests a lot because some of the work I do requires a lot of integrations w/ different APIs. I also use arrow quite a bit, even though I feel like I should try one of the newer, cooler alternatives.

How did you get started with Real Python?

've been following Dan Bader for quite a few years, before I even heard of Real Python. I really liked his python tips newsletter, and always felt he was really good at summarizing things into simple and easy-to-digest bits.

As Real Python grew bigger, I started finding myself reading their articles more and more often. I clearly recall reading the logging and pep8 articles, and thinking they were awesome. I started sharing RP's article with my team all the time, and always felt like they were so well written and thorough.

At some point, I was freelancing and doing my own side project, and, since I had a bit more free time than usual, decided it was time to give back to the community. I wrote an application to RP saying that I've never been a technical writer, that I didn't even know if I was capable of doing it or even good at it, but that I really wanted to give back and, if possible, write for RP.

I got an article as a trial and that's how the story begun 🙂

I see you have co-founded several companies. Do you have advice for others who would like to strike out on their own?

There's lot of advice I can think of, but maybe the most important is to just do it (sorry nike). If you have an idea or project that you've been thinking of doing for a while, go ahead, start small and build something that either makes your life or other peoples' life easier.

After starting, my second most important advice is to launch it 🙂 Whatever you decide to build (or are building), put it in front of people. As a dev, I think it's sometimes too easy to just build more and more, add scope, more functionality, and delay the process of actually launching and putting things in front of users. I did that mistake myself a few times, and ended up with a bunch of little dead projects, that no one ever used.

So, in short, if you have an idea of something to build, build it and launch it asap. No matter how small or simple.

Side-note: feel free to reach out if you're working on a side-project or small co and wanna bounce some ideas or need some help. I'm always happy to help a fellow dev turned founder.

The post PyDev of the Week: Pedro Pregueiro appeared first on Mouse Vs Python.

Categories: FLOSS Project Planets

Morpht: Drupal personalization roundup (2014 - 2021)

Planet Drupal - Sun, 2021-10-10 22:39
A roundup of what has happened in Drupal personalization from 2014 to 2021 covering presentations, module releases and trends.
Categories: FLOSS Project Planets

Daniel Roy Greenfeld: Exploring the Bunch Class

Planet Python - Sun, 2021-10-10 20:00
Warning

Be careful with how you use bunch classes. It is possible to overwrite critical methods and attributes. Please don't use these in anything important or you may regret it.

Every play with a bunch class? I started using them early in my Python career, although it took four years to find out what they were called and better ways to code them.

Over time I became wary of them. In large and/or sophisticated projects you want predictable code, which explains the addition of the typing controls in Python. This goes against that direction, using the mutability of Python to expedite adding functionality while introducing potential instability.

Simple Unprotected Bunch Class class Bunch: """ Simple unprotected Python bunch class """ def __init__(self, **kwargs): self.__dict__.update(kwargs) bunch = Bunch(name='Exploring the bunch class') print(bunch.name)

Those who don't know about the Dict.update() method use this technique:

class VerboseBunch: """ Simple, verbose unprotected Python bunch class """ def __init__(self, **kwargs): for k, v in kwargs.items(): self.__dict__[k] = v

We aren't limited to __init__ methods, I've used a similar technique on update and save functions:

class Student: def __init__(self, **kwargs): self.__dict__.update(kwargs) self.grade_history = [] self.current_grade = None def update(self, **kwargs): """Bunch style update!""" self.__dict__.update(kwargs) def grade(self): # Determines grade of student r = httpx.get(GRADING_SERVICE_URL) self.update(current_grade=r.json()['grade']) self.grade_history.append(self.current_grade) student = Student(name='Daniel', age=8) studentgrad

Awesome, right?

Wrong, it's not awesome. In fact, there's a problem.

The Problem with Bunch Classes

Yes, bunch classes and generic update methods are fun, easy-to-understand, and take advantage of Python's mutability. Unfortunately the mutability that powers Bunch classes can cause havoc. Here's an example of a Bunch class failure:

student = Student(name='Daniel', age=8) # Overriding the grade() method by accident student.update(grade='A')

By updating the student's grade, we have overwritten the grade() method.

Simple protected Python bunch class

You can make protected Bunch classes, that in theory don't let pesky developers overwrite attributes, methods, and properties by accident during object instantiation.

class ProtectedBunch: """ Use this when you don't want to overwrite existing methods and data """ def __init__(self, **kwargs): for k, v in kwargs.items(): if not hasattr(self, k): setattr(self, k, v) bunch = ProtectedBunch(__str__=5) print(bunch)

Note that this only protects the __init__ method. It doesn't prevent any other method using the Bunch pattern. So overwriting the grade method is still possible if another method uses the bunch pattern.

Protected Python bunch class that throws errors

You can write bunch classes to raise errors when a key is in self.__dict__. This makes overrides explicitly fail.

class NotMutableAttribute(Exception): pass class ProtectedBunchWithException: """ Protected Python bunch class that throws errors Use this when you want to inform the coder they are touching protected code """ def __init__(self, **kwargs): for k, v in kwargs.items(): if hasattr(self, k): msg = f'{k} is not mutable' raise NotMutableAttribute(msg) else: setattr(self, k, v) bunch = ProtectedBunch(__str__=5) print(bunch)

Again, this doesn't block other methods using bunch-style dict updates from overriding methods and attributes.

Avoiding bugs caused by Bunch classes and bunch-style update methods

The best way to avoid the bugs generated by bunch classes or generic update methods that can overwrite critical methods and attributes is to simply avoid using them. If a project takes this route, I recommend putting it in the standards and conventions.

If you do go forward with bunch classes, don't use checks of k not in self.__dict__ to block overriding existing methods. Methods and class attributes do not exist in the instance __dict__.

Historical Note

This is a modern update of a blog post I wrote nearly ten years ago.

Categories: FLOSS Project Planets

Awesome Python Applications: SQLFluff

Planet Python - Sun, 2021-10-10 18:07

SQLFluff: Dialect-flexible and configurable SQL linter, designed with ELT applications in mind, with support for templating and autofixing errors.

Links:

Categories: FLOSS Project Planets

Unbroken!

Planet KDE - Sun, 2021-10-10 18:00

Calamares is a distro- and desktop-agnostic Linux installer. It’s my day job. It is named for squid, in particular battered squid rings from the Mediterranean sea, Calamares. There’s lots of ways to catch squid and octopuses. One way is to use an octopus trap, and in Japan these have a fairly distinctive shape and are called tako tsubo. There is a specific kind of heart spasm that causes the left ventricle to take on the shape of an octopus trap; this is generally Not Good. Here’s a cute illustration from a squid-lover.

It’s been an education! Thank you to well-wishers who took time to send me email. Things turned out much less serious, and much more squidly, than originally feared. I saw a lot of white coats this week, all competent and friendly and concerned about my mom’s well-being. Got her home in decent shape on friday with a fistful of new prescriptions and doctor’s orders for rest – so that’s what’s planned for her for now.

One of my neighbours is a neurologist, another a cardiological nurse, and they helped me out by repeating what I’d already heard at the hospital – which is useful because then I can say “mom, M says thing as well!” Consistency in messaging is a great help.

So I’m about 60% back on track, reserving the rest of my energy for keeping an eye out on mom. Look for me in merge requests, code reviews, and calamares releases everywhere.

After reading Other Minds by Peter Godfrey-Smith I think I won’t be eating squid and octopus quite so enthusiastically as I did in Greece, anymore.

Categories: FLOSS Project Planets

Łukasz Langa: Weekly Report, October 4 - 10

Planet Python - Sun, 2021-10-10 17:13

This week Pablo released Python 3.10.0. I was part of the “small” release party that ended up bringing a live audience of 400 people on YouTube, Guido included. It was a pleasure.

Categories: FLOSS Project Planets

QHtmlParser: writing an HTML parser with your brain switched off

Planet KDE - Sun, 2021-10-10 15:57

While developing MiTubo I've recently felt the need of parsing HTML pages: the first problem I wanted to solve was implementing proper RSS feed detection when the user entered a website URL into MiTubo's search box, so that MiTubo would parse the site's HTML, look for <link rel="alternate"...> URLs in the HEAD section, and let the user subscribe to any video feeds found there.

A quick search in the internet did not provide a clear answer: I found a Qt HTML parser in (stalled) development, and a few other C++ or C parsers (among the latters, lexbor is the most inspiring), but all of them seem to take the approach of parsing the HTML file into a DOM tree, while I was hoping to find a lightweight SAX-like parser. Pretty much like Python's html.parser.

Anyway, I don't remember how it happened, but at a certain point I found myself looking at html.parser source code, and I was surprised to see how compact it was (apart, of course, for the long list of character references for the HTML entities!). Upon a closer look, it also appeared that the code was not making much use of Python's dynamic typing, so, I thought, maybe I could give it a try to rewrite that into a Qt class. And a few hours later QHtmlParser was born.

As this post's title suggests, the process of rewriting html.parser with Qt was quite straightforward, and the nice thing about it is that I didn't have to spend any time reading the HTML standard or trying to figure out how to implement the parser: I just had to translate Python code into C++ code, and thanks to the nice API of QString (which in many ways resembles Python's — or vice versa) this was not too hard. I even left most of the original code comments untouched, and reused quite a few tests from the test suite.

It was time well spent. :-)

If you think you might need an HTML parser for your Qt application, you are welcome to give it a try. It's not a library, just a set of files that you can import into your project; for the time being I only have a build file for QBS, but I'll happily accept contributions to make it easier to use QHtmlParser with projects built using other build systems. You can see here the changes I made in MiTubo to start using it and detect RSS feed in a webpage's HEAD.

That's all for now. And in case you missed the link before, you can find QHtmlParser here.

Categories: FLOSS Project Planets

Golems GABB: Generating dummy Drupal content with Devel & more

Planet Drupal - Sun, 2021-10-10 15:44
Generating dummy Drupal content with Devel & more Editor Sun, 10/10/2021 - 22:44

CMSs like Drupal offer website owners unlimited opportunities to add as much content as they need and when they need it. However, at the stage of website building, when developers and themers are creating layouts, Views, and other things that shape the content structure, there is often no content ready yet.

How to test everything well in various scenarios without content available? Developers or QA engineers are not editors — generating nodes for testing purposes can be a tedious task for them. Luckily, it is possible to “invite” an instant content generation assistant to your website. Just a few clicks will be needed for filling the site with as many dummy entities as needed.

Categories: FLOSS Project Planets

Getting ready for KDE review — Kalendar devlog 18

Planet KDE - Sun, 2021-10-10 11:02
Good news! We have spent time this week preparing Kalendar for KDE Review — the two-week process that new KDE applications are subjected to before initial release. Don’t worry, we’re going to go over what that means in a second. We will also go through some of the refactoring, tweaking, and boatload bug-fixing that has …
Categories: FLOSS Project Planets

Ben Hutchings: Debian LTS work, September 2021

Planet Debian - Sun, 2021-10-10 08:03

In August I was assigned 12.75 hours of work by Freexian's Debian LTS initiative and carried over 18 hours from earlier months. I worked 2 hours and will carry over the remainder.

I started work on an update to the linux package, but did not make an upload yet.

Categories: FLOSS Project Planets

Norbert Preining: TeX Live contrib archive available via CTAN mirrors

Planet Debian - Sat, 2021-10-09 23:39

The TeX Live contrib repository has been for many years now a valuable source of packages that cannot enter proper TeX Live due to license restrictions etc. I took over maintenance of it in 2017 from Taco, and since then the repository has been available via my server. Since a few weeks, tlcontrib is now available via the CTAN mirror network, the Comprehensive TeX Archive Network.

Thanks to the team of CTAN who offered to mirror the tlcontrib, users can get much faster (and reliable) access via the mirror, by adding tlcontrib as additional repository source for tlmgr, either permanently via:

tlmgr repository add https://mirrors.ctan.org/systems/texlive/tlcontrib tlcontrib

or via a one-shot

tlmgr --repository https://mirrors.ctan.org/systems/texlive/tlcontrib install PACKAGE

The list of packages can be seen here, and includes besides others:

  • support for commercial fonts (lucida, garamond, …)
  • Noto condensed
  • various sets of programs around acrotex

(and much more!).

You can install all packages from the repository by installing the new collection-contrib.

Thanks to the whole CTAN team, and please switch your repositories to the CTAN mirror to get load of my server, thanks a lot!

Enjoy.

Categories: FLOSS Project Planets

Pages