• 1 Post
  • 18 Comments
Joined 9 months ago
cake
Cake day: March 1st, 2024

help-circle



  • To keep it simple

    testing and static type checking – catches all the bugs

    linting and formatters – so git diff isn’t pure noise showing trailing and unnecessary whitespace and collaborators won’t have to go back to correct things that coulda been automagically fixed.

    in code documentation – Can be extracted by Sphinx as part of the documentation process. Hint: interrogate is your friend.

    gh workflows – to have the test suite run against various py versions, os, and maybe architectures. Without which not even confident it runs well on your own machine let alone anywhere else.

    requirements.txt – is an output file. Where is requirements.in ??

    xz hacker sends his love

    Makefile – for people who like a ton of shell scripts in their Python packages. Up until realize that ya know which Python interpreter is being run, but can’t have any level of confidence about the shell interpreter. Cuz it’s a big unknown and unknowable. Gotta just take it on faith.





  • Thanks for the introduction to taskipy. Think if i need macros, Makefile is the way to go. Supports running targets in parallel and i like performing a check to ensure the virtual environment is activated or the command won’t run.

    .ONESHELL:
    .DEFAULT_GOAL := help
    SHELL := /bin/bash
    APP_NAME := logging_strict
    
    #virtual environment. If 0 issue warning
    #Not activated:0
    #activated: 1
    ifeq ($(VIRTUAL_ENV),)
    $(warning virtualenv not activated)
    is_venv =
    else
    is_venv = 1
    VENV_BIN := $(VIRTUAL_ENV)/bin
    VENV_BIN_PYTHON := python3
    PY_X_Y := $(shell $(VENV_BIN_PYTHON) -c 'import platform; t_ver = platform.python_version_tuple(); print(".".join(t_ver[:2]));')
    endif
    
    .PHONY: mypy
    mypy:					## Static type checker (in strict mode)
    ifeq ($(is_venv),1)
    	@$(VENV_BIN_PYTHON) -m mypy -p $(APP_NAME)
    endif
    
    

    make mypy without the virtualenv on will write a warning message why it’s not working!




  • If it’s worth sharing it’s worth to accompany the blog post with a repo containing unittests and tox.ini and pre-commit

    If that had been done, tox would give feedback that match switch support is py310+

    functools.singledispatch might be helpful to test multiple implementations

    Complaint about sharing code within a blog post is the quality is ALWAYS suspect.

    Lets leave crapoverflow.com style code examples in the past. Instead share tested code.





  • The multiple venv for different Python versions sounds exactly like what tox does

    Then setup a github action that does nightly builds. Which will catch issues caused by changes that only tested against one python version or on one platform

    py313 is a good version to test against cuz there were many modules removed or depreciated or APIs changed

    good luck. Hope some of my advice is helpful




  • logging_stricttoPythonA Guide to Python Lambda Functions
    link
    fedilink
    arrow-up
    1
    ·
    edit-2
    7 months ago

    BFF 1: Chuck is going to be so surprised. We’ve hired the best caterers, cosplay theme, fireworks, yard ales, twister themed blind laser tag, there will be balloons, ball pool, athletic challenge course, fabulous entertainment from top notch talent, show girls, the wine will flow like water

    BFF 2: Tell me you didn’t invite that grifter, mypy

    BFF 1: I … err … hum. Opps

    mypy enters the conversation

    Don’t use lambda use def function instead

    BFF 2: Man i hate that guy. Rains on our parade and sucks the fun out of the room (and this entire thread).