Skip to content

Commit 6b79bb1

Browse files
authored
Update bootstrap (#242)
* Update configure-pyright.sh * Update bootstrap
1 parent e2c4141 commit 6b79bb1

File tree

2 files changed

+36
-27
lines changed

2 files changed

+36
-27
lines changed

.trunk/configure-pyright.sh

+17-18
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,10 @@ venv_name=$(grep -m 1 venv pyproject.toml | tr -s ' ' | tr -d '"' | tr -d "'" |
77
# Check if pyrightconfig already exists.
88
if [[ ! -f pyrightconfig.json ]]; then
99

10-
if [[ -z ${venv_name} ]]; then
11-
echo "Using Poetry"
12-
poetry_env_info=$(poetry env info --path) >/dev/null 2>&1
13-
venv_path=${poetry_env_info%/*} # ABCDE
14-
venv_name=${poetry_env_info#*/} # 12345
15-
16-
# Generate the pyrightconfig.json file.
17-
json_string=$(jq -n \
18-
--arg v "${venv_name}" \
19-
--arg vp "${venv_path}" \
20-
'{venv: $v, venvPath: $vp} ')
21-
22-
echo "${json_string}" >pyrightconfig.json
23-
else
24-
echo "Using Pyenv"
25-
# Check if pyenv-pyright plugin is installed
10+
# Capture poetry environment path and check if it's empty.
11+
poetry_env_info=$(poetry env info --path 2>/dev/null || true)
12+
if [[ -z ${poetry_env_info} ]]; then
13+
# Check if pyenv is installed
2614
if ! command -v pyenv &>/dev/null; then
2715
echo "pyenv not installed. Please install pyenv..."
2816
exit 1
@@ -32,14 +20,26 @@ if [[ ! -f pyrightconfig.json ]]; then
3220
dir_path="${pyenv_root}"/plugins/pyenv-pyright
3321
if [[ ! -d ${dir_path} ]]; then
3422
# trunk-ignore(shellcheck/SC2312)
35-
if [[ -n $(ls -A "${dir_path}") ]]; then
23+
if [[ -z $(ls -A "${dir_path}") ]]; then
3624
git clone https://github.com/alefpereira/pyenv-pyright.git "${dir_path}"
3725
fi
3826
fi
3927

4028
# Generate the pyrightconfig.json file.
4129
pyenv pyright "${venv_name}"
4230
pyenv local "${venv_name}"
31+
else
32+
poetry_env_info=$(poetry env info --path 2>/dev/null || true)
33+
venv_path=$(dirname "${poetry_env_info}") # Get directory path
34+
venv_name=$(basename "${poetry_env_info}") # Get base name
35+
36+
# Generate the pyrightconfig.json file.
37+
json_string=$(jq -n \
38+
--arg v "${venv_name}" \
39+
--arg vp "${venv_path}" \
40+
'{venv: $v, venvPath: $vp} ')
41+
42+
echo "${json_string}" >pyrightconfig.json
4343
fi
4444
fi
4545

@@ -48,5 +48,4 @@ if ! jq -r --arg venv_name "${venv_name}" '. | select((.venv != $venv_name or .v
4848
echo "Failed to configure pyright to use environment '${venv_name}' as interpreter. Please check pyrightconfig.json..."
4949
exit 1
5050
fi
51-
echo "All done!"
5251
exit 0

Makefile

+19-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,3 @@
1-
bootstrap:
2-
-pyenv deactivate
3-
pyenv virtualenv 3.10 admin-backend
4-
pyenv activate admin-backend
5-
pip3 install poetry
6-
poetry install
7-
81
install_trunk:
92
$(eval trunk_installed=$(shell trunk --version > /dev/null 2>&1 ; echo $$? ))
103
ifneq (${trunk_installed},0)
@@ -16,8 +9,25 @@ uninstall_trunk:
169
sudo rm -if `which trunk`
1710
rm -ifr ${HOME}/.cache/trunk
1811

19-
git_hooks: install_trunk
20-
trunk actions run configure-pyright-with-pyenv
12+
create_env:
13+
# Copy .env
14+
cp .env.example .env
15+
16+
configure_pyright:
17+
trunk actions run configure-pyright
18+
19+
setup_with_pyenv: install_trunk create_env ## Sets up a local dev environment using Pyenv
20+
$(eval venv_name=$(shell grep 'venv =' pyproject.toml | cut -d '"' -f 2 ))
21+
if [ -n "$(venv_name)" ] && ! pyenv versions --bare | grep -q "^$(venv_name)$$"; then \
22+
$(eval python_version=$(shell grep 'python =' pyproject.toml | cut -d '"' -f 2 | sed 's/^\^//')) \
23+
$(eval pyenv_version=$(shell pyenv versions --bare | grep$(python_version) )) \
24+
pyenv virtualenv $(pyenv_version) $(venv_name); \
25+
fi
26+
@eval "$$(pyenv init -)" && \
27+
pyenv activate $(venv_name) && \
28+
poetry install
29+
30+
make configure_pyright
2131

2232
check:
2333
trunk fmt

0 commit comments

Comments
 (0)