Skip to content

Commit

Permalink
[CHORE] Review and fix commit hooks (#5027)
Browse files Browse the repository at this point in the history
<!-- Thanks for your contribution! As part of our Community Growers
initiative 🌱, we're donating Justdiggit bunds in your name to reforest
sub-Saharan Africa. To claim your Community Growers certificate, please
contact David Berenstein in our Slack community or fill in this form
https://tally.so/r/n9XrxK once your PR has been merged. -->

# Description

Review and improve the pre-commit hooks configuration.

**Type of change**

(Please delete options that are not relevant. Remember to title the PR
according to the type of change)

- [ ] New feature (non-breaking change which adds functionality)
- [ ] Refactor (change restructuring the codebase without changing
functionality)
- [ ] Improvement (change adding some improvement to an existing
functionality)

**How Has This Been Tested**

(Please describe the tests that you ran to verify your changes. And
ideally, reference `tests`)

- [ ] Test A
- [ ] Test B

**Checklist**

- [ ] I added relevant documentation
- [ ] I followed the style guidelines of this project
- [ ] I did a self-review of my code
- [ ] I made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] I filled out [the contributor form](https://tally.so/r/n9XrxK)
(see text above)
- [ ] I have added relevant notes to the `CHANGELOG.md` file (See
https://keepachangelog.com/)

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
frascuchon and pre-commit-ci[bot] authored Jun 14, 2024
1 parent 2212021 commit f569e8d
Show file tree
Hide file tree
Showing 119 changed files with 196 additions and 330 deletions.
4 changes: 3 additions & 1 deletion .github/actions/generate-credentials/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ def generate_credentials() -> Dict[str, Any]:
credentials = {}
for user in ["owner", "admin", "annotator"]:
logging.info(f"Generating random credential for user '{user}'")
password = generate_password_from_secret(secret=SECRET, salt=f"{GITHUB_REF}/{user}", length=32)
password = generate_password_from_secret(
secret=SECRET, salt=f"{GITHUB_REF}/{user}", length=32
)
credentials[user] = password
return credentials

Expand Down
16 changes: 12 additions & 4 deletions .github/actions/slack-post-credentials/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ def get_slack_channel_id(client: WebClient) -> Union[str, None]:
for channel in result["channels"]:
if channel["name"] == SLACK_CHANNEL_NAME:
channel_id = channel["id"]
logging.info(f"Found channel id for '{SLACK_CHANNEL_NAME}' channel: '{channel_id}'")
logging.info(
f"Found channel id for '{SLACK_CHANNEL_NAME}' channel: '{channel_id}'"
)
return channel_id


Expand All @@ -87,7 +89,9 @@ def get_pr_url(pr_number: int) -> str:
return f"https://github.com/argilla-io/argilla/pull/{pr_number}"


def get_thread_ts_pr_message(client: WebClient, channel_id: str, pr_number: int) -> Union[str, None]:
def get_thread_ts_pr_message(
client: WebClient, channel_id: str, pr_number: int
) -> Union[str, None]:
response = client.conversations_history(channel=channel_id, limit=1000)
response.validate()

Expand Down Expand Up @@ -119,7 +123,9 @@ def bot_already_replied(client: WebClient, channel_id: str, thread_ts: str) -> b
return False


def reply_thread_with_credentials(client: WebClient, channel_id: str, thread_ts: str) -> None:
def reply_thread_with_credentials(
client: WebClient, channel_id: str, thread_ts: str
) -> None:
client.chat_postMessage(
channel=channel_id,
text=f"Credentials for PR deployed environment (use as password and API key):\n- URL: {URL}\n- owner: '{OWNER}'\n- admin: '{ADMIN}'\n- annotator: '{ANNOTATOR}'",
Expand Down Expand Up @@ -153,7 +159,9 @@ def reply_thread_with_credentials(client: WebClient, channel_id: str, thread_ts:
pr_number = get_pull_request_number()
if pr_number is None:
logging.error(f"Could not parse `GITHUB_REF` ({GITHUB_REF}) to get PR number")
raise ValueError(f"Could not parse `GITHUB_REF` ({GITHUB_REF}) to get PR number")
raise ValueError(
f"Could not parse `GITHUB_REF` ({GITHUB_REF}) to get PR number"
)

client = get_slack_client()

Expand Down
58 changes: 45 additions & 13 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,32 +1,43 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
exclude_types: [text, jupyter]
- id: trailing-whitespace

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.1.4
hooks:
- id: ruff-format

##############################################################################
# argilla specific hooks
##############################################################################
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.1.4
hooks:
- id: ruff
files: 'argilla/src/.*\.py$'
args:
- --fix
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.5.4
hooks:
- id: insert-license
name: "Insert license header in Python source files"
files: '^argilla-sdk/.*\.py$'
exclude: ^argilla-sdk/docs/snippets/
files: '^argilla/.*\.py$'
exclude: ^argilla/docs/snippets/
args:
- --license-filepath
- argilla-sdk/LICENSE_HEADER
- argilla/LICENSE_HEADER
- --fuzzy-match-generates-todo
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.1.4
hooks:
- id: ruff
files: '^argilla-sdk/.*\.py$'
args:
- --fix
- id: ruff-format
files: '^argilla-sdk/.*\.py$'
- repo: https://github.com/kynan/nbstripout
rev: 0.7.1
hooks:
- id: nbstripout
files: '^argilla-sdk/.*\.ipynb$'
files: '^argilla/.*\.ipynb$'
args:
- --keep-count
- --keep-output
Expand All @@ -37,6 +48,27 @@ repos:
# - --keep-execution-count
# - --keep-metadata
# - --keep-version
##############################################################################
# argilla-server specific hooks
##############################################################################
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.1.4
hooks:
- id: ruff
files: 'argila-server/src/.*\.py$'
args:
- --fix

- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.5.5
hooks:
- id: insert-license
name: "Insert license header in Python source files"
files: '^argilla-server/.*\.py$'
args:
- --license-filepath
- argilla-server/LICENSE_HEADER
- --fuzzy-match-generates-todo

ci:
autofix_commit_msg: |
Expand Down
47 changes: 0 additions & 47 deletions argilla-server/.pre-commit-config.yaml

This file was deleted.

File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion argilla-server/src/argilla_server/_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
from argilla_server.database import get_async_db
from argilla_server.logging import configure_logging
from argilla_server.models import User
from argilla_server.pydantic_v1.errors import ConfigError
from argilla_server.search_engine import get_search_engine
from argilla_server.security import auth
from argilla_server.settings import settings
Expand Down
2 changes: 1 addition & 1 deletion argilla-server/src/argilla_server/alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from alembic import context
from argilla_server.database import database_url_sync
from argilla_server.models.base import DatabaseModel
from argilla_server.models.database import * # noqa: I001
from argilla_server.models.database import * # noqa
from sqlalchemy import engine_from_config, pool

# this is the Alembic Config object, which provides
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
Create Date: 2023-07-24 12:47:11.715011
"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm import selectinload

from argilla_server import models
from argilla_server.api.policies.v1 import DatasetPolicy, MetadataPropertyPolicy, authorize, is_authorized
from argilla_server.api.schemas.v1.datasets import (
Dataset as DatasetSchema,
Expand All @@ -38,10 +37,10 @@
MetadataPropertyCreate,
)
from argilla_server.api.schemas.v1.vector_settings import VectorSettings, VectorSettingsCreate, VectorsSettings
from argilla_server.contexts import accounts, datasets
from argilla_server.contexts import datasets
from argilla_server.database import get_async_db
from argilla_server.enums import ResponseStatus
from argilla_server.models import Dataset, User, Workspace
from argilla_server.models import Dataset, User
from argilla_server.search_engine import (
SearchEngine,
get_search_engine,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import argilla_server.search_engine as search_engine
from argilla_server.api.policies.v1 import DatasetPolicy, RecordPolicy, authorize, is_authorized
from argilla_server.api.schemas.v1.datasets import Dataset as DatasetSchema
from argilla_server.api.schemas.v1.records import (
Filters,
FilterScope,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from uuid import UUID

from fastapi import APIRouter, Depends, Security, status
from fastapi import APIRouter, Depends, Security
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm import selectinload

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from uuid import UUID

from fastapi import APIRouter, Depends, Security, status
from fastapi import APIRouter, Depends, Security
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm import selectinload

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def _check_oauth_enabled_or_raise() -> None:


def _get_provider_by_name_or_raise(provider_name: str) -> OAuth2ClientProvider:
if not provider_name in settings.oauth.providers:
if provider_name not in settings.oauth.providers:
raise HTTPException(status_code=404, detail=f"Provider '{provider_name}' not found")
return settings.oauth.providers[provider_name]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from uuid import UUID

from fastapi import APIRouter, Depends, Security, status
from fastapi import APIRouter, Depends, Security
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm import selectinload

Expand Down
3 changes: 1 addition & 2 deletions argilla-server/src/argilla_server/api/handlers/v1/records.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import TYPE_CHECKING
from uuid import UUID

from fastapi import APIRouter, Depends, Query, Security, status
Expand All @@ -26,7 +25,7 @@
from argilla_server.api.schemas.v1.responses import Response, ResponseCreate
from argilla_server.api.schemas.v1.suggestions import Suggestion as SuggestionSchema
from argilla_server.api.schemas.v1.suggestions import SuggestionCreate, Suggestions
from argilla_server.contexts import datasets, questions
from argilla_server.contexts import datasets
from argilla_server.database import get_async_db
from argilla_server.errors.future.base_errors import NotFoundError, UnprocessableEntityError
from argilla_server.models import Dataset, Question, Record, Suggestion, User
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from uuid import UUID

from fastapi import APIRouter, Depends, Security, status
from fastapi import APIRouter, Depends, Security
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm import selectinload

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from uuid import UUID

from fastapi import APIRouter, Depends, Security, status
from fastapi import APIRouter, Depends, Security
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm import selectinload

Expand Down
2 changes: 0 additions & 2 deletions argilla-server/src/argilla_server/api/handlers/v1/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import List
from uuid import UUID

from fastapi import APIRouter, Depends, Request, Security, status
Expand All @@ -25,7 +24,6 @@
from argilla_server.api.schemas.v1.workspaces import Workspaces
from argilla_server.contexts import accounts
from argilla_server.database import get_async_db
from argilla_server.errors.future import NotUniqueError
from argilla_server.models import User
from argilla_server.security import auth

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from uuid import UUID

from fastapi import APIRouter, Depends, Security, status
from fastapi import APIRouter, Depends, Security
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm import selectinload

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
Workspaces,
WorkspaceUserCreate,
)
from argilla_server.contexts import accounts, datasets
from argilla_server.contexts import accounts
from argilla_server.database import get_async_db
from argilla_server.errors.future import NotFoundError, UnprocessableEntityError
from argilla_server.models import User, Workspace, WorkspaceUser
Expand Down
3 changes: 1 addition & 2 deletions argilla-server/src/argilla_server/api/policies/v1/commons.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Awaitable, Callable, Optional
from uuid import UUID
from typing import Awaitable, Callable

from argilla_server.errors import ForbiddenOperationError
from argilla_server.models import User
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

from datetime import datetime
from typing import Annotated, Any, Dict, Generic, List, Literal, Optional, TypeVar, Union
from typing import Any, Dict, Generic, List, Literal, Optional, TypeVar, Union
from uuid import UUID

from argilla_server.api.schemas.v1.commons import UpdateSchema
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from argilla_server.api.schemas.v1.commons import UpdateSchema
from argilla_server.api.schemas.v1.fields import FieldName
from argilla_server.enums import OptionsOrder, QuestionType
from argilla_server.pydantic_v1 import BaseModel, Field, conlist, constr, root_validator, validator
from argilla_server.pydantic_v1 import BaseModel, Field, conlist, constr, root_validator
from argilla_server.settings import settings

try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from typing import Any, Dict, Optional
from typing import Optional

from argilla_server.pydantic_v1 import BaseModel, BaseSettings, Field

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

from datetime import datetime
from typing import Annotated, Any, Dict, List, Literal, Optional, Union
from typing import Any, List, Literal, Optional, Union
from uuid import UUID

from argilla_server.api.schemas.v1.questions import QuestionName
Expand Down
Loading

0 comments on commit f569e8d

Please sign in to comment.