Skip to content

Commit

Permalink
build: use rye instead of poetry
Browse files Browse the repository at this point in the history
Test Plan:
- Install pacakge with rye
- Run tests
- Manually test pages

Reviewers: 

Pull Request: #17
  • Loading branch information
kod-kristoff authored Jan 18, 2024
1 parent 4ce793a commit a2e0379
Show file tree
Hide file tree
Showing 8 changed files with 168 additions and 623 deletions.
58 changes: 58 additions & 0 deletions .github/actions/setup-python-env/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: "setup-python-env"
description: "Composite action to setup the Python and rye environment."

inputs:
cache-extra-key:
required: false
description: "Extra cache key to use"
default: ""
python-version:
required: false
description: "The python version to use"
default: "3.11"
rye-version:
required: false
description: "The version of rye to use"
default: "latest"
outputs:
python-version:
description: "Python version used"
value: ${{ steps.set-python-version.outputs.python-version }}
rye-version:
description: "rye version used"
value: ${{ steps.set-rye-version.outputs.poetry-version }}

runs:
using: "composite"
steps:
- name: Install rye
id: setup-rye
uses: eifinger/setup-rye@f8f2ca26808cdffef0b77c4fddf4305a5e5b010a
with:
version: ${{ inputs.rye-version }}

- name: Pin python version
run: rye pin ${{ inputs.python-version }}
shell: bash

- name: Output python version
id: set-python-version
run: echo "python-version=$(rye run python -c 'import sys; print(".".join(map(str, sys.version_info[0:3])))')" >> $GITHUB_OUTPUT
shell: bash

- name: Output rye version
id: set-rye-version
run: echo "rye-version=${{ steps.setup-rye.outputs.rye-version}}" >> $GITHUB_OUTPUT
shell: bash

- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.set-python-version.outputs.python-version }}-${{ inputs.cache-extra-key }}-${{ hashFiles('**/pyproject.toml') }}

- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: rye sync --features=ci
shell: bash
132 changes: 24 additions & 108 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ name: CI

on:
push:
branches:
- main
tags:
- v*
pull_request: {}
pull_request:
merge_group:

permissions:
contents: read

env:
POETRY_VERSION: "1.3.1"
MINIMUM_PYTHON_VERSION: "3.10"

jobs:
Expand All @@ -32,43 +31,16 @@ jobs:
# check-out repo and set-up python
#----------------------------------------------
- name: Check out repository
uses: actions/checkout@v3
- name: Set up python ${{ env.MINIMUM_PYTHON_VERSION }}
id: setup-python
uses: actions/setup-python@v4
with:
python-version: ${{ env.MINIMUM_PYTHON_VERSION }}
#----------------------------------------------
# ----- install & configure poetry -----
uses: actions/checkout@v4

#----------------------------------------------
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: ${{ env.POETRY_VERSION }}
virtualenvs-create: true
virtualenvs-in-project: true
#----------------------------------------------
# load cached venv if cache exists
# ----- install & configure python & rye -----
#----------------------------------------------
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
- name: Set up the environment
uses: ./.github/actions/setup-python-env
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/pyproject.toml') }}-${{ hashFiles('.github/workflows/ci.yml')}}
#----------------------------------------------
# install dependencies if cache does not exist
#----------------------------------------------
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: |
poetry install --no-interaction --no-root
poetry install --only ci
#----------------------------------------------
# install your root project, if required
#----------------------------------------------
- name: Install library
run: poetry install --no-interaction
python-version: ${{ env.MINIMUM_PYTHON_VERSION }}

#----------------------------------------------
# Run matrix task
#----------------------------------------------
Expand All @@ -94,43 +66,15 @@ jobs:
# check-out repo and set-up python
#----------------------------------------------
- name: Check out repository
uses: actions/checkout@v3
- name: Set up python ${{ env.MINIMUM_PYTHON_VERSION }}
id: setup-python
uses: actions/setup-python@v4
with:
python-version: ${{ env.MINIMUM_PYTHON_VERSION }}
#----------------------------------------------
# ----- install & configure poetry -----
#----------------------------------------------
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: ${{ env.POETRY_VERSION }}
virtualenvs-create: true
virtualenvs-in-project: true
uses: actions/checkout@v4

