Skip to content

June of 2022

Coding

  • New: Themes.

    Vuetify comes with two themes pre-installed, light and dark. To set the default theme of your application, use the defaultTheme option.

    File: src/plugins/vuetify.js

    import { createApp } from 'vue'
    import { createVuetify } from 'vuetify'
    
    export default createVuetify({
      theme: {
        defaultTheme: 'dark'
      }
    })
    

    Adding new themes is as easy as defining a new property in the theme.themes object. A theme is a collection of colors and options that change the overall look and feel of your application. One of these options designates the theme as being either a light or dark variation. This makes it possible for Vuetify to implement Material Design concepts such as elevated surfaces having a lighter overlay color the higher up they are.

    File: src/plugins/vuetify.js

    import { createApp } from 'vue'
    import { createVuetify, ThemeDefinition } from 'vuetify'
    
    export default createVuetify({
      theme: {
        defaultTheme: 'myCustomLightTheme',
        themes: {
          myCustomLightTheme: {
            dark: false,
            colors: {
              background: '#FFFFFF',
              surface: '#FFFFFF',
              primary: '#510560',
              'primary-darken-1': '#3700B3',
              secondary: '#03DAC6',
              'secondary-darken-1': '#018786',
              error: '#B00020',
              info: '#2196F3',
              success: '#4CAF50',
              warning: '#FB8C00',
            }
          }
        }
      }
    })
    

    To dynamically change theme during runtime.

    <template>
      <v-app>
        <v-btn @click="toggleTheme">toggle theme</v-btn>
        ...
      </v-app>
    </template>
    
    <script>
    import { useTheme } from 'vuetify'
    
    export default {
      setup () {
        const theme = useTheme()
    
        return {
          theme,
          toggleTheme: () => theme.global.name.value = theme.global.current.value.dark ? 'light' : 'dark'
        }
      }
    }
    </script>
    

    Most components support the theme prop. When used, a new context is created for that specific component and all of its children. In the following example, the v-btn uses the dark theme applied by its parent v-card.

    <template>
      <v-app>
        <v-card theme="dark">
          <!-- button uses dark theme -->
          <v-btn>foo</v-btn>
        </v-card>
      </v-app>
    </template>
    
  • New: Add more elements.

Generic Coding Practices

Use warnings to evolve your code

  • New: Change signature of method if you can.

    You can take the chance of the deprecation to change the signature of the function, so that if the user is using the old argument, it uses the old behaviour and gets the warning, and if it's using the new argument, it uses the new. The advantage of changing the signature is that you don't need to do another deprecation for the temporal argument flag.

Python

  • New: Add huey.

    huey is a little task queue for python.

  • New: Generators.

    Generator functions are a special kind of function that return a lazy iterator. These are objects that you can loop over like a list. However, unlike lists, lazy iterators do not store their contents in memory.

    An example would be an infinite sequence generator

    def infinite_sequence():
        num = 0
        while True:
            yield num
            num += 1
    

    You can use it as a list:

    for i in infinite_sequence():
    ...     print(i, end=" ")
    ...
    0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
    30 31 32 33 34 35 36 37 38 39 40 41 42
    [...]
    

    Instead of using a for loop, you can also call next() on the generator object directly. This is especially useful for testing a generator in the console:.

    >>> gen = infinite_sequence()
    >>> next(gen)
    0
    >>> next(gen)
    1
    >>> next(gen)
    2
    >>> next(gen)
    3
    

BeautifulSoup

  • New: Modifying the tree.

    PageElement.replace_with() removes a tag or string from the tree, and replaces it with the tag or string of your choice:

    markup = '<a href="http://example.com/">I linked to <i>example.com</i></a>'
    soup = BeautifulSoup(markup)
    a_tag = soup.a
    
    new_tag = soup.new_tag("b")
    new_tag.string = "example.net"
    a_tag.i.replace_with(new_tag)
    
    a_tag
    

    Sometimes it doesn't work. If it doesn't use:

    +a_tag.clear()
    a_tag.append(new_tag)
    

Boto3

Feedparser

  • New: Parse a feed from a string.

    >>> import feedparser
    >>> rawdata = """<rss version="2.0">
    <channel>
    <title>Sample Feed</title>
    </channel>
    </rss>"""
    >>> d = feedparser.parse(rawdata)
    >>> d['feed']['title']
    u'Sample Feed'
    

