-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bootstrapping & separate by environment (#419)
* Fix bootstrap for pyenv * Update trunk pyright config action * Get python version from pyproject file
- Loading branch information
1 parent
f1b782c
commit 5b1a84b
Showing
4 changed files
with
82 additions
and
65 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#! /usr/bin/env bash | ||
set -e | ||
|
||
# Get the name of the expected venv for this repo from the pyproject.toml file. | ||
venv_name=$(grep -m 1 venv pyproject.toml | tr -s ' ' | tr -d '"' | tr -d "'" | cut -d' ' -f3) || true | ||
|
||
# Check if pyrightconfig already exists. | ||
if [[ ! -f pyrightconfig.json ]]; then | ||
|
||
# Capture poetry environment path and check if it's empty. | ||
poetry_env_info=$(poetry env info --path 2>/dev/null || true) | ||
if [[ -z ${poetry_env_info} ]]; then | ||
# Check if pyenv is installed | ||
if ! command -v pyenv &>/dev/null; then | ||
echo "pyenv not installed. Please install pyenv..." | ||
exit 1 | ||
fi | ||
|
||
pyenv_root=$(pyenv root) | ||
dir_path="${pyenv_root}"/plugins/pyenv-pyright | ||
if [[ ! -d ${dir_path} ]]; then | ||
# trunk-ignore(shellcheck/SC2312) | ||
if [[ -z $(ls -A "${dir_path}") ]]; then | ||
git clone https://github.com/alefpereira/pyenv-pyright.git "${dir_path}" | ||
fi | ||
fi | ||
|
||
# Generate the pyrightconfig.json file. | ||
pyenv pyright "${venv_name}" | ||
pyenv local "${venv_name}" | ||
else | ||
poetry_env_info=$(poetry env info --path 2>/dev/null || true) | ||
venv_path=$(dirname "${poetry_env_info}") # Get directory path | ||
venv_name=$(basename "${poetry_env_info}") # Get base name | ||
|
||
# Generate the pyrightconfig.json file. | ||
json_string=$(jq -n \ | ||
--arg v "${venv_name}" \ | ||
--arg vp "${venv_path}" \ | ||
'{venv: $v, venvPath: $vp} ') | ||
|
||
echo "${json_string}" >pyrightconfig.json | ||
fi | ||
fi | ||
|
||
# Check whether required keys are present in pyrightconfig.json. | ||
if ! jq -r --arg venv_name "${venv_name}" '. | select((.venv != $venv_name or .venv == "") and (.venvPath == null or .venvPath == ""))' pyrightconfig.json >/dev/null 2>&1; then | ||
echo "Failed to configure pyright to use environment '${venv_name}' as interpreter. Please check pyrightconfig.json..." | ||
exit 1 | ||
fi | ||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,42 @@ | ||
# definitions for local development | ||
# Definitions for local development | ||
|
||
poetry_environment: create_venv | ||
poetry install | ||
|
||
check_dev_environment: | ||
ifneq (,$(wildcard ./.env)) | ||
echo "Dev environment already configured." | ||
exit 1 | ||
install_trunk: | ||
$(eval trunk_installed=$(shell trunk --version > /dev/null 2>&1 ; echo $$? )) | ||
ifneq (${trunk_installed},0) | ||
$(eval OS_NAME=$(shell uname -s | tr A-Z a-z)) | ||
curl https://get.trunk.io -fsSL | bash | ||
endif | ||
|
||
configure_pyright: | ||
trunk actions run configure-pyright-with-pyenv | ||
uninstall_trunk: | ||
sudo rm -if `which trunk` | ||
rm -ifr ${HOME}/.cache/trunk | ||
|
||
dev_install: install_trunk check_dev_environment | ||
# Sets up a local dev environment | ||
configure_pyright: | ||
trunk actions run configure-pyright | ||
|
||
create_env: | ||
# Copy .env | ||
cp .env.example .env | ||
|
||
setup: install_trunk create_env ## Sets up a local dev environment using Poetry | ||
# Install pip | ||
pip install --upgrade pip | ||
# Install poetry | ||
|
||
# Install poetry & dependencies | ||
pip install "poetry==1.8.1" | ||
poetry install | ||
|
||
make poetry_environment | ||
make configure_pyright | ||
|
||
create_venv: | ||
-pyenv deactivate | ||
pyenv virtualenv 3.10 backend | ||
pyenv activate backend | ||
|
||
install_trunk: | ||
$(eval trunk_installed=$(shell trunk --version > /dev/null 2>&1 ; echo $$? )) | ||
ifneq (${trunk_installed},0) | ||
$(eval OS_NAME=$(shell uname -s | tr A-Z a-z)) | ||
curl https://get.trunk.io -fsSL | bash | ||
endif | ||
setup_with_pyenv: install_trunk create_env ## Sets up a local dev environment using Pyenv | ||
$(eval venv_name=$(shell grep 'venv =' pyproject.toml | cut -d '"' -f 2 )) | ||
if [ -n "$(venv_name)" ] && ! pyenv versions --bare | grep -q "^$(venv_name)$$"; then \ | ||
$(eval python_version=$(shell grep 'python =' pyproject.toml | cut -d '"' -f 2 | sed 's/^\^//')) \ | ||
$(eval pyenv_version=$(shell pyenv versions --bare | grep$(python_version) )) \ | ||
pyenv virtualenv $(pyenv_version) $(venv_name); \ | ||
fi | ||
@eval "$$(pyenv init -)" && \ | ||
pyenv activate $(venv_name) && \ | ||
poetry install | ||
|
||
uninstall_trunk: | ||
sudo rm -if `which trunk` | ||
rm -ifr ${HOME}/.cache/trunk | ||
make configure_pyright |