#----------------------------------------------
# load cached venv if cache exists
# ----- install & configure python & rye -----
#----------------------------------------------
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
- name: Set up the environment
uses: ./.github/actions/setup-python-env
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/pyproject.toml') }}-${{ hashFiles('.github/workflows/ci.yml')}}
#----------------------------------------------
# install dependencies if cache does not exist
#----------------------------------------------
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: |
poetry install --no-interaction --no-root
poetry install --only ci
#----------------------------------------------
# install your root project, if required
#----------------------------------------------
- name: Install library
run: poetry install --no-interaction
python-version: ${{ env.MINIMUM_PYTHON_VERSION }}
#----------------------------------------------
# Run matrix task
#----------------------------------------------
Expand All @@ -156,43 +100,15 @@ jobs:
# check-out repo and set-up python
#----------------------------------------------
- name: Check out repository
uses: actions/checkout@v3
- name: Set up python ${{ env.MINIMUM_PYTHON_VERSION }}
id: setup-python
uses: actions/setup-python@v4
with:
python-version: ${{ env.MINIMUM_PYTHON_VERSION }}
uses: actions/checkout@v4

#----------------------------------------------
# ----- install & configure poetry -----
# ----- install & configure python & rye -----
#----------------------------------------------
- name: Install Poetry
uses: snok/install-poetry@v1
- name: Set up the environment
uses: ./.github/actions/setup-python-env
with:
version: ${{ env.POETRY_VERSION }}
virtualenvs-create: true
virtualenvs-in-project: true
#----------------------------------------------
# load cached venv if cache exists
#----------------------------------------------
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/pyproject.toml') }}-${{ hashFiles('.github/workflows/ci.yml')}}
#----------------------------------------------
# install dependencies if cache does not exist
#----------------------------------------------
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: |
poetry install --no-interaction --no-root
poetry install --only ci
#----------------------------------------------
# install your root project, if required
#----------------------------------------------
- name: Install library
run: poetry install --no-interaction
python-version: ${{ env.MINIMUM_PYTHON_VERSION }}
#----------------------------------------------
# Run matrix task
#----------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions Justfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
default: test

INVENV := if env_var_or_default('VIRTUAL_ENV', "") == "" { "poetry run" } else { "" }
INVENV := if env_var_or_default('VIRTUAL_ENV', "") == "" { "rye run" } else { "" }


alias dev := install-dev
# installs the project for development
install-dev:
poetry install
rye sync --no-lock

# installs the project for deployment
install:
poetry install --only main
rye sync --no-lock --no-dev

# setup CI environment
install-ci: install-dev
poetry install --only ci
rye sync --no-lock --features=ci


# lint all code
Expand Down
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
.default: help

ifeq (${VIRTUAL_ENV},)
INVENV = poetry run
INVENV = rye run
else
INVENV =
endif
Expand Down Expand Up @@ -36,14 +36,14 @@ help:

dev: install-dev
install-dev:
poetry install
rye sync --no-lock

install:
poetry install --only main --sync
rye sync --no-dev --no-lock

# setup CI environment
install-ci: install-dev
poetry install --only ci
rye sync --no-lock --features=ci

.PHONY: lint
lint:
Expand All @@ -63,8 +63,8 @@ type-check:

# build the project
build:
poetry build
rye build

serve-dev:
${INVENV} watchfiles "uvicorn --bind localhost:8000 app.views:app" app
${INVENV} watchfiles "gunicorn --chdir app --bind 'localhost:8000' app.views:app" app

Loading

0 comments on commit a2e0379

Please sign in to comment.