Skip to content

Commit

Permalink
Add command line tool
Browse files Browse the repository at this point in the history
  • Loading branch information
lsbardel committed Mar 24, 2024
1 parent a510f2b commit 63af12b
Show file tree
Hide file tree
Showing 11 changed files with 1,259 additions and 1,082 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
strategy:
matrix:
python-version: ["3.10", "3.11", "3.12-dev"]
python-version: ["3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v3
Expand All @@ -34,7 +34,7 @@ jobs:
- name: run tests
run: make test
- name: upload coverage reports to codecov
if: matrix.python-version == '3.11'
if: matrix.python-version == '3.12'
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
Expand All @@ -48,10 +48,10 @@ jobs:
- build
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.11
- name: Set up Python 3.12
uses: actions/setup-python@v3
with:
python-version: "3.11"
python-version: "3.12"
- name: Install dependencies
run: make install-dev
- name: build book
Expand Down
28 changes: 18 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,45 +1,53 @@
.PHONY: help clean docs install-dev lint lint-check test publish notebook book publish-book

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

clean: ## remove python cache files
.PHONY: clean
clean: ## Remove python cache files
find . -name '__pycache__' | xargs rm -rf
find . -name '*.pyc' -delete
rm -rf build
rm -rf dist
rm -rf .pytest_cache
rm -rf .coverage


docs: ## build docs
.PHONY: docs
docs: ## Build docs
cd docs && make docs

install-dev: ## install packages for development
.PHONY: install-dev
install-dev: ## Install packages for development
@./dev/install

.PHONY: lint
lint: ## Run linters
@poetry run ./dev/lint fix


.PHONY: lint-check
lint-check: ## Run linters in check mode
@poetry run ./dev/lint


test: ## test with python 3.8 with coverage
.PHONY: test
test: ## Test with python 3.8 with coverage
@poetry run pytest -x -v --cov --cov-report xml

publish: ## release to pypi and github tag
.PHONY: publish
publish: ## Release to pypi and github tag
@poetry publish --build -u lsbardel -p $(PYPI_PASSWORD)

.PHONY: notebook
notebook: ## Run Jupyter notebook server
@poetry run ./dev/start-jupyter 9095

.PHONY: book
book: ## Build static jupyter {book}
poetry run jupyter-book build docs --all

publish-book: ## publish the book to github pages
.PHONY: publish-book
publish-book: ## Publish the book to github pages
poetry run ghp-import -n -p -f docs/_build/html

.PHONY: outdated
outdated: ## Show outdated packages
poetry show -o -a
20 changes: 20 additions & 0 deletions ccy/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import click
import pandas as pd
from rich.console import Console

import ccy

from .console import df_to_rich


@click.group()
def ccys() -> None:
"""Currency commands."""


@ccys.command()
def show() -> None:
"""Show table with all currencies."""
df = pd.DataFrame(ccy.dump_currency_table())
console = Console()
console.print(df_to_rich(df, exclude=("symbol_raw",)))
19 changes: 19 additions & 0 deletions ccy/cli/console.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import pandas as pd
from rich.table import Table

set_alike = set[str] | frozenset[str] | tuple[str] | list[str] | None


def df_to_rich(
df: pd.DataFrame, *, exclude: set_alike = None, **columns: dict
) -> Table:
table = Table()
if exclude_columns := set(exclude or ()):
df = df.drop(columns=exclude_columns)
for column in df.columns:
config = dict(justify="right", style="cyan", no_wrap=True)
config.update(columns.get(column) or {})
table.add_column(column, **config) # type: ignore[arg-type]
for row in df.values:
table.add_row(*[str(item) for item in row])
return table
6 changes: 4 additions & 2 deletions ccy/core/currency.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ def description(self) -> str:
return "Dollar"

def info(self) -> dict[str, Any]:
return self._asdict()
data = self._asdict()
data["symbol"] = self.symbol
return data

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


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


_ccys: ccydb = ccydb()
Expand Down
4 changes: 2 additions & 2 deletions ccy/core/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,12 +434,12 @@ def make_ccys(db: ccydb) -> None:
"985",
"PZ",
29,
"Polish Zloty",
"Polish Złoty",
dfr,
"PL",
"ACT/ACT",
"ACT/365",
symbol_raw=r"\u0050\u0142",
symbol_raw=r"\u007a\u0142",
)
insert(
"TRY",
Expand Down
1 change: 1 addition & 0 deletions ccy/core/daycounter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* 30 / 360
* Actual Actual
"""

from __future__ import annotations

from copy import copy
Expand Down
2 changes: 1 addition & 1 deletion dev/lint
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ fi
echo "run black"
black ccy tests --exclude "fluid_common/protos/v2|fluid_apps/db/migrations" ${BLACK_ARG}
echo "run ruff"
ruff ccy tests ${RUFF_ARG}
ruff check ccy tests ${RUFF_ARG}
echo "run mypy"
mypy ccy

0 comments on commit 63af12b

Please sign in to comment.