Skip to content

Commit

Permalink
Update bootstrap (#74)
Browse files Browse the repository at this point in the history
* Fix bootstrap

* Update pyright config script

* Fix entity counter bug on corpus

* Bump tp 3.8.26

* Use session instead of op

* Revert "Use session instead of op"

This reverts commit 4a9c49f.

* Revert "Fix entity counter bug on corpus"

This reverts commit 7e380ab.
  • Loading branch information
katybaulch authored Nov 18, 2024
1 parent 654ce6a commit 500b4f8
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 40 deletions.
34 changes: 0 additions & 34 deletions .trunk/configure-pyright-with-pyenv.sh

This file was deleted.

51 changes: 51 additions & 0 deletions .trunk/configure-pyright.sh
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
6 changes: 3 additions & 3 deletions .trunk/trunk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ actions:
- trunk-announce
enabled:
- trunk-check-pre-commit
- configure-pyright-with-pyenv
- configure-pyright
- trunk-fmt-pre-commit
- trunk-upgrade-available
definitions:
- id: configure-pyright-with-pyenv
run: source .trunk/configure-pyright-with-pyenv.sh
- id: configure-pyright
run: source .trunk/configure-pyright.sh
triggers:
- git_hooks: [pre-commit]
17 changes: 15 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,21 @@ uninstall_trunk:
sudo rm -if `which trunk`
rm -ifr ${HOME}/.cache/trunk

git_hooks: install_trunk
trunk actions run configure-pyright-with-pyenv
configure_pyright:
trunk actions run configure-pyright

setup_with_pyenv: install_trunk ## 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

make configure_pyright

check:
trunk fmt
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "db-client"
version = "3.8.25"
version = "3.8.26"
description = "All things to do with the datamodel and its storage. Including alembic migrations and datamodel code."
authors = ["CPR-dev-team <[email protected]>"]
license = "Apache-2.0"
Expand Down

0 comments on commit 500b4f8

Please sign in to comment.