python / python/mypy

Running dmypy as a systemd user service

Offen
#16,941 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

feature topic-daemon
Vorherrschende Sprache
Python
Sterne
20.6k
Forks
3.3k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

Feature

Make dmypy look for either its status file or maybe even the socket in a well-known place.

As this well-known place I propose for Linux systems a directory /run/user/$UID/mypy (or the value of the environment variable XDG_RUNTIME_DIR). The name of status file would encode the path for which dmypy is running.

Pitch

mypy can be run as a daemon, which is currently manually started via dmypy start. It can already run in the foreground via dmypy daemon and I have started to use this to start the mypy daemon on login on my Linux system as a systemd user service as this moves the management of the lifecycle of the daemon to the service manager, that I already have running (as does the vast majority of Linux systems), so that I don't have to think about it anymore.

I do this via this service file in ~/.config/systemd/user/

# mypy@.service
[Unit]
Description=mypy daemon

[Service]
Type=simple
WorkingDirectory=%I
ExecStart=dmypy --status-file %t/mypy/%I.json daemon
RuntimeDirectory=mypy

which is instantiated via systemctl enable mypy@$(systemd-escape /path/to/my/project).service. The specifiers %I and %t expand to /path/to/my/project and the value of XDG_RUNTIME_DIR (by default /run/user/$UID). respectively. I then have a wrapper function for dmypy that sets --status-file to the appropriate value for my project directory (/run/user/$UID/mypy/$(systemd-escape $(git rev-parse --show-toplevel)).json to be specific).

I would like to streamline this setup, so that the wrapper is no longer necessary by having mypy look not only for .dmypy.json by default, but also check for the existence of the status file in the above described well-known location. This would allow e.g. for distributions packaging mypy to ship this or a similar service file to users and automatically restart the daemon on upgrades.

The feature itself is extensible. This directory could be used for the dmypy socket directly instead of giving it a random name in /tmp, but I have not yet looked into why this was designed as it is.

I guess a similar feature could be implemented for launchd on MacOS and on Windows, but I have no knowledge of these systems.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit den Einstiegspunkten dmypy start und dmypy daemon und verfolge anschließend, wie --status-file und der standardmäßige Speicherort .dmypy.json aufgelöst werden. Vergleiche dieses Verhalten mit dem vorgeschlagenen Speicherort XDG_RUNTIME_DIR oder /run/user/$UID/mypy. Das Ziel ist erreicht, wenn ein systemd-Benutzerdienst dmypy ohne Wrapper ausführen kann und das bestehende Verhalten für status-file weiterhin nutzbar bleibt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
cli, devops, operating-systems
Issue-Typ
Feature
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.