diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..85618f1 --- /dev/null +++ b/.envrc @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +use flake + +# Add venv bin to PATH so development tools can be invoked more easily +PATH_add .venv/bin + +# Add src to PYTHONPATH so Python and tools can find imports correctly +path_add PYTHONPATH src + +# Add venv site packages to PYTHONPATH so imports work +path_add PYTHONPATH ".venv/$NIX_PYTHON_SITE_PACKAGES" + +# Make pip use the venv (useful for ad-hoc temporary package installation) +PIP_PREFIX="$(expand_path .)/.venv" +export PIP_PREFIX +export PIP_IGNORE_INSTALLED=1 + +# These are annoying so stuff them all in one place +PYTHONPYCACHEPREFIX="$(expand_path .)/.pycache" +export PYTHONPYCACHEPREFIX diff --git a/.gitignore b/.gitignore index 8584735..92d0da7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,14 @@ -build -__pycache__ -*.egg-info +# Python artifacts +/.coverage +/.pycache +/.pytest_cache +/.venv +/dist +/build +/*.egg-info + +# Direnv cache +/.direnv + +# Nix artifacts +/result diff --git a/beangrow/compute_returns.py b/beangrow/compute_returns.py index 7faabb9..bb4119d 100755 --- a/beangrow/compute_returns.py +++ b/beangrow/compute_returns.py @@ -87,7 +87,7 @@ def main(): prices.build_price_map(entries), end_date, output_reports, - args.parallel, args.pdf) + parallel=args.parallel, pdf=args.pdf) # Generate price reports. output_prices = path.join(args.output, "prices") diff --git a/beangrow/reports.py b/beangrow/reports.py index 75dbe92..0fb4d7d 100755 --- a/beangrow/reports.py +++ b/beangrow/reports.py @@ -1,45 +1,42 @@ #!/usr/bin/env python3 -"""Calculate my true returns, including dividends and real costs. +""" +Calculate my true returns, including dividends and real costs. """ __copyright__ = "Copyright (C) 2020 Martin Blais" __license__ = "GNU GPLv2" -from os import path -from typing import Any, Dict, List, Tuple, Optional -from functools import partial import collections import datetime import io import logging import multiprocessing -import os import platform import subprocess import tempfile import typing +from functools import partial +from pathlib import Path +from typing import Any, Dict, List, Optional, Tuple -from dateutil.relativedelta import relativedelta -import numpy as np - -import matplotlib.pyplot as plt import matplotlib.dates as mdates -import pandas -from pandas.plotting import register_matplotlib_converters -register_matplotlib_converters() - -from beancount.core import data -from beancount.core import prices +import matplotlib.pyplot as plt +import numpy as np +import pandas as pd +from beancount.core import data, prices from beancount.core.amount import Amount from beancount.parser import printer +from dateutil.relativedelta import relativedelta +from matplotlib.axes import Axes +from pandas.plotting import register_matplotlib_converters -from beangrow.config_pb2 import Config, Group -from beangrow.investments import AccountData -from beangrow.investments import CashFlow from beangrow import investments from beangrow import returns as returnslib +from beangrow.config_pb2 import Config, Group +from beangrow.investments import AccountData, CashFlow from beangrow.returns import Pricer +register_matplotlib_converters() # Basic type aliases. Account = str @@ -81,7 +78,8 @@