Skip to content

Commit 63af12b

Browse files
committed
Add command line tool
1 parent a510f2b commit 63af12b

File tree

11 files changed

+1259
-1082
lines changed

11 files changed

+1259
-1082
lines changed

.github/workflows/build.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
1818
strategy:
1919
matrix:
20-
python-version: ["3.10", "3.11", "3.12-dev"]
20+
python-version: ["3.10", "3.11", "3.12"]
2121

2222
steps:
2323
- uses: actions/checkout@v3
@@ -34,7 +34,7 @@ jobs:
3434
- name: run tests
3535
run: make test
3636
- name: upload coverage reports to codecov
37-
if: matrix.python-version == '3.11'
37+
if: matrix.python-version == '3.12'
3838
uses: codecov/codecov-action@v3
3939
with:
4040
token: ${{ secrets.CODECOV_TOKEN }}
@@ -48,10 +48,10 @@ jobs:
4848
- build
4949
steps:
5050
- uses: actions/checkout@v3
51-
- name: Set up Python 3.11
51+
- name: Set up Python 3.12
5252
uses: actions/setup-python@v3
5353
with:
54-
python-version: "3.11"
54+
python-version: "3.12"
5555
- name: Install dependencies
5656
run: make install-dev
5757
- name: build book

Makefile

+18-10
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,53 @@
1-
.PHONY: help clean docs install-dev lint lint-check test publish notebook book publish-book
21

2+
.PHONY: help
33
help:
44
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//'
55

6-
clean: ## remove python cache files
6+
.PHONY: clean
7+
clean: ## Remove python cache files
78
find . -name '__pycache__' | xargs rm -rf
89
find . -name '*.pyc' -delete
910
rm -rf build
1011
rm -rf dist
1112
rm -rf .pytest_cache
1213
rm -rf .coverage
1314

14-
15-
docs: ## build docs
15+
.PHONY: docs
16+
docs: ## Build docs
1617
cd docs && make docs
1718

18-
install-dev: ## install packages for development
19+
.PHONY: install-dev
20+
install-dev: ## Install packages for development
1921
@./dev/install
2022

23+
.PHONY: lint
2124
lint: ## Run linters
2225
@poetry run ./dev/lint fix
2326

24-
27+
.PHONY: lint-check
2528
lint-check: ## Run linters in check mode
2629
@poetry run ./dev/lint
2730

28-
29-
test: ## test with python 3.8 with coverage
31+
.PHONY: test
32+
test: ## Test with python 3.8 with coverage
3033
@poetry run pytest -x -v --cov --cov-report xml
3134

32-
publish: ## release to pypi and github tag
35+
.PHONY: publish
36+
publish: ## Release to pypi and github tag
3337
@poetry publish --build -u lsbardel -p $(PYPI_PASSWORD)
3438

39+
.PHONY: notebook
3540
notebook: ## Run Jupyter notebook server
3641
@poetry run ./dev/start-jupyter 9095
3742

43+
.PHONY: book
3844
book: ## Build static jupyter {book}
3945
poetry run jupyter-book build docs --all
4046

41-
publish-book: ## publish the book to github pages
47+
.PHONY: publish-book
48+
publish-book: ## Publish the book to github pages
4249
poetry run ghp-import -n -p -f docs/_build/html
4350

51+
.PHONY: outdated
4452
outdated: ## Show outdated packages
4553
poetry show -o -a

ccy/cli/__init__.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import click
2+
import pandas as pd
3+
from rich.console import Console
4+
5+
import ccy
6+
7+
from .console import df_to_rich
8+
9+
10+
@click.group()
11+
def ccys() -> None:
12+
"""Currency commands."""
13+
14+
15+
@ccys.command()
16+
def show() -> None:
17+
"""Show table with all currencies."""
18+
df = pd.DataFrame(ccy.dump_currency_table())
19+
console = Console()
20+
console.print(df_to_rich(df, exclude=("symbol_raw",)))

ccy/cli/console.py

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import pandas as pd
2+
from rich.table import Table
3+
4+
set_alike = set[str] | frozenset[str] | tuple[str] | list[str] | None
5+
6+
7+
def df_to_rich(
8+
df: pd.DataFrame, *, exclude: set_alike = None, **columns: dict
9+
) -> Table:
10+
table = Table()
11+
if exclude_columns := set(exclude or ()):
12+
df = df.drop(columns=exclude_columns)
13+
for column in df.columns:
14+
config = dict(justify="right", style="cyan", no_wrap=True)
15+
config.update(columns.get(column) or {})
16+
table.add_column(column, **config) # type: ignore[arg-type]
17+
for row in df.values:
18+
table.add_row(*[str(item) for item in row])
19+
return table

ccy/core/currency.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ def description(self) -> str:
5959
return "Dollar"
6060

6161
def info(self) -> dict[str, Any]:
62-
return self._asdict()
62+
data = self._asdict()
63+
data["symbol"] = self.symbol
64+
return data
6365

6466
def printinfo(self, stream: Any | None = None) -> None:
6567
info = self.info()
@@ -205,7 +207,7 @@ def make_ccypairs() -> dict[str, ccy_pair]:
205207

206208

207209
def dump_currency_table() -> list:
208-
return [c._asdict() for c in sorted(currencydb().values(), key=lambda x: x.order)]
210+
return [c.info() for c in sorted(currencydb().values(), key=lambda x: x.order)]
209211

210212

211213
_ccys: ccydb = ccydb()

ccy/core/data.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -434,12 +434,12 @@ def make_ccys(db: ccydb) -> None:
434434
"985",
435435
"PZ",
436436
29,
437-
"Polish Zloty",
437+
"Polish Złoty",
438438
dfr,
439439
"PL",
440440
"ACT/ACT",
441441
"ACT/365",
442-
symbol_raw=r"\u0050\u0142",
442+
symbol_raw=r"\u007a\u0142",
443443
)
444444
insert(
445445
"TRY",

ccy/core/daycounter.py

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* 30 / 360
77
* Actual Actual
88
"""
9+
910
from __future__ import annotations
1011

1112
from copy import copy

dev/lint

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ fi
1212
echo "run black"
1313
black ccy tests --exclude "fluid_common/protos/v2|fluid_apps/db/migrations" ${BLACK_ARG}
1414
echo "run ruff"
15-
ruff ccy tests ${RUFF_ARG}
15+
ruff check ccy tests ${RUFF_ARG}
1616
echo "run mypy"
1717
mypy ccy

0 commit comments

Comments
 (0)