VSCodeのカスタムタスクを用いて、PyInstallerで実行ファイルを作るときにバージョンを含んだファイル名を自動でつける。
git tagからverを生成します。(git describe)
Windowsでの環境ごとのpath指定があまりきれいではありません。Anaconda+conda環境が前提なので、そのほか環境ではうまく動かないかもしれません。
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "Run Pyinstaller",
"type": "shell",
"command": "./script/pyinstaller.sh",
"windows": {
"command": ".\\script\\pyinstaller.cmd ${config:python.pythonPath}"
},
"group": "build",
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": true,
"clear": false
}
}
]
}
script/pyinstaller.sh
# !/bin/sh
ver=`git describe --tags`
set -x
pyinstaller --onefile -n EXENAME_$ver main.py
script/pyinstaller.cmd
@for /f "usebackq tokens=*" %%i in (`git describe --tags`) do @set VER=%%i
%1\..\Scripts\pyinstaller --onefile -n EXENAME_%VER% main.py