Running dmypy as a systemd user service

未关闭
#16,941 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
停滞
技术栈
python

调研方向

从 dmypy start 和 dmypy daemon 入口点开始,然后跟踪 --status-file 和默认 .dmypy.json 位置的解析方式。将该行为与建议的 XDG_RUNTIME_DIR 或 /run/user/$UID/mypy 位置进行比较。当 systemd 用户服务可以在不使用 wrapper 的情况下运行 dmypy,同时现有的 status-file 行为仍然可用时,即视为完成。

由索引模型根据 Issue 内容生成。

描述

feature topic-daemon

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.

主要语言
Python
星标
20.6k
派生
3.3k
平均合并
1 天 18 小时
30 天内合并 PR
54

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

python/mypy 的其他 Issue

查看 python/mypy 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。