Python Snippets

  • New: Define a property of a class.

    If you're using Python 3.9 or above you can directly use the decorators:

    class G:
        @classmethod
        @property
        def __doc__(cls):
            return f'A doc for {cls.__name__!r}'
    

    If you're not, the solutions are not that good.

  • New: Fix SIM113 Use enumerate.

    Use enumerate to get a running number over an iterable.

    idx = 0
    for el in iterable:
        ...
        idx += 1
    
    for idx, el in enumerate(iterable):
        ...
    

Git

  • Improvement: Master to main branch change's controversy.

    The change is not free of controversy, for example in the PDM project some people are not sure that it's needed for many reasons. Let's see each of them:

    As we're not part of the deciding organisms of the collectives doing the changes, all we can use are their statements and discussions to guess what are the reasons behind their support of the change. Despite that some of them do use the argument that other communities do support the change to emphasize the need of the change, all of them mention that the main reason is that the term is offensive to some people.

    • I don't see an issue using the term master: If you relate to this statement it can be because you're not part of the communities that suffer the oppression tied to the term, and that makes you blind to the issue. It's a lesson I learned on my own skin throughout the years. There are thousand of situations, gestures, double meaning words and sentences that went unnoticed by me until I started discussing it with the people that are suffering them (women, racialized people, LGTBQI+, ...). Throughout my experience I've seen that the more privileged you are, the blinder you become. You can read more on privileged blindness here, here or here (I've skimmed through the articles, and are the first articles I've found, there are probably better references).

      I'm not saying that privileged people are not aware of the issues or that they can even raise them. We can do so and more we read, discuss and train ourselves, the better we'll detect them. All I'm saying is that a non privileged person will always detect more because they suffer them daily.

      I understand that for you there is no issue using the word master, there wasn't an issue for me either until I saw these projects doing the change, again I was blinded to the issue as I'm not suffering it. That's because change is not meant for us, as we're not triggered by it. The change is targeted to the people that do perceive that master is an offensive term. What we can do is empathize with them and follow this tiny tiny tiny gesture. It's the least we can do.

      Think of a term that triggers you, such as heil hitler, imagine that those words were being used to define the main branch of your code, and that everyday you sit in front of your computer you see them. You'll probably be reminded of the historic events, concepts, feelings that are tied to that term each time you see it, and being them quite negative it can slowly mine you. Therefore it's legit that you wouldn't want to be exposed to that negative effects.

    • I don't see who will benefit from this change: Probably the people that belongs to communities that are and have been under constant oppression for a very long time, in this case, specially the racialized ones which have suffered slavery.

      Sadly you will probably won't see many the affected people speak in these discussions, first because there are not that many, sadly the IT world is dominated by middle aged, economically comfortable, white, cis, hetero, males. Small changes like this are meant to foster diversity in the community by allowing them being more comfortable. Secondly because when they see these debates they move on as they are so fed up on teaching privileged people of their privileges. They not only have to suffer the oppression, we also put the burden on their shoulders to teach us.

    As and ending thought, if you see yourself being specially troubled by the change, having a discomfort feeling and strong reactions. In my experience these signs are characteristic of privileged people that feel that their privileges are being threatened, I've felt them myself countless times. When I feel it, +I usually do two things, fight them as strong as I can, or embrace them, analyze them, and go to the root of them. Depending on how much energy I have I go with the easy or the hard one. I'm not saying that it's you're case, but it could be.

DevOps

Infrastructure as Code

Helmfile

  • Correction: Tweak the update process to make it more resilient.

    • Check that all the helm deployments are well deployed with helm list -A | grep -v deployed
    • Change the context to the production cluster before running the production steps
  • New: Fix Cannot patch X field is immutable error.

    You may think that deleting the resource, usually a deployment or daemonset will fix it, but helmfile apply will end without any error, the resource won't be recreated , and if you do a helm list, the deployment will be marked as failed.

    The solution we've found is disabling the resource in the chart's values so that it's uninstalled an install it again.

    This can be a problem with the resources that have persistence. To patch it, edit the volume resource with kubectl edit pv -n namespace volume_pvc, change the persistentVolumeReclaimPolicy to Retain, apply the changes to uninstall, and when reinstalling configure the chart to use that volume (easier said than done).

Automating Processes

cruft

  • New: Use skip to avoid problems with .git.

    Since 2.10.0 you can add a skip category inside the .cruft.json, so that it doesn't check that directory:

    json { "template": "xxx", "commit": "xxx", "checkout": null, "context": { "cookiecutter": { ... } }, "directory": null, "skip": [ ".git" ] }