Skip to content

Commit

Permalink
replace black with ruff-format
Browse files Browse the repository at this point in the history
  • Loading branch information
codereverser committed Dec 21, 2024
1 parent 1e40844 commit 6785945
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 133 deletions.
11 changes: 4 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
repos:
- repo: 'https://github.com/pre-commit/pre-commit-hooks'
rev: v4.4.0
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.287
rev: v0.8.4
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: 'https://github.com/psf/black'
rev: 23.7.0
hooks:
- id: black
- id: ruff-format
9 changes: 5 additions & 4 deletions casparser/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from rich.prompt import Prompt
from rich.table import Table

from . import read_cas_pdf, __version__
from . import __version__, read_cas_pdf
from .analysis.gains import CapitalGainsReport
from .enums import CASFileType
from .exceptions import GainsError, IncompleteCASError, ParserException
Expand Down Expand Up @@ -146,8 +146,9 @@ def print_summary(parsed_data: CASData, output_filename=None, include_zero_folio
console_row = {
"scheme": scheme_name,
"open": scheme["open"],
"close": format_number(scheme_close) if is_summary
else f"{format_number(scheme_close)}\n/\n{calc_close}",
"close": format_number(scheme_close)
if is_summary
else f"{format_number(scheme_close)}\n/\n{calc_close}",
"value": f"{formatINR(valuation['value'])}\n@\n{formatINR(valuation['nav'])}",
"txns": len(scheme["transactions"]),
"status": status,
Expand Down Expand Up @@ -384,4 +385,4 @@ def cli(output, summary, password, include_all, gains, gains_112a, force_pdfmine


if __name__ == "__main__":
cli(prog_name="casparser")
cli(prog_name="casparser")
4 changes: 2 additions & 2 deletions casparser/process/cas_detailed.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
DESCRIPTION_TAIL_RE,
DETAILED_DATE_RE,
DIVIDEND_RE,
FOLIO_RE,
FOLIO_KV_RE,
FOLIO_RE,
NAV_RE,
NOMINEE_RE,
OPEN_UNITS_RE,
REGISTRAR_RE,
SCHEME_RE,
SCHEME_KV_RE,
SCHEME_RE,
TRANSACTION_RE1,
TRANSACTION_RE2,
TRANSACTION_RE3,
Expand Down
106 changes: 19 additions & 87 deletions poetry.lock

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

27 changes: 15 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ python = "^3.10"
casparser-isin = ">=2024.5.12"
click = ">=7.0,<9.0"
colorama = "^0.4.6"
"pdfminer.six" = "20221105"
"pdfminer.six" = "20240706"
python-dateutil = "^2.8.2"
rich = "^13.5.2"
pydantic = "^2.3.0"
Expand All @@ -32,18 +32,15 @@ mupdf = ["PyMuPDF"]
fast = ["PyMuPDF"]

[tool.poetry.dev-dependencies]
coverage = {version = "^7.1", extras=["toml"]}
ipython = "^8.1.0"
pytest = "^7.4.0"
pytest-cov = "^4.1.0"
coverage = {version = "^7.6", extras=["toml"]}
ipython = "^8.31.0"
pytest = "~8.3.0"
pytest-cov = "~6.0.0"
pre-commit = "^4.0.0"

[tool.poetry.scripts]
casparser = 'casparser.cli:cli'

[tool.poetry.group.dev.dependencies]
black = "^23.3.0"

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
Expand All @@ -69,10 +66,16 @@ omit = [
[tool.poetry-version-plugin]
source = "init"

[tool.black]
line-length = 100
target-version = ['py38']

[tool.ruff]
line-length = 100
target-version = "py38"


[tool.ruff.lint]
select = ["E", "F", "I"]

[tool.ruff.format]
quote-style = "double"
indent-style = "space"
skip-magic-trailing-comma = false
line-ending = "auto"
5 changes: 3 additions & 2 deletions tests/test_mupdf.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import re

import fitz
from click.testing import CliRunner
import pytest
from click.testing import CliRunner

from casparser.exceptions import CASParseError
from casparser.enums import FileType
from casparser.exceptions import CASParseError

from .base import BaseTestClass


Expand Down
3 changes: 2 additions & 1 deletion tests/test_pdfminer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from pdfminer.layout import LTTextBoxHorizontal
import pytest
from pdfminer.layout import LTTextBoxHorizontal

from casparser.exceptions import CASParseError

from .base import BaseTestClass


Expand Down
55 changes: 37 additions & 18 deletions tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@

import pytest

from casparser.enums import TransactionType
from casparser.exceptions import CASParseError, HeaderParseError
from casparser.process import process_cas_text
from casparser.process.cas_detailed import parse_header, get_transaction_type, get_parsed_scheme_name
from casparser.process.cas_detailed import ParsedTransaction, parse_transaction
from casparser.process.cas_detailed import (
ParsedTransaction,
get_parsed_scheme_name,
get_transaction_type,
parse_header,
parse_transaction,
)
from casparser.process.cas_summary import parse_header as parse_summary_header
from casparser.process.utils import isin_search
from casparser.enums import TransactionType


class TestProcessClass:
Expand Down Expand Up @@ -95,21 +100,35 @@ def test_dividend_transactions(self):
)

def test_parsed_scheme_name(self):
assert get_parsed_scheme_name(
"Axis Long Term Equity Fund - Direct Growth") == "Axis Long Term Equity Fund - Direct Growth"
assert get_parsed_scheme_name(
"Axis Bluechip Fund - Regular Growth ") == "Axis Bluechip Fund - Regular Growth"
assert get_parsed_scheme_name(
"HSBC Corporate Bond Fund - Regular Growth (Formerly known as L&T Triple Ace Bond Fund - Growth)") == \
"HSBC Corporate Bond Fund - Regular Growth"
assert get_parsed_scheme_name(
"Bandhan ELSS Tax saver Fund-Growth-(Regular Plan)"
"(erstwhile Bandhan Tax Advantage ELSS Fund-Growth-Regular Plan)") == \
"Bandhan ELSS Tax saver Fund-Growth-(Regular Plan)"
assert get_parsed_scheme_name(
"Bandhan Liquid Fund-Growth-(Regular Plan) (erstwhile IDFC Cash Fund-Growth-Regular Plan) (Non-Demat) ") == \
"Bandhan Liquid Fund-Growth-(Regular Plan)"

assert (
get_parsed_scheme_name("Axis Long Term Equity Fund - Direct Growth")
== "Axis Long Term Equity Fund - Direct Growth"
)
assert (
get_parsed_scheme_name("Axis Bluechip Fund - Regular Growth ")
== "Axis Bluechip Fund - Regular Growth"
)
assert (
get_parsed_scheme_name(
"HSBC Corporate Bond Fund - Regular Growth "
"(Formerly known as L&T Triple Ace Bond Fund - Growth)"
)
== "HSBC Corporate Bond Fund - Regular Growth"
)
assert (
get_parsed_scheme_name(
"Bandhan ELSS Tax saver Fund-Growth-(Regular Plan)"
"(erstwhile Bandhan Tax Advantage ELSS Fund-Growth-Regular Plan)"
)
== "Bandhan ELSS Tax saver Fund-Growth-(Regular Plan)"
)
assert (
get_parsed_scheme_name(
"Bandhan Liquid Fund-Growth-(Regular Plan) "
"(erstwhile IDFC Cash Fund-Growth-Regular Plan) (Non-Demat) "
)
== "Bandhan Liquid Fund-Growth-(Regular Plan)"
)

def test_isin_search(self):
isin, amfi, scheme_type = isin_search(
Expand Down

0 comments on commit 6785945

Please sign in to comment.