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

Feature/uv #156

Open
wants to merge 33 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
8dbbd9c
Update pyproject.toml dependencies
fazedordecodigo Oct 21, 2024
9c21b6c
Atualiza a formatação das dependências no pyproject.toml
fazedordecodigo Nov 16, 2024
3e6fd94
Atualiza as versões das dependências no arquivo de configuração do pr…
fazedordecodigo Nov 16, 2024
044b646
Atualiza informações de autoria e repositório no pyproject.toml
fazedordecodigo Nov 16, 2024
200268d
Atualiza configuração do Dependabot e ajusta dependências no pyprojec…
fazedordecodigo Nov 16, 2024
93b4642
Adiciona suporte a anotações futuras e atualiza a URL do repositório …
fazedordecodigo Nov 16, 2024
796302c
Remove arquivo de configuração do Sonar e simplifica dependências de …
fazedordecodigo Nov 16, 2024
450d326
Atualiza anotações de tipo para usar 'Self' e simplifica importações …
fazedordecodigo Nov 16, 2024
b8baa0e
Adiciona anotações de tipo em funções de validação e ajusta a configu…
fazedordecodigo Nov 16, 2024
23963b5
Adiciona verificação de tipo condicional e atualiza configuração do T…
fazedordecodigo Nov 16, 2024
2a08898
Adiciona suporte a anotações futuras e formata código para melhorar a…
fazedordecodigo Nov 16, 2024
f0dc715
Adiciona comentários de tipo para ignorar avisos em testes de validaç…
fazedordecodigo Nov 16, 2024
5289d58
Ajusta formatação de comentário de tipo em teste de validação de string
fazedordecodigo Nov 16, 2024
69a7e11
Remove argumento de correção de final de linha na configuração do pre…
fazedordecodigo Nov 16, 2024
7d4b4e3
Substitui a classe Notifiable para herdar de NotifiableProtocol e adi…
fazedordecodigo Nov 16, 2024
3922dab
Ajusta tipos de mensagem em testes de validação booleana e adiciona t…
fazedordecodigo Nov 16, 2024
5f741bc
Adiciona mensagens padrão para validações booleanas em is_false e is_…
fazedordecodigo Nov 16, 2024
7de7b19
Adiciona ambiente pre-commit ao tox e ajusta descrição para execução …
fazedordecodigo Nov 16, 2024
7f5729a
Adiciona teste para mensagem padrão quando is_false é inválido
fazedordecodigo Nov 16, 2024
65515b1
Ajusta mensagens padrão e parâmetros nos métodos de validação booleana
fazedordecodigo Jan 12, 2025
548d443
Merge branch 'develop' into feature/uv
fazedordecodigo Jan 12, 2025
f911ac7
Corrige a anotação de tipo da função _valid_email e adiciona verifica…
fazedordecodigo Jan 12, 2025
b45a523
Ajusta a documentação e a lógica de validação do método is_credit_car…
fazedordecodigo Jan 12, 2025
c2ddfed
Ajusta a formatação da documentação nos métodos de validação da class…
fazedordecodigo Jan 12, 2025
e3b4b76
Ajusta a formatação da documentação nos métodos da classe BoolValidat…
fazedordecodigo Jan 12, 2025
c3d4fa0
Adiciona suporte a anotações futuras no módulo de padrões regex
fazedordecodigo Jan 12, 2025
3e8f924
Merge branch 'develop' into feature/uv
Feb 11, 2025
3ea94f1
Atualiza dependências e grupos de dependência no pyproject.toml
Feb 11, 2025
38ae152
Ajusta padrões regex, corrige formatação e atualiza dependências no p…
Feb 11, 2025
3a270cd
Refatora funções de regex para retornar padrões compilados e remove c…
fazedordecodigo Feb 13, 2025
3d1cda8
Remove função desnecessária de conversão de padrões regex e ajusta im…
fazedordecodigo Feb 13, 2025
ee5523c
Adiciona anotações de tipo aos testes de validação de regex e remove …
fazedordecodigo Feb 13, 2025
f88b910
Merge branch 'develop' into feature/uv
fazedordecodigo Feb 13, 2025
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 .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ updates:
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "weekly"
interval: "weekly"
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ appsettings.json
.ruff_cache
.tool-versions
.tox
coverage.xml
coverage.xml
39 changes: 16 additions & 23 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ default_language_version:

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand All @@ -12,35 +12,28 @@ repos:
- id: check-symlinks
- id: destroyed-symlinks
- id: mixed-line-ending
args:
- "--fix=lf"
- id: check-case-conflict
- id: check-merge-conflict

