# serhii.net

In the middle of the desert you can say anything you want

## Reminder of why people use IDEs

Was unhappy about the order of suggestions for completion in Pycharm, more current stuff I can remember than arguments to a function I don’t.

Started looking for ways to order them, but then realized that I ACTUALLY want documentation for the thing under the cursor - that I have in vim/jedi and use but somehow not in pycharm.

1. <Ctrl-Shift-I> does this “Quick definition”
2. The “Ctrl-click” “go to source” bit - if you don’t click but just hover you also get a tooltip.

“View -> Quick type definition” exists too! Can be bound to a key, but available though the menu.

That menu has A LOT of stuff that is going to be transformative for the way I code. Describing here in full to remember it, it’s worth it.

My understanding is:

• “Quick definition”: short “what” and the closest “where”
• short “what”: “it’s a function: def ou()..”, “It’s a variable the function got through this part of the signature: a: str,
• <C-S-i> by default
• “Quick documentation” - a bit of everything
• signature, docstring, everything I usually need
• <Alt-K> for me, default <Ctrl-P>,
• if pressed twice opens a separate static window that shows the documentation of everything under the cursor as it moves!
• “Type info” - “it’s a str!”
• Tells you the type information - prolly type hints but not necessarily
• <Alt-P> for me, default <Ctrl-Shift-P>
• “Quick type definition”: Function or classes signatures
• This thing is a duck. Ducks are birds that ….. If the duck is a str - well now I know that a str has a long definition. No default shortcut.
• “Context info” - info about current thing from off-screen
• <Alt-q>
• First the name of the function being edited, then the name of the class it’s in, etc.
• Repeat calls make it go higher

## Changes to my shortcuts

• <Alt-K> is now quick documentation
• <Alt-P> is now type info

Onwards!

• ### Day 1281 (04 Jul 2022)

A (DatasetInfo) object contains dataset metadata like version etc.

## Option1 - subclass DatasetBuilder

Build and load touches the topic and suggests subclassing BuilderConfig, it’s the class that then is used by the DatasetBulider.

## Option2 - you can subclass the Dataset

Fine-tuning with custom datasets — transformers 3.2.0 documentation

Example shown, not for this problem, and I don’t really like it but whatever.

## The best solution

Ended up just not adding metadata, I basically needed things that can be recovered anyway from a Features object with ClassLabels.

No easy support for custom metadata is really strange to me - sounds like something quite useful to many “Dataset created with version XX of converter program” and I see no reason why HF doesn’t do this.

Strong intuitive feeling that I’m misunderstanding the logic on some level and the answer I need is closer in spirit to “why would you want to add custom attributes to X, you could just ….”

Does everyone use separate key/values in the dataset itself or something?

• ### Day 1269 (22 Jun 2022)

#### Directory structure for python research-y projects

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:

1. Structuring Your Project — The Hitchhiker’s Guide to Python Suggests this structure and describes it well:
README.rst
setup.py
requirements.txt
sample/__init__.py
sample/core.py
sample/helpers.py
docs/conf.py
docs/index.rst
tests/test_basic.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.

#### Python unpacking operator to get list of dictionary keys from dict_keys

The * operator works to get a list from dictionary keys!

• my_dict.keys() returns a dict_keys object.
• [*my_dict.keys()] returns the keys as list of str
• list(..) would do the same but in a more readable way :)

Anyway filling this under “cool stuff I won’t ever use”

• ### Day 1268 (21 Jun 2022)

#### Pytest fixtures that yield instead of return for better cleanup code

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

#### Pycharm drop into the debugger on failed tests

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).

• ### Day 1267 (20 Jun 2022)

Since Docker is again part of my life, I’ll add things here as I google them.

## Building

### Contexts

• 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

### .dockerignore

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

#### Listing context after .dockerignore

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

• 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.

## Dockerfile commands

### COPY and slashes

From the official docu:

• If <dest> has a slash at the end it’s considered a directory.
• If it doesn’t - it’s a regular file

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.

• ### Day 1266 (19 Jun 2022)

#### Telegram Desktop official bindings keyboard shortcuts

Keyboard Shortcuts · telegramdesktop/tdesktop Wiki

Most interesting ones:

• Move to the Chat Below: Ctrl + Tab; Ctrl + PageDown; Alt + ↓
• Move to the Chat Above: Ctrl + Shift + Tab; Ctrl + PageUp; Alt + ↑
• Move to the folder below: Ctrl + Shift + ↓
• Jump directly to the folder: Ctrl + 1; Ctrl + 2; Ctrl + 3; Ctrl + 4; Ctrl + 5; Ctrl + 6; Ctrl + 7
• Reply to a Message: Ctrl + ↑; Ctrl + ↓
• Search Contact: Ctrl + J
• Create Link: Ctrl + K

Mouse shortcuts:

• Info about Messages: Hover the timestamp
• Forward a message to a chat: Drag the message to a chat in the list

#### Disable mouse while typing blues part N

I now have an easy 220614-0020 Linux toggle touchpad binding. Still not optimal.

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.

## Python script

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!

## Disable one-tap-click and don’t focus on mouse hover

The hopefully final solution:

1. synclient TapButton1=1
2. Added this to config.py: follow_mouse_focus = False

Unexpectedly, helped with a lot of random usability bits.

• ### Day 1265 (18 Jun 2022)

#### Python parse library that's the opposite of formatted strings

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.