Skip to content

Commit

Permalink
Update pyproject & fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
twsl committed Sep 7, 2024
1 parent 046b93e commit 5f15c80
Show file tree
Hide file tree
Showing 8 changed files with 857 additions and 762 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ repos:
- id: nbstripout

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.5.5
rev: v0.6.4
hooks:
- id: ruff
args: ["--fix", "-v"]

- repo: https://github.com/RobertCraigie/pyright-python
rev: v1.1.374
rev: v1.1.379
hooks:
- id: pyright
args: ["--verbose", "--project=."]
Expand Down
1 change: 1 addition & 0 deletions docs/docs/notebooks/the-boring-model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"import torch\n",
"from torch.nn import functional as F # noqa: N812\n",
"from torch.utils.data import DataLoader, Dataset\n",
"\n",
"from whos_there.callback import NotificationCallback\n",
"from whos_there.senders.debug import DebugSender\n",
"\n",
Expand Down
1 change: 1 addition & 0 deletions examples/the-boring-model.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from torch.optim.lr_scheduler import StepLR
from torch.optim.sgd import SGD
from torch.utils.data import DataLoader, Dataset

from whos_there.callback import NotificationCallback
from whos_there.senders.debug import DebugSender

Expand Down
1,573 changes: 831 additions & 742 deletions poetry.lock

Large diffs are not rendered by default.

13 changes: 8 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ issues = "https://github.com/twsl/whos-there/issues"

[tool.poetry.dependencies]
python = "^3.10"
lightning = "^2.3.0"
python-telegram-bot = "^21.4"
lightning = "^2.4.0"
python-telegram-bot = "^21.5"
requests = "^2.32.3"

[tool.poetry.group.dev.dependencies]
ruff = ">=0.5.5,<0.7.0"
ruff = "^0.6.4"
bandit = "^1.7.9"
pre-commit = "^3.8.0"
pyright = "^1.1.374"
pyright = "^1.1.379"
ipykernel = "^6.29.5"
ipywidgets = "^8.1.3"
ipywidgets = "^8.1.5"
ipython = "^8.26.0"
jupytext = " ^1.16.4"
nbconvert = "^7.16.3"
Expand Down Expand Up @@ -135,6 +135,9 @@ exclude_lines = [
[tool.ruff]
line-length = 120 # Must agree with Black
extend-include = ["*.ipynb"]
lint.extend-select = [
"I",
]
lint.select = [
"B", # flake8-bugbear
"C4", # flake8-comprehensions
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/test_base.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from whos_there.__about__ import __version__


def test_version():
def test_version() -> None:
assert __version__ is not None
13 changes: 7 additions & 6 deletions tests/unit/test_dry_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import torch
from torch import Tensor
from torch.utils.data import DataLoader, Dataset

from whos_there.callback import NotificationCallback
from whos_there.senders.base import Sender

Expand All @@ -15,7 +16,7 @@ def __init__(self, size: int, length: int) -> None:
self.len = length
self.data = torch.randn(length, size)

def __getitem__(self, index) -> Tensor:
def __getitem__(self, index: int) -> Tensor:
return self.data[index]

def __len__(self) -> int:
Expand All @@ -27,19 +28,19 @@ def __init__(self) -> None:
super().__init__()
self.layer = torch.nn.Linear(16, 2)

def forward(self, x: Tensor, *args, **kwargs) -> Tensor: # pyright: ignore [reportIncompatibleMethodOverride]
def forward(self, x: Tensor, *args: Any, **kwargs: Any) -> Tensor: # pyright: ignore [reportIncompatibleMethodOverride]
return self.layer(x)

def training_step(self, batch, batch_idx) -> dict[str, Any]: # pyright: ignore [reportIncompatibleMethodOverride]
def training_step(self, batch: Any, batch_idx: int) -> dict[str, Any]: # pyright: ignore [reportIncompatibleMethodOverride]
loss = self(batch).sum()
self.log("train_loss", loss)
return {"loss": loss}

def validation_step(self, batch, batch_idx) -> None: # pyright: ignore [reportIncompatibleMethodOverride]
def validation_step(self, batch: Any, batch_idx: int) -> None: # pyright: ignore [reportIncompatibleMethodOverride]
loss = self(batch).sum()
self.log("valid_loss", loss)

def test_step(self, batch, batch_idx) -> None: # pyright: ignore [reportIncompatibleMethodOverride]
def test_step(self, batch: Any, batch_idx: int) -> None: # pyright: ignore [reportIncompatibleMethodOverride]
loss = self(batch).sum()
self.log("test_loss", loss)

Expand Down Expand Up @@ -94,7 +95,7 @@ def test_dry_run_failed() -> None:
train_data = DataLoader(RandomDataset(16, 8), batch_size=2)
val_data = DataLoader(RandomDataset(16, 8), batch_size=2)

def training_step_fail(self, batch, batch_idx):
def training_step_fail(self, batch, batch_idx) -> None:
raise TrainingError("failed")

sender = TestSender()
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/test_pickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@
from whos_there.senders import DebugSender, DiscordSender, EmailSender, SlackSender, TeamsSender, TelegramSender


def test_notification_pickle():
def test_notification_pickle() -> None:
ForkingPickler.dumps(NotificationCallback())


def test_debug_pickle():
def test_debug_pickle() -> None:
ForkingPickler.dumps(DebugSender())


def test_discord_pickle():
def test_discord_pickle() -> None:
ForkingPickler.dumps(DiscordSender(webhook_url=""))


def test_email_pickle():
def test_email_pickle() -> None:
ForkingPickler.dumps(EmailSender(host="", port=0, sender_email="", password="", recipient_emails=[])) # nosec


def test_slack_pickle():
def test_slack_pickle() -> None:
ForkingPickler.dumps(SlackSender(webhook_url="", channel=""))


def test_telegram_pickle():
def test_telegram_pickle() -> None:
ForkingPickler.dumps(TelegramSender(token="", chat_id=-1)) # nosec

0 comments on commit 5f15c80

Please sign in to comment.