- repo: https://github.com/asottile/pyupgrade
rev: v3.15.1
rev: v3.19.0
hooks:
- id: pyupgrade
args: ["--py39-plus"]
args: ["--py311-plus"]

- repo: https://github.com/python-poetry/poetry
rev: 1.8.0
- repo: https://github.com/astral-sh/uv-pre-commit
# uv version.
rev: 0.5.2
hooks:
- id: poetry-check
- id: poetry-lock
- id: poetry-export
args: [
"--with",
"dev",
"-f",
"requirements.txt",
"-o",
"./requirements/requirements_dev.txt",
]
# Compile requirements
- id: pip-compile
args: [requirements-dev.in, -o, requirements-dev.txt]
files: ^requirements-dev\.(in|txt)$

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.0
rev: v0.7.4
hooks:
- id: ruff
args:
- "--fix"
- "--fixable=ALL"
- "--exit-non-zero-on-fix"
args: [--exit-non-zero-on-fix, --config=pyproject.toml]
- id: ruff-format
args: [--config=pyproject.toml]
16 changes: 10 additions & 6 deletions flunt/constants/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

from .messages import (
CNPJ,
CONTAINS,
Expand All @@ -14,10 +16,11 @@
EMAIL,
EQUALS,
EXACT_LENGTH,
GREATER_OR_EQUALS_THAN,
GREATER_THAN,
GREATER_THAN_OR_EQUALS,
IN_LIST,
IP,
IS_BETWEEN,
IS_CALLABLE,
IS_DECIMAL,
IS_DICT,
Expand Down Expand Up @@ -48,8 +51,8 @@
IS_TRUE,
IS_TYPE,
IS_UUID,
LESS_THAN,
LESS_THAN_OR_EQUALS,
LOWER_OR_EQUALS_THAN,
LOWER_THAN,
MAC_ADDRESS,
MAX_LENGTH,
MIN_LENGTH,
Expand Down Expand Up @@ -83,9 +86,9 @@
"CNPJ",
"PHONE",
"GREATER_THAN",
"GREATER_THAN_OR_EQUALS",
"LESS_THAN",
"LESS_THAN_OR_EQUALS",
"GREATER_OR_EQUALS_THAN",
"LOWER_THAN",
"LOWER_OR_EQUALS_THAN",
"EQUALS",
"NOT_EQUALS",
"IN_LIST",
Expand Down Expand Up @@ -122,4 +125,5 @@
"IS_NOT_SET",
"IS_STR",
"IS_NOT_STR",
"IS_BETWEEN",
]
9 changes: 6 additions & 3 deletions flunt/constants/messages.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

REQUIRED = "The field {0} is required"
MAX_LENGTH = "The field {0} must be less than {1} characters"
MIN_LENGTH = "The field {0} must be at least {1} characters"
Expand All @@ -20,9 +22,9 @@
CNPJ = "The field {0} must be a valid CNPJ"
PHONE = "The field {0} must be a valid phone number"
GREATER_THAN = "The field {0} must be greater than {1}"
GREATER_THAN_OR_EQUALS = "The field {0} must be greater than or equals {1}"
LESS_THAN = "The field {0} must be less than {1}"
LESS_THAN_OR_EQUALS = "The field {0} must be less than or equals {1}"
GREATER_OR_EQUALS_THAN = "The field {0} must be greater or equals than {1}"
LOWER_THAN = "The field {0} must be lower than {1}"
LOWER_OR_EQUALS_THAN = "The field {0} must be lower or equals than {1}"
EQUALS = "The field {0} must be equals {1}"
NOT_EQUALS = "The field {0} must be different than {1}"
IN_LIST = "The field {0} must be in the list {1}"
Expand Down Expand Up @@ -98,3 +100,4 @@
IS_DATE_NOT_EQUAL = "The field {0} must not be a Date equal to {1}"
IS_DATE_EQUAL = "The field {0} must be a Date equal to {1}"
IS_DATE_NOT_EQUAL = "The field {0} must not be a Date equal to {1}"
IS_BETWEEN = "The field {0} must be between {1} and {2}"
19 changes: 15 additions & 4 deletions flunt/localization/flunt_regex_patterns.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
"""Module Flunt Regex Patterns."""

from __future__ import annotations

from typing import TYPE_CHECKING

if TYPE_CHECKING:
from re import Pattern

