Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support pyproject.toml features with older python #11

Merged
merged 10 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@ env:
jobs:
pytest:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
version: ["3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version-file: .python-version
python-version: ${{ matrix.version }}

- name: Install Dependencies
run: make install
Expand Down
8 changes: 6 additions & 2 deletions paracelsus/pyproject.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import os
import tomllib
from pathlib import Path
from typing import Any, Dict

try:
import tomllib
except: # noqa: E722
import toml as tomllib # type: ignore


def get_pyproject_settings(dir: Path = Path(os.getcwd())) -> Dict[str, Any] | None:
pyproject = dir / "pyproject.toml"
Expand All @@ -11,6 +15,6 @@ def get_pyproject_settings(dir: Path = Path(os.getcwd())) -> Dict[str, Any] | No
return None

with open(pyproject, "rb") as f:
data = tomllib.load(f)
data = tomllib.loads(f.read().decode())

return data.get("tool", {}).get("paracelsus", None)
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ authors = [{"name" = "Robert Hafner"}]
dependencies = [
"pydot",
"sqlalchemy",
"typer"
"typer",
"toml; python_version < '3.11'"
]
description = ""
dynamic = ["version"]
Expand Down
4 changes: 3 additions & 1 deletion tests/assets/example/models.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from datetime import UTC, datetime
from datetime import datetime, timezone
from uuid import uuid4

from sqlalchemy import Boolean, DateTime, ForeignKey, String, Text, Uuid
from sqlalchemy.orm import mapped_column

from .base import Base

UTC = timezone.utc


class User(Base):
__tablename__ = "users"
Expand Down
4 changes: 3 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import os
import shutil
import tempfile
from datetime import UTC, datetime
from datetime import datetime, timezone
from pathlib import Path
from uuid import uuid4

import pytest
from sqlalchemy import Boolean, DateTime, ForeignKey, String, Text, Uuid
from sqlalchemy.orm import declarative_base, mapped_column

UTC = timezone.utc


@pytest.fixture
def metaclass():
Expand Down