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

fix(lint): fixing linter issues #102

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
14 changes: 14 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[flake8]
max-line-length = 100
max-complexity = 18
select =
"B", # Bugbear
"C", # Cyclomatic complexity
"E", # PEP8 errors
"F", # PyFlakes
"W", # PEP8 warnings
"T4", # Flake8 plugins that check typing
"B9", # Bugbear
#require-plugins =
# "flake8-bugbear",
# "flake8-black",
28 changes: 28 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
hooks:
- id: flake8
additional_dependencies: [flake8-black, flake8-bugbear]
args: [--config, .flake8]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.1
hooks:
- id: ruff
args: [--fix]
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
args: [--profile, black]
- repo: local
hooks:
- id: pytest
name: pytest
entry: pytest
language: system
pass_filenames: false
always_run: true
22 changes: 22 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
pydantic = "*"
fastapi = "*"
pydantic-settings = "*"
mangum = "*"
httpx = "*"
Comment on lines +6 to +11
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider specifying version ranges for production dependencies.

While using "*" for package versions allows for the latest updates, it may lead to unexpected behavior or compatibility issues in the future. For production dependencies, it's generally recommended to specify version ranges or pin specific versions.

Consider updating the [packages] section to include version ranges. For example:

[packages]
pydantic = ">=2.0,<3.0"
fastapi = ">=0.100.0,<1.0.0"
pydantic-settings = ">=2.0,<3.0"
mangum = ">=0.17.0,<1.0.0"
httpx = ">=0.24.0,<1.0.0"

This ensures compatibility while still allowing for minor updates and bug fixes.


[dev-packages]
pre-commit = "*"
pytest = "*"
black = "*"
flake8 = "*"
pylint = "*"
mypy = "*"
Comment on lines +13 to +19
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Dev dependencies align well with project needs; consider version specifications.

The development dependencies listed align well with the project's linting and testing needs, and they correspond to the configurations in .flake8 and .pre-commit-config.yaml.

For better reproducibility of the development environment, consider specifying version ranges for these packages as well. For example:

[dev-packages]
pre-commit = ">=3.0.0,<4.0.0"
pytest = ">=7.0.0,<8.0.0"
black = ">=23.0.0,<24.0.0"
flake8 = ">=6.0.0,<7.0.0"
pylint = ">=2.17.0,<3.0.0"
mypy = ">=1.0.0,<2.0.0"

This ensures consistent behavior across different development environments while still allowing for minor updates and bug fixes.


[requires]
python_version = "3.12"
572 changes: 572 additions & 0 deletions Pipfile.lock

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions examples/cli-base/setup.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
from setuptools import setup

with open('requirements.txt') as f:
with open("requirements.txt") as f:
required = f.read().splitlines()

with open('VERSION.txt') as f:
with open("VERSION.txt") as f:
version = f.read().splitlines()

setup(
name="python command base",
version=str(version),
py_modules=['src'],
py_modules=["src"],
package_dir={"": "src"},
install_requires=required,
author=', '.join(["mnq78"]),
author_email=', '.join(["matias.quiroga@nan-labs.com"]),
entry_points='''
author=", ".join(["mnq78"]),
author_email=", ".join(["matias.quiroga@nan-labs.com"]),
entry_points="""
[console_scripts]
pycmd=app:start
''',
""",
description="Developer tool CLI base.",
)
6 changes: 3 additions & 3 deletions examples/cli-base/src/app.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

import argparse


def start():
parser = argparse.ArgumentParser(description="Just an example",
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser = argparse.ArgumentParser(
description="Just an example", formatter_class=argparse.ArgumentDefaultsHelpFormatter
)
parser.add_argument("-v", "--verbose", action="store_true", help="increase verbosity")
parser.add_argument("-e", "--exclude", action="store_true", help="something to exclude")
args = parser.parse_args()
Expand Down
36 changes: 16 additions & 20 deletions examples/cli-typer-base/main.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from rich.console import Console
from rich.progress import track
from rich.style import errors as rich_style_errors
from tables.exchange import exchange_table_gen
from typer import Typer

from services.api_consumer import Exchange
from services.calculator import Calculator, CalculatorLogger
from services.input_wrapper import InputWrapper
from tables.exchange import exchange_table_gen
from typer import Typer

app = Typer()

Expand All @@ -23,10 +22,7 @@ def hello(name: str, color: str = "yellow"):


@app.command()
def currencies(
euro: bool = True,
official: bool = True
):
def currencies(euro: bool = True, official: bool = True):
"""Retrieves the values from an api
https://bluelytics.com.ar/#!/api and render the data in a table using rich.
"""
Expand All @@ -36,22 +32,22 @@ def currencies(
options = (euro, official)

match options:
case(True, False):
del exchange.data['oficial']
del exchange.data['oficial_euro']
case(False, True):
del exchange.data['oficial_euro']
del exchange.data['blue_euro']
case(False, False):
del exchange.data['oficial']
del exchange.data['oficial_euro']
del exchange.data['blue_euro']
case (True, False):
del exchange.data["oficial"]
del exchange.data["oficial_euro"]
case (False, True):
del exchange.data["oficial_euro"]
del exchange.data["blue_euro"]
case (False, False):
del exchange.data["oficial"]
del exchange.data["oficial_euro"]
del exchange.data["blue_euro"]

table = exchange_table_gen(exchange.data)
console = Console()
console.print(
":heavy_check_mark: :thumbs_up: :tada: :100: Last update:",
exchange.data["last_update"][:-6]
exchange.data["last_update"][:-6],
)
console.print(table)

Expand All @@ -68,7 +64,7 @@ def conversion(json_response: bool = False) -> None:
console.print_exception()
raise e
if json_response:
console.print_json(exchange.json_data.content.decode('utf8'))
console.print_json(exchange.json_data.content.decode("utf8"))

input = InputWrapper(exchange, console)

Expand All @@ -77,5 +73,5 @@ def conversion(json_response: bool = False) -> None:
CalculatorLogger(calculator)


if __name__ == '__main__':
if __name__ == "__main__":
app()
31 changes: 11 additions & 20 deletions examples/cli-typer-base/services/calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,26 @@
from entities.currencies import Currency, OperationType
from rich.style import Style
from rich.table import Table

from services.input_wrapper import ConversionParams


class Calculator:
def __init__(
self,
conversion_params: ConversionParams
) -> None:
def __init__(self, conversion_params: ConversionParams) -> None:
self.conversion_params = conversion_params

def _get_exchange_value(self) -> None:
match self.conversion_params.from_currency:
case Currency.ARS.value:
self.conversion_params.exchange = pow(
self.conversion_params.exchange
.get(self.conversion_params.to_currency)
.get(OperationType.SELL.value),
-1
self.conversion_params.exchange.get(self.conversion_params.to_currency).get(
OperationType.SELL.value
),
-1,
)
case _:
self.conversion_params.exchange = self.conversion_params.exchange \
.get(self.conversion_params.from_currency).get(OperationType.BUY.value)
self.conversion_params.exchange = self.conversion_params.exchange.get(
self.conversion_params.from_currency
).get(OperationType.BUY.value)

def convert(self) -> None:
self._get_exchange_value()
Expand All @@ -46,29 +43,23 @@ def logger(self) -> None:
justify="center",
width=30,
header_style=Style(color="blue", bold=True),
style=Style(
color="blue"
)
style=Style(color="blue"),
)
table.add_column(
"TO",
justify="center",
width=30,
header_style=Style(color="green", bold=True),
style=Style(
color="green",
bold=True
)
style=Style(color="green", bold=True),
)

table.add_row(
self.calculator.conversion_params.from_currency.upper(),
self.calculator.conversion_params.to_currency.upper(),

)
table.add_row(
str(self.calculator.conversion_params.amount),
str("%.2f" % self.calculator.converted_value)
str("%.2f" % self.calculator.converted_value),
)

console.print(table)
14 changes: 4 additions & 10 deletions examples/cli-typer-base/services/input_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from entities.currencies import CURRENCY_NAMES, Currency
from rich.console import Console

from services.api_consumer import Exchange


Expand Down Expand Up @@ -52,15 +51,13 @@ def _amount_input(self) -> None:
"Introduce the amount in "
f"{self._from_currency.name.upper()} "
f"to be converted to {self._to_currency.name.upper()}",
style="bold green"
style="bold green",
)
command = input("AMOUNT: ")
self._amount = float(command)

def wrap(self) -> ConversionParams:
while self._amount == 0 or \
not self._from_currency or \
not self._to_currency:
while self._amount == 0 or not self._from_currency or not self._to_currency:
try:
if not self._from_currency:
self._from_currency_input()
Expand All @@ -69,15 +66,12 @@ def wrap(self) -> ConversionParams:
if self._amount == 0:
self._amount_input()
except ValueError:
self._console.print(
"Invalid value, please try again",
style="bold red"
)
self._console.print("Invalid value, please try again", style="bold red")
continue
return ConversionParams(
exchange=self._exchange_data,
console=self._console,
amount=self._amount,
from_currency=self._from_currency.value,
to_currency=self._to_currency.value
to_currency=self._to_currency.value,
)
18 changes: 4 additions & 14 deletions examples/cli-typer-base/tables/exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def exchange_table_add_rows(data: dict, table: Table) -> Table:
key.upper(),
"AR$ " + str(value["value_buy"]),
"AR$ " + str(value["value_sell"]),
end_section=True
end_section=True,
)
return table

Expand All @@ -23,30 +23,20 @@ def exchange_table_gen(data: dict) -> Table:
justify="center",
width=30,
header_style=Style(color="green", bold=True),
style=Style(
color="green",
bold=True
)
style=Style(color="green", bold=True),
)
table.add_column(
"Buy price",
justify="center",
width=15,
header_style=Style(color="red", bold=True),
style=Style(
bgcolor="white",
color="Red"
)
style=Style(bgcolor="white", color="Red"),
)
table.add_column(
"Sell price",
justify="center",
width=15,
header_style=Style(color="blue", bold=True),
style=Style(
bgcolor="white",
blink=True,
color="blue"
)
style=Style(bgcolor="white", blink=True, color="blue"),
)
return exchange_table_add_rows(data, table)
3 changes: 1 addition & 2 deletions examples/fastapi-base/src/controllers/users_controller.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from fastapi import APIRouter, status

from models.user_model import Users, UsersList
from services.user_service import UsersService

Expand Down Expand Up @@ -42,7 +41,7 @@ async def put_user(user_id: int) -> Users:
status_code=status.HTTP_200_OK,
response_model=Users,
name="Update User by Id",
deprecated=True
deprecated=True,
)
async def dep_get_user_by_id(user_id: int) -> Users:
return user_service.get_user(user_id)
2 changes: 1 addition & 1 deletion examples/fastapi-base/src/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from starlette.config import Config

ROOT_DIR = os.getcwd()
_config = Config(os.path.join(ROOT_DIR, '.env'))
_config = Config(os.path.join(ROOT_DIR, ".env"))

# API info
APP_VERSION = "0.0.1"
Expand Down
1 change: 0 additions & 1 deletion examples/fastapi-base/src/factories/user_factory.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import factory
from faker import Factory

from models.user_model import Users

faker = Factory.create()
Expand Down
Loading
Loading