REGEX_PATTERNS = {
"email": r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)",
"passport": r"^(?!^0+$)[a-zA-Z0-9]{3,20}$",
"only_numbers": r"^\d+$",
"only_letters_and_numbers": r"[A-Za-z0-9_-]",
"url": r"^(http|https):(\/\/www\.|\/\/www\.|\/\/|\/\/)[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$"
r"|(http|https):(\/\/localhost:\d*|\/\/127\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]|[1-9][0-9]"
r"|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]))(:[0-9]{1,5})?(\/.*)?$",
r"|(http|https):(\/\/localhost:\d*|\/\/127\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]|[1-9][0-9]"
r"|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5]))(:[0-9]{1,5})?(\/.*)?$",
"cpf": r"^\d{3}\.?\d{3}\.?\d{3}-?\d{2}$",
"cnpj": r"^\d{2}\.?\d{3}\.?\d{3}/?\d{4}-?\d{2}$",
}

def get_pattern(name: str) -> str | None:

def get_pattern(name: str) -> str | Pattern[str]:
"""Retrieve a regex pattern by its name."""
return REGEX_PATTERNS.get(name)
value = REGEX_PATTERNS.get(name)
if value is None:
return ""
return value
5 changes: 3 additions & 2 deletions flunt/notifications/notifiable.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"""Module Notifiable."""

from abc import ABC
from __future__ import annotations

from flunt.notifications.notification import Notification
from flunt.protocols.notifiable_protocol import NotifiableProtocol


class Notifiable(ABC): # noqa: B024
class Notifiable(NotifiableProtocol):
"""
A class representing an object that can be notified.

Expand Down
2 changes: 2 additions & 0 deletions flunt/notifications/notification.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Module Notification."""

from __future__ import annotations

from dataclasses import dataclass


Expand Down
Empty file added flunt/protocols/__init__.py
Empty file.
181 changes: 181 additions & 0 deletions flunt/protocols/notifiable_protocol.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
"""Module Notifiable."""

from __future__ import annotations

from abc import ABC, abstractmethod
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from flunt.notifications.notification import Notification


class NotifiableProtocol(ABC):
"""
A class representing an object that can be notified.

This class extends Notification and provides methods for managing notifications.

Attributes
----------
notifications: list[Notification]
A list of notifications.
is_valid: bool
A boolean indicating if there are any notifications.

Methods
-------
- get_notification_instance
- add_notifications
- add_notification
- get_notifications
- clear

"""

@abstractmethod
def __init__(self) -> None:
"""Initialize the list of notifications."""

@property
@abstractmethod
def notifications(self) -> list[Notification]:
"""
Return the list of notifications.

Returns
-------
`list[Notification]`
A list of notifications.

Examples
--------
```python
obj = Notifiable()
obj.notifications # []
```

"""

@property
@abstractmethod
def is_valid(self) -> bool:
"""
Check if there are any notifications.

Returns
-------
`bool`
True if there are no notifications, False otherwise.

Examples
--------
```python
obj = Notifiable()
obj.is_valid() # True
```

"""

@abstractmethod
def add_notifications(self, notifications: list[Notification]) -> None:
"""
Add notifications from a list of contracts to the list of notifications.

Parameters
----------
`notifications`: list[Notification]
A list of notifications to be added.

Returns
-------
`None`

Examples
--------
```python
obj = Notifiable()
obj.add_notifications([Notification("key", "message")])
obj.notifications # [Notification("key", "message")]
```

"""

@abstractmethod
def add_notification(self, field: str, message: str) -> None:
"""
Add a single notification to the list of notifications.

Parameters
----------
`notification`: Notification
The notification to be added.

Returns
-------
`None`

Examples
--------
```python
obj = Notifiable()
obj.add_notification("field", "message")
obj.notifications # [Notification("field", "message")]
```

"""

@abstractmethod
def get_notifications(self) -> list[Notification]:
"""
Return the list of notifications.

Returns
-------
`list[Notification]`
A list of notifications.

Examples
--------
```python
obj = Notifiable()
obj.get_notifications() # []
```

"""

@abstractmethod
def clear(self) -> None:
"""
Clear the list of notifications.

Returns
-------
`None`

Examples
--------
```python
obj = Notifiable()
obj.clear() # []
```

"""

@abstractmethod
def __repr__(self) -> str:
"""
Return a string representation of the list of notifications.

Returns
-------
`str`
A string representation of the list of notifications.

Examples
--------
```python
obj = Notifiable()
repr(obj) # "[]"
```

"""
Loading
Loading