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

Ci: Update ruff and cruft template #291

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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 .cruft.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"template": "https://github.com/KennethEnevoldsen/swift-python-cookiecutter",
"commit": "e02068889310225ea4f65ea0b203c2949e1597a9",
"commit": "85413085032f305896da8bad287a83d53fb0b196",
"checkout": null,
"context": {
"cookiecutter": {
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/static_type_checks.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# THIS ACTION WILL:
# 1. Install dependencies
# 2. Run static type checker

# SETUP:
# None required except for the Makefile

name: static_type_checks

on:
Expand Down
12 changes: 7 additions & 5 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
# This workflow will:
# 1) install Python dependencies
# 2) run make test
# THIS ACTION WILL:
# 1) install Python dependencies
# 2) run make test

# SETUP:
# None required except for the Makefile

name: Tests
name: test
on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
pytest:
test:
runs-on: ${{ matrix.os }}
permissions:
contents: read
Expand Down
6 changes: 3 additions & 3 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ static-type-check:
lint:
@echo "--- 🧹 Running linters ---"
ruff format . # running ruff formatting
ruff src/ --fix # running ruff linting
ruff tests/ --fix
ruff docs/conf.py --fix
ruff check src/ --fix # running ruff linting
ruff check tests/ --fix
ruff check docs/conf.py --fix

test:
@echo "--- 🧪 Running tests ---"
Expand Down
83 changes: 42 additions & 41 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,7 @@ repository = "https://github.com/centre-for-humanities-computing/DaCy"
file = "LICENSE"
name = "Apache License 2.0"
[project.optional-dependencies]
dev = [
"cruft>=2.0.0",
"pyright>=1.1.339",
"ruff>=0.0.270",
]
dev = ["cruft>=2.0.0", "pyright>=1.1.339", "ruff==0.7.1"]
tests = ["pytest>=7.1.2", "pytest-cov>=3.0.0", "pytest-instafail>=0.4.2"]
docs = [
"sphinx==5.3.0",
Expand Down Expand Up @@ -110,6 +106,42 @@ pythonPlatform = "Darwin"

[tool.ruff]
# extend-include = ["*.ipynb"]

# Exclude a variety of commonly ignored directories.
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".hg",
".nox",
".pants.d",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"venv",
"__init__.py",
".venv",
".env",
".git",
"__pycache__",
"dev/**",
"training/main/**",
"training/ner_fine_grained/**",
"papers/DaCy-A-Unified-Framework-for-Danish-NLP/**",
"docs/performance_testing_utils/**",
]
Comment on lines +111 to +141
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Remove duplicate exclude patterns.

The exclude list contains duplicate entries:

  • .venv appears on lines 123 and 132
  • .git appears on lines 115 and 134

Apply this diff to remove duplicates:

exclude = [
  ".bzr",
  ".direnv",
  ".eggs",
  ".git",
  ".hg",
  ".nox",
  ".pants.d",
  ".pytype",
  ".ruff_cache",
  ".svn",
  ".tox",
  ".venv",
  "__pypackages__",
  "_build",
  "buck-out",
  "build",
  "dist",
  "node_modules",
  "venv",
  "__init__.py",
- ".venv",  # Remove duplicate
  ".env",
- ".git",   # Remove duplicate
  "__pycache__",
  "dev/**",
  "training/main/**",
  "training/ner_fine_grained/**",
  "papers/DaCy-A-Unified-Framework-for-Danish-NLP/**",
  "docs/performance_testing_utils/**",
]
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".hg",
".nox",
".pants.d",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"venv",
"__init__.py",
".venv",
".env",
".git",
"__pycache__",
"dev/**",
"training/main/**",
"training/ner_fine_grained/**",
"papers/DaCy-A-Unified-Framework-for-Danish-NLP/**",
"docs/performance_testing_utils/**",
]
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".hg",
".nox",
".pants.d",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"venv",
"__init__.py",
".env",
"__pycache__",
"dev/**",
"training/main/**",
"training/ner_fine_grained/**",
"papers/DaCy-A-Unified-Framework-for-Danish-NLP/**",
"docs/performance_testing_utils/**",
]

target-version = "py38"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Align ruff target-version with project's Python requirement.

The project requires Python >=3.9, but ruff's target-version is set to py38. Consider updating to:

-target-version = "py38"
+target-version = "py39"

This alignment ensures ruff uses language features and checks appropriate for your minimum supported Python version.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
target-version = "py38"
target-version = "py39"


[tool.ruff.lint]
# Enable pycodestyle (`E`) and Pyflakes (`F`) codes by default.
select = [
"A",
Expand Down Expand Up @@ -150,54 +182,23 @@ ignore = [
"ANN202",
"COM812",
]
ignore-init-module-imports = true
# Allow autofix for all enabled rules (when `--fix`) is provided.
unfixable = ["ERA"]
# Exclude a variety of commonly ignored directories.
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".hg",
".nox",
".pants.d",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"venv",
"__init__.py",
".venv",
".env",
".git",
"__pycache__",
"dev/**",
"training/main/**",
"training/ner_fine_grained/**",
"papers/DaCy-A-Unified-Framework-for-Danish-NLP/**",
"docs/performance_testing_utils/**",
]


# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
target-version = "py38"


[tool.ruff.lint.pydocstyle]
convention = "google"

[tool.ruff.flake8-annotations]
[tool.ruff.lint.flake8-annotations]
mypy-init-return = true
suppress-none-returning = true


[tool.ruff.mccabe]
[tool.ruff.lint.mccabe]
# Unlike Flake8, default to a complexity level of 10.
max-complexity = 10

Expand Down
1 change: 1 addition & 0 deletions src/dacy/download.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Functions for downloading DaCy models."""

import os
from importlib.metadata import version
from pathlib import Path
Expand Down
1 change: 1 addition & 0 deletions src/dacy/load.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Functionality for loading and locating DaCy models."""

import warnings
from pathlib import Path
from typing import Any, Union
Expand Down
1 change: 1 addition & 0 deletions src/dacy/score/input_length.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Contains functions for testing the performance of models on varying input
length."""

from typing import Callable, List, Union

import pandas as pd
Expand Down
3 changes: 2 additions & 1 deletion src/dacy/score/score.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""This includes function for scoring models applied to a SpaCy corpus."""

from __future__ import annotations

from copy import copy
Expand Down Expand Up @@ -163,7 +164,7 @@ def __score(augmenter): # noqa: ANN001

# and collapse list to dict
for key in scores: # type: ignore
scores[key] = [s[key] if key in s else None for s in scores_ls] # type: ignore
scores[key] = [s.get([key], None) for s in scores_ls] # type: ignore
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix critical bug in score aggregation.

There's a bug in the dictionary access where a list is incorrectly passed to the get() method. This will cause all scores to be None as the key will never be found.

Apply this fix:

-            scores[key] = [s.get([key], None) for s in scores_ls]
+            scores[key] = [s.get(key, None) for s in scores_ls]
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
scores[key] = [s.get([key], None) for s in scores_ls] # type: ignore
scores[key] = [s.get(key, None) for s in scores_ls] # type: ignore


scores["k"] = list(range(k)) # type: ignore

Expand Down
5 changes: 3 additions & 2 deletions tests/test_datasets.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import dacy
from dacy.datasets import dane, female_names, male_names, muslim_names
from spacy.lang.da import Danish
from spacy.training import Example
from spacy.training.corpus import Corpus

import dacy
from dacy.datasets import dane, female_names, male_names, muslim_names


def test_dane():
train, dev, test = dane(open_unverified_connection=True) # type: ignore
Expand Down
3 changes: 2 additions & 1 deletion tests/test_download.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import dacy
import pytest

import dacy
from dacy.load import load


Expand Down
3 changes: 2 additions & 1 deletion tests/test_hate_speech.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import dacy
import spacy

import dacy


def test_add_hate_speech_detection():
nlp = spacy.blank("da")
Expand Down
5 changes: 3 additions & 2 deletions tests/test_score.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import pandas as pd
from dacy.datasets import dane
from dacy.score import n_sents_score, score
from spacy.lang.da import Danish
from spacy.training.augment import create_lower_casing_augmenter

from dacy.datasets import dane
from dacy.score import n_sents_score, score


def test_score():
nlp = Danish()
Expand Down
3 changes: 2 additions & 1 deletion tests/test_sentiment.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import dacy
import spacy

import dacy


def test_add_subjectivity():
nlp = spacy.blank("da")
Expand Down
Loading