In the middle of the desert you can say anything you want
Evergreen topic (Day 841 - serhii.net dealt more with “data science projects”, 220105-1142 Order of directories inside a python project is about using ./src
and there’s also “put tests inside ./tests
in folder/file names that directly mirror the ones in the package”).
Problem: If you have a nested package that’s loosely coupled, where do you put random stuff that’s not python package code or tests?
Things I found or learned when looking for ideas:
README.rst
LICENSE
setup.py
requirements.txt
sample/__init__.py
sample/core.py
sample/helpers.py
docs/conf.py
docs/index.rst
tests/test_basic.py
tests/test_advanced.py
2.What is the best project structure for a Python application? - Stack Overflow - Really nice discussion and links, including to Jp Calderone 3. Filesystem structure of a Python project - Jp Calderone — LiveJournal It had this gem that I REALLY needed to hear:
Don’t:
- try to come up with magical hacks to make Python able to import your module or package without having the user add the directory containing it to their import path (either via PYTHONPATH or some other mechanism). You will not correctly handle all cases and users will get angry at you when your software doesn’t work in their environment.
In the documentation, found out that yield
is the recommended way to return stuff from fixtures.
Amongs other neat bits, any cleanup code after it will get executed when the fixture itself gets destroyed (based on scope).
pytest fixtures: explicit, modular, scalable — pytest documentation
If a pytest test running inside the debugger failed because of an exception, pycharm always stopped the process and printed the stack trace instead of letting me debug the exception when raised.
The setting in pycharm settings “drop into the debugger on failed test” fixed that. (And pdbpp
had nothing to do with the issue).
Since Docker is again part of my life, I’ll add things here as I google them.
docker build ./somedirectory
has that dir as build context.docker build -f ./somedirectory/Dockerfile
has the current directory as build context, and all siblings of somedirectory
are part of the context too.Relevant for COPY
that can work only on files in the current build context: Dockerfile reference | Docker Documentation
If the context is big it takes time. In my case I had a lot of stray virtualenvs that made it really big.
.dockerignore
helps:
Has to be in the root directory of the context.
Samples:
And things like .venv
or ./venv
are only relative to context root! **/.venv
Did that, context was still big.
dockerfile - Docker command/option to display or list the build context - Stack Overflow told me that my favourite ncdu
parses them nicely!
ncdu -X .dockerignore
Not the same but exactly what I wanted. Then I got the list of all weird environments I created by adding the missing ones, leading to this:
# Environments
**/.env
**/.venv
**/env
**/venv
**/ENV
**/venv_jupyter
**/build_venv
**/venv_torch
**/.install_venv
docker build . -t imagename:optionaltag
so you don’t have to copy the ID every time.Then you can just cycle between these two commands when developing:
docker build -t name .
docker run --rm -it -p 8888:8888 -v /home/sh/hsa/Data:/docker_vol name:latest
Things get nicely cached - which means installing tensorflow ideally would be above the lines in the Dockerfile that get changed often as part of the process above.
COPY
and slashesFrom the official docu:
<dest>
has a slash at the end it’s considered a directory.Matters when copying multiple things, or if it doesn’t exist.
WORKDIR
Tried
RUN cd whatever
RUN python3 -m pip install -r requirements.txt
Didn’t work. I needed WORKDIR
.
It works like cd
, if called sequentially each path is relative to the previous one.
Keyboard Shortcuts · telegramdesktop/tdesktop Wiki
Most interesting ones:
Mouse shortcuts:
I now have an easy 220614-0020 Linux toggle touchpad binding. Still not optimal.
The Internet told me about atareao/Touchpad-Indicator: An indicator for the touchpad, which also does basic settings, including disable touchpad when typing.
First thing it did is change some settings with speed/acceleration/… on open, touchpad behaves differently now.
The disable-touchpad-when-typing doesn’t work for me, but other options work. Looking deeper, it changes these options in the synaptics driver, that I can view/edit throughsynclient
.
synclient -l
to list them.
The actual option itself seems to do this:
synclient PalmDetect=1
which doesn’t work for me either.
Someone wrote a python script to do the touchpad disabling: How can I disable touchpad while typing? On Ubuntu 16.04 syndaemon isn’t working - Ask Ubuntu, but does it have to come to this?
A solution online was to disable one-finger-taps as clicks, but in my qtile setup the focus follows the mouse, even without clicks.
But actually actually actually - that’s a setting I’m not too attached to!
The hopefully final solution:
synclient TapButton1=1
config.py
: follow_mouse_focus = False
Unexpectedly, helped with a lot of random usability bits.
pytest-print · PyPI adds a printer
that when passed to the pytest itself can be used to print stuff, like steps, debug values maybe, etc.
Had a string generated like f"Something {filename} etc."
, needed to get filename
.
The parse · PyPI library does just that and is the opposite of python’s format
. And has also additional neat functions.
from libqtile.log_utils import logger
# ...
logger.warning("Disabling touchpad")
Finally got them! Or maybe wasn’t clear in older versions of the docu.
Lazy objects — Qtile 0.1.dev50+g2b2cd60.d20220610 documentation
Option 1:
from libqtile.config import Key
from libqtile.lazy import lazy
@lazy.function
def my_function(qtile):
...
keys = [
Key(
["mod1"], "k",
my_function
)
]
Option 2:
from libqtile.lazy import lazy
from libqtile.log_utils import logger
def multiply(qtile, value, multiplier=10):
logger.warning(f"Multiplication results: {value * multiplier}")
keys = [
Key(
["mod1"], "k",
lazy.function(multiply, 10, multiplier=2)
)
]
Or decorated version
from libqtile.config import Key
from libqtile.lazy import lazy
from libqtile.log_utils import logger
@lazy.function
def multiply(qtile, value, multiplier=10):
logger.warning(f"Multiplication results: {value * multiplier}")
keys = [
Key(
["mod1"], "k",
multiply(10, multiplier=2)
)
]