Skip to content

Commit

Permalink
ci: fix dependencies and pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
thearchitector committed Nov 26, 2023
1 parent 89f8b1c commit 70fa90b
Show file tree
Hide file tree
Showing 10 changed files with 514 additions and 29 deletions.
3 changes: 0 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
*
!Dockerfile
!.dockerignore
!casbin_tortoise_adapter
!tests
!pdm.lock
!pyproject.toml
!README.md
14 changes: 8 additions & 6 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,21 @@ jobs:
POSTGRES_PASSWORD: "password"
POSTGRES_DB: "casbin_rule"
options: >-
--health-cmd "pg_isready"
--health-cmd "pg_isready -U postgres"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4
- name: Set up PDM
uses: pdm-project/setup-pdm@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: true
cache: "pip"
- name: Install dependencies
run: pdm install -G :all
run: pip install -r requirements.txt
- name: Run tests
run: pdm run pytest
run: pytest
env:
POSTGRES_HOST: "localhost"
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
!.vscode/settings.json
.pdm-python
.venv
pdm.lock

# caches
.pytest_cache
Expand Down
13 changes: 8 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ repos:
require_serial: true
args: ["--explicit-package-bases", "--check-untyped-defs"]
additional_dependencies:
[
"asynccasbin<2.0.0,>=1.1.2",
'tortoise-orm[accel]>=0.19.1; python_version < "3.8"',
'tortoise-orm[accel]>=0.20; python_version >= "3.8"',
]
["asynccasbin<2.0.0,>=1.1.2", "tortoise-orm[accel]>=0.18.0"]
- repo: https://github.com/pdm-project/pdm
rev: 2.10.4
hooks:
- id: pdm-lock-check
- id: pdm-export
args: ["-G", ":all", "--pyproject", "-o", "requirements.txt"]
files: ^pdm.lock$
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
Expand Down
14 changes: 8 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
# syntax=docker/dockerfile:1

FROM python:3.11
FROM python:3.7

WORKDIR /casbin-tortoise

RUN pip install -U pip setuptools wheel && \
pip install pdm
pip install pdm~=2.10.0

WORKDIR /casbin-tortoise
COPY pyproject.toml pdm.lock /casbin-tortoise
RUN pdm export -G :all -o requirements.txt --without-hashes && \
COPY pyproject.toml pyproject.toml

RUN pdm export -G :all --pyproject -o requirements.txt && \
pip install -r requirements.txt

COPY . ./casbin-tortoise
COPY . .

ENV PYTHONPATH=/casbin-tortoise

Expand Down
2 changes: 1 addition & 1 deletion casbin_tortoise_adapter/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __init__(self, modelclass: Type[CasbinRule] = CasbinRule) -> None:
self.modelclass: Type[CasbinRule] = modelclass
self._filtered: bool = False

async def load_policy(self, model: Model) -> None:
async def load_policy(self, model: Model) -> None: # pyright: ignore
"""Loads all policy rules from storage."""
for line in await self.modelclass.all():
load_policy_line(str(line), model)
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
POSTGRES_PASSWORD: "password"
POSTGRES_DB: "casbin_rule"
healthcheck:
test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER"]
test: ["CMD-SHELL", "pg_isready -U postgres"]
interval: 10s
timeout: 5s
retries: 5
Expand Down
479 changes: 479 additions & 0 deletions pdm.lock

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ authors = [
requires-python = ">=3.7,<4.0"
dependencies = [
"asynccasbin<2.0.0,>=1.1.2",
"tortoise-orm[accel]>=0.19.1; python_version < \"3.8\"",
"tortoise-orm[accel]>=0.20; python_version >= \"3.8\"",
"tortoise-orm[accel]>=0.18.0"
]

[project.urls]
Expand All @@ -31,9 +30,10 @@ changelog = "https://github.com/thearchitector/casbin-tortoise-adapter/blob/main
[tool.pdm]
[tool.pdm.dev-dependencies]
dev = [
"pytest<8.0,>=7.1",
"pytest-asyncio>=0.15.1",
"asyncpg>=0.28.0",
"pytest~=7.0",
"pluggy~=1.2.0",
"pytest-asyncio~=0.21.0",
"asyncpg~=0.28.0",
]

[tool.pytest.ini_options]
Expand Down
5 changes: 4 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import asyncio
import os

import pytest
from casbin import Enforcer
Expand All @@ -16,11 +17,13 @@ def event_loop():

@pytest.fixture(scope="session")
async def adapter():
host: str = os.getenv("POSTGRES_HOST", "postgres")

# connect to db and generate schemas
await Tortoise.init(
{
"connections": {
"default": "postgres://postgres:password@postgres:5432/casbin"
"default": f"postgres://postgres:password@{host}:5432/casbin"
},
"apps": {"my_app": {"models": ["casbin_tortoise_adapter"]}},
},
Expand Down

0 comments on commit 70fa90b

Please sign in to comment.