Skip to content

Commit

Permalink
Merge pull request #7 from staticdev/feature/new-interface-prompt-too…
Browse files Browse the repository at this point in the history
…lkit

New interface prompt toolkit
  • Loading branch information
staticdev committed Jan 2, 2022
2 parents 9d0f64d + 9474952 commit 900f730
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 149 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
/docs/_build/
/src/*.egg-info/
__pycache__/
*.xls

# Pycharm
.idea/
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Instale na sua máquina o Python 3.8.0 ou superior (versão 3.10 recomendada) pa

Usuários do Windows devem baixar a versão `Windows x86-64 executable installer` e na tela de instalação marcar a opção `Add Python 3.8 to PATH`:

.. image:: docs/_images/winpath.png
.. image:: docs/images/winpath.png
:width: 400
:alt: Checkbox PATH na instalação Windows

Expand Down
Binary file added docs/images/winpath.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def coverage(session: Session) -> None:
session.run("coverage", *args)


@session(python=python_versions)
@session(python=python_versions[0])
def typeguard(session: Session) -> None:
"""Runtime type checking using Typeguard."""
session.install(".")
Expand All @@ -174,7 +174,7 @@ def xdoctest(session: Session) -> None:
session.run("python", "-m", "xdoctest", *args)


@session(name="docs-build", python="3.10")
@session(name="docs-build", python=python_versions[0])
def docs_build(session: Session) -> None:
"""Build the documentation."""
args = session.posargs or ["docs", "docs/_build"]
Expand All @@ -191,7 +191,7 @@ def docs_build(session: Session) -> None:
session.run("sphinx-build", *args)


@session(python="3.10")
@session(python=python_versions[0])
def docs(session: Session) -> None:
"""Build and serve the documentation with live reloading on file changes."""
args = session.posargs or ["--open-browser", "docs", "docs/_build"]
Expand Down
105 changes: 16 additions & 89 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "irpf-investidor"
version = "2022.1"
version = "2021.1"
description = "IRPF Investidor"
authors = ["staticdev <staticdev-support@protonmail.com>"]
license = "MIT"
Expand All @@ -19,8 +19,8 @@ Changelog = "https://github.com/staticdev/irpf-investidor/releases"
python = ">=3.8,<4.0"
click = ">=8.0.1"
pandas = ">=1.3.5"
prompt-toolkit = ">=3.0.24"
xlrd = ">=2.0.1"
inquirer = ">=2.9.1"

[tool.poetry.dev-dependencies]
Pygments = ">=2.10.0"
Expand Down Expand Up @@ -73,7 +73,7 @@ show_error_codes = true
show_error_context = true

[[tool.mypy.overrides]]
module = ["inquirer", "pandas", "pytest_mock", "xlrd"]
module = ["pandas", "pytest_mock", "xlrd"]
ignore_missing_imports = true

[build-system]
Expand Down
9 changes: 0 additions & 9 deletions src/irpf_investidor/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,6 @@ def main() -> None:
source_df = irpf_investidor.report_reader.clean_table_cols(source_df)
source_df = irpf_investidor.report_reader.group_trades(source_df)
trades = irpf_investidor.report_reader.get_trades(source_df)

click.secho(
(
"Para o cálculo dos emolumentos é necessário informar operações"
"realizadas em horário de leilão. Essa informação é obtida com "
"a sua corretora através de relatórios de ordem de compra."
),
fg="green",
)
auction_trades = prompt.select_trades(trades)
tax_df = irpf_investidor.report_reader.calculate_taxes(source_df, auction_trades)
irpf_investidor.report_reader.output_taxes(tax_df)
Expand Down
50 changes: 21 additions & 29 deletions src/irpf_investidor/prompt.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,36 @@
"""Prompt module."""
from __future__ import annotations

from typing import Any
import prompt_toolkit.shortcuts as shortcuts

import inquirer

TITLE = "IRPF Investidor"

def select_trades(trades: list[tuple[str, int]]) -> Any:

def select_trades(trades: list[tuple[int, str]]) -> list[int]:
"""Checkbox selection of auction trades.
Args:
trades (list[tuple[str, int]]): list of all trades and indexes.
trades: list of all trades and indexes.
Returns:
Any: list of indexes of selected auction trades.
list of string indexes of selected auction trades.
"""
text = (
"Informe as operações realizadas em horário de leilão para cálculo dos "
"emolumentos.\nEssa informação é obtida através de sua corretora."
)
while True:
selection = inquirer.prompt(
[
inquirer.Checkbox(
"trades",
message=(
"Quais operações foram realizadas em horário de leilão? "
"(Selecione apertando espaço e ao terminar aperte enter)"
),
choices=trades,
)
]
)["trades"]
if len(selection) == 0:
answer = inquirer.prompt(
[
inquirer.List(
"",
message="Nenhuma operação selecionada.\nIsso está correto?",
choices=["Sim", "Não"],
)
]
)[""]
if answer == "Sim":
operations: list[int] = shortcuts.checkboxlist_dialog(
title=TITLE,
text=text,
values=trades, # type: ignore
).run()
if not operations or len(operations) == 0:
confirmed = shortcuts.yes_no_dialog(
title=TITLE, text="Nenhuma operação selecionada.\nIsso está correto?"
).run()
if confirmed:
return []
else:
return selection
return operations
4 changes: 2 additions & 2 deletions src/irpf_investidor/report_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def clean_table_cols(source_df: pd.DataFrame) -> pd.DataFrame:
return source_df.dropna(axis="columns", how="all")


def get_trades(df: pd.DataFrame) -> list[tuple[str, int]]:
def get_trades(df: pd.DataFrame) -> list[tuple[int, str]]:
"""Return trades representations.
Args:
Expand All @@ -147,7 +147,7 @@ def get_trades(df: pd.DataFrame) -> list[tuple[str, int]]:
df = df.drop(columns=["Valor Total (R$)"])
list_of_list = df.astype(str).values.tolist()
df = df.drop(columns=["total_cost_rs"])
return [(" ".join(x), i) for i, x in enumerate(list_of_list)]
return [(i, " ".join(x)) for i, x in enumerate(list_of_list)]


def group_trades(df: pd.DataFrame) -> pd.DataFrame:
Expand Down

0 comments on commit 900f730

Please sign in to comment.