mirror of
https://github.com/esphome/esphome.git
synced 2026-09-12 07:47:33 +00:00
[core] Consolidate setup scripts into a cross-platform setup.py
script/setup and script/setup.bat implemented the same workflow and were kept in sync by hand, which had already drifted: the worktree hook fix in #18843 landed in the bash script only. Both are now thin wrappers around script/setup.py, so there is one implementation to maintain. The post-checkout hook also checks for a venv/Scripts layout before doing anything, so a branch switch on Windows can no longer clear a working virtual environment.
This commit is contained in:
@@ -1,20 +1,38 @@
|
||||
#!/bin/sh
|
||||
# Prepare the dev environment for a new checkout or worktree.
|
||||
#
|
||||
# Installed into the git hooks directory by script/setup. Deliberately tiny and
|
||||
# self-contained: it stays valid on branches where script/setup does not exist,
|
||||
# and simply does nothing there.
|
||||
# Installed into the git hooks directory by script/setup.py. Deliberately tiny
|
||||
# and self-contained: it stays valid on branches where the setup script does not
|
||||
# exist, and simply does nothing there.
|
||||
|
||||
# $3 is 1 for a branch checkout, 0 for a file checkout.
|
||||
[ "$3" = "1" ] || exit 0
|
||||
|
||||
top=$(git rev-parse --show-toplevel 2>/dev/null) || exit 0
|
||||
|
||||
# This also runs on ordinary branch switches, where there is nothing to do.
|
||||
# This also runs on ordinary branch switches, where there is nothing to do. Both
|
||||
# layouts are checked because git for Windows runs hooks under its own bundled
|
||||
# shell, where the environment lives in venv/Scripts rather than venv/bin.
|
||||
[ -x "$top/venv/bin/python" ] && exit 0
|
||||
[ -x "$top/script/setup" ] || exit 0
|
||||
[ -f "$top/venv/Scripts/python.exe" ] && exit 0
|
||||
|
||||
[ -f "$top/script/setup.py" ] || exit 0
|
||||
|
||||
# Clear VIRTUAL_ENV so a checkout made from a shell with an environment already
|
||||
# activated still gets its own, rather than having the active one repointed at
|
||||
# this working tree.
|
||||
exec env -u VIRTUAL_ENV "$top/script/setup"
|
||||
unset VIRTUAL_ENV
|
||||
|
||||
# The interpreter goes by different names across platforms, and on Windows
|
||||
# "python3" is often a stub that opens the app store instead of running
|
||||
# anything, so each candidate is tried before it is used. Doing nothing is the
|
||||
# right outcome when none of them work.
|
||||
try_setup() {
|
||||
"$@" -c "" >/dev/null 2>&1 || return 1
|
||||
exec "$@" "$top/script/setup.py"
|
||||
}
|
||||
|
||||
try_setup python3
|
||||
try_setup python
|
||||
try_setup py -3
|
||||
exit 0
|
||||
|
||||
Reference in New Issue
Block a user