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

Require sqlalchemy>=2 and upgrade code. #544

Merged
merged 2 commits into from
Jan 1, 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
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ repos:
optree,
pluggy,
rich,
sqlalchemy,
sqlalchemy>2,
types-setuptools,
]
pass_filenames: false
Expand Down
6 changes: 5 additions & 1 deletion docs/source/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ chronological order. Releases follow [semantic versioning](https://semver.org/)
releases are available on [PyPI](https://pypi.org/project/pytask) and
[Anaconda.org](https://anaconda.org/conda-forge/pytask).

## 0.4.5 - 2023-12-xx
## 0.5.0 - 2024-xx-xx

- {pull}`544` requires sqlalchemy `>=2` and upgrades the syntax.

## 0.4.5 - 2024-01-xx

- {pull}`515` enables tests with graphviz in CI. Thanks to {user}`NickCrews`.
- {pull}`517` raises an error when the configuration file contains a non-existing path
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dependencies:
- pluggy >=1.0.0
- optree >=0.9
- rich
- sqlalchemy >=1.4.36
- sqlalchemy >=2
- tomli >=1.0.0
- typing_extensions
- universal_pathlib
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ dependencies = [
"packaging",
"pluggy>=1",
"rich",
"sqlalchemy>=1.4.36",
"sqlalchemy>=2",
'tomli>=1; python_version < "3.11"',
'typing-extensions; python_version < "3.9"',
]
Expand Down
19 changes: 10 additions & 9 deletions src/_pytask/database_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
from typing import TYPE_CHECKING

from _pytask.dag_utils import node_and_neighbors
from sqlalchemy import Column
from sqlalchemy import create_engine
from sqlalchemy import String
from sqlalchemy.orm import declarative_base
from sqlalchemy.orm import DeclarativeBase
from sqlalchemy.orm import Mapped
from sqlalchemy.orm import mapped_column
from sqlalchemy.orm import sessionmaker

if TYPE_CHECKING:
Expand All @@ -27,17 +27,18 @@
DatabaseSession = sessionmaker()


BaseTable = declarative_base()
class BaseTable(DeclarativeBase):
pass


class State(BaseTable): # type: ignore[valid-type, misc]
class State(BaseTable):
"""Represent the state of a node in relation to a task."""

__tablename__ = "state"

task = Column(String, primary_key=True)
node = Column(String, primary_key=True)
hash_ = Column(String)
task: Mapped[str] = mapped_column(primary_key=True)
node: Mapped[str] = mapped_column(primary_key=True)
hash_: Mapped[str]


def create_database(url: str) -> None:
Expand All @@ -54,7 +55,7 @@ def _create_or_update_state(first_key: str, second_key: str, hash_: str) -> None
if not state_in_db:
session.add(State(task=first_key, node=second_key, hash_=hash_))
else:
state_in_db.hash_ = hash_ # type: ignore[assignment]
state_in_db.hash_ = hash_
session.commit()


Expand Down
14 changes: 6 additions & 8 deletions src/_pytask/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@
from _pytask.session import Session
from _pytask.traceback import Traceback
from rich.table import Table
from sqlalchemy import Column
from sqlalchemy import Float
from sqlalchemy import String

from sqlalchemy.orm import Mapped
from sqlalchemy.orm import mapped_column

if TYPE_CHECKING:
from _pytask.reports import ExecutionReport
Expand All @@ -51,9 +49,9 @@

__tablename__ = "runtime"

task = Column(String, primary_key=True)
date = Column(Float)
duration = Column(Float)
task: Mapped[str] = mapped_column(primary_key=True)
date: Mapped[float]
duration: Mapped[float]


@hookimpl(tryfirst=True)
Expand Down Expand Up @@ -198,7 +196,7 @@
"""Collect runtimes."""
with DatabaseSession() as session:
runtimes = [session.get(Runtime, task.signature) for task in tasks]
return {task.name: r.duration for task, r in zip(tasks, runtimes) if r} # type: ignore[misc]
return {task.name: r.duration for task, r in zip(tasks, runtimes) if r}

Check warning on line 199 in src/_pytask/profile.py

View check run for this annotation

Codecov / codecov/patch

src/_pytask/profile.py#L199

Added line #L199 was not covered by tests


class FileSizeNameSpace:
Expand Down