Skip to content

Commit

Permalink
feat: use rye as project manager (#2359)
Browse files Browse the repository at this point in the history
* feat: use rye as project manager

* chore: change poetry to rye for scripts

* ci: avoid duplicate executions

* Remove unused check and rename check

* removed unused parallel tasks

* Remove strategy altogether

---------

Co-authored-by: Adrià Casajús <[email protected]>
  • Loading branch information
cquintana92 and acasajus authored Jan 16, 2025
1 parent 864b5d1 commit 20056a1
Show file tree
Hide file tree
Showing 11 changed files with 1,038 additions and 175 deletions.
57 changes: 29 additions & 28 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
name: Test and lint
name: SimpleLogin actions

on: [push, pull_request]
on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
lint:
Expand All @@ -9,35 +15,30 @@ jobs:
- name: Check out repo
uses: actions/checkout@v3

- name: Install poetry
run: pipx install poetry

- uses: actions/setup-python@v4
- name: "Install rye"
id: setup-rye
uses: eifinger/setup-rye@v4
with:
python-version: '3.10'
cache: 'poetry'
version: '0.43.0'
checksum: 'ca702c3d93fd6ec76a1a0efaaa605e10736ee79a0674d241aad1bc0fe26f7d80'
enable-cache: true

- name: Install OS dependencies
if: ${{ matrix.python-version }} == '3.10'
run: |
sudo apt update
sudo apt install -y libre2-dev libpq-dev
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction
if: steps.setup-rye.outputs.cache-hit != 'true'
run: rye sync --no-lock

- name: Check formatting & linting
run: |
poetry run pre-commit run --all-files
rye run pre-commit run --all-files
test:
runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python-version: ["3.10"]

# service containers to run with `postgres-job`
services:
Expand Down Expand Up @@ -69,24 +70,23 @@ jobs:
- name: Check out repo
uses: actions/checkout@v3

- name: Install poetry
run: pipx install poetry

- uses: actions/setup-python@v4
- name: Install rye
id: setup-rye
uses: eifinger/setup-rye@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'poetry'
version: '0.43.0'
checksum: 'ca702c3d93fd6ec76a1a0efaaa605e10736ee79a0674d241aad1bc0fe26f7d80'
enable-cache: true
cache-prefix: 'rye-cache'

- name: Install OS dependencies
if: ${{ matrix.python-version }} == '3.10'
run: |
sudo apt update
sudo apt install -y libre2-dev libpq-dev
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction

if: steps.setup-rye.outputs.cache-hit != 'true'
run: rye sync --no-lock

- name: Start Redis v6
uses: superchargejs/[email protected]
Expand All @@ -95,7 +95,8 @@ jobs:

- name: Run db migration
run: |
CONFIG=tests/test.env poetry run alembic upgrade head
rye install alembic
CONFIG=tests/test.env rye run alembic upgrade head
- name: Prepare version file
run: |
Expand All @@ -104,7 +105,7 @@ jobs:
- name: Test with pytest
run: |
poetry run pytest
rye run pytest
env:
GITHUB_ACTIONS_TEST: true

Expand Down
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.10.16
27 changes: 10 additions & 17 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ SimpleLogin backend consists of 2 main components:
## Install dependencies

The project requires:
- Python 3.10 and poetry to manage dependencies
- Python 3.10 and rye to manage dependencies
- Node v10 for front-end.
- Postgres 13+

First, install all dependencies by running the following command.
Feel free to use `virtualenv` or similar tools to isolate development environment.

```bash
poetry sync
rye sync
```

On Mac, sometimes you might need to install some other packages via `brew`:
Expand All @@ -55,7 +55,7 @@ brew install -s re2 pybind11
We use pre-commit to run all our linting and static analysis checks. Please run

```bash
poetry run pre-commit install
rye run pre-commit install
```

To install it in your development environment.
Expand Down Expand Up @@ -160,25 +160,25 @@ Here are the small sum-ups of the directory structures and their roles:
The code is formatted using [ruff](https://github.com/astral-sh/ruff), to format the code, simply run

```
poetry run ruff format .
rye run ruff format .
```

The code is also checked with `flake8`, make sure to run `flake8` before creating the pull request by

```bash
poetry run flake8
rye run flake8
```

For HTML templates, we use `djlint`. Before creating a pull request, please run

```bash
poetry run djlint --check templates
rye run djlint --check templates
```

If some files aren't properly formatted, you can format all files with

```bash
poetry run djlint --reformat .
rye run djlint --reformat .
```

## Test sending email
Expand Down Expand Up @@ -236,18 +236,11 @@ There are several ways to setup Python and manage the project dependencies on Ma
# we haven't managed to make python 3.12 work
brew install python3.10

# make sure to update the PATH so python, pip point to Python3
# for us it can be done by adding "export PATH=/opt/homebrew/opt/[email protected]/libexec/bin:$PATH" to .zprofile
# Install rye using the official installation script, found on https://rye.astral.sh/guide/installation/

# Although pipx is the recommended way to install poetry,
# install pipx via brew will automatically install python 3.12
# and poetry will then use python 3.12
# so we recommend using poetry this way instead
curl -sSL https://install.python-poetry.org | python3 -

poetry install
# Install the dependencies
rye sync

# activate the virtualenv and you should be good to go!
source .venv/bin/activate

```
50 changes: 26 additions & 24 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,45 @@ WORKDIR /code
COPY ./static/package*.json /code/static/
RUN cd /code/static && npm ci

# Main image
FROM python:3.10
FROM --platform=linux/amd64 ubuntu:22.04

ARG RYE_VERSION="0.43.0"
ARG RYE_HASH="ca702c3d93fd6ec76a1a0efaaa605e10736ee79a0674d241aad1bc0fe26f7d80"

# Keeps Python from generating .pyc files in the container
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONDONTWRITEBYTECODE=1
# Turns off buffering for easier container logging
ENV PYTHONUNBUFFERED 1
ENV PYTHONUNBUFFERED=1

# Add poetry to PATH
ENV PATH="${PATH}:/root/.local/bin"

WORKDIR /code

# Copy poetry files
COPY poetry.lock pyproject.toml ./

# Install and setup poetry
RUN pip install -U pip \
&& apt-get update \
&& apt install -y curl netcat-traditional gcc python3-dev gnupg git libre2-dev cmake ninja-build\
&& curl -sSL https://install.python-poetry.org | python3 - \
# Remove curl and netcat from the image
&& apt-get purge -y curl netcat-traditional \
# Run poetry
&& poetry config virtualenvs.create false \
&& poetry install --no-interaction --no-ansi --no-root \
# Clear apt cache \
&& apt-get purge -y libre2-dev cmake ninja-build\
# Copy dependency files
COPY pyproject.toml requirements.lock requirements-dev.lock .python-version ./

# Install deps
RUN apt-get update \
&& apt-get install -y curl netcat-traditional gcc python3-dev gnupg git libre2-dev build-essential pkg-config cmake ninja-build bash clang \
&& curl -sSL "https://github.com/astral-sh/rye/releases/download/${RYE_VERSION}/rye-x86_64-linux.gz" > rye.gz \
&& echo "${RYE_HASH} rye.gz" | sha256sum -c - \
&& gunzip rye.gz \
&& chmod +x rye \
&& mv rye /usr/bin/rye \
&& rye toolchain fetch `cat .python-version` \
&& rye sync --no-lock --no-dev \
&& apt-get autoremove -y \
&& apt-get purge -y curl netcat-traditional build-essential pkg-config cmake ninja-build python3-dev clang\
&& apt-get autoremove -y \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# Copy code
COPY . .

# copy npm packages
COPY --from=npm /code /code

# copy everything else into /code
COPY . .

ENV PATH="/code/.venv/bin:$PATH"
EXPOSE 7777

#gunicorn wsgi:app -b 0.0.0.0:7777 -w 2 --timeout 15 --log-level DEBUG
Expand Down
Loading

0 comments on commit 20056a1

Please sign in to comment.