Skip to content

Commit 611f3f3

Browse files
better modularization
- pin docker dependency - fix errors - fetch-tags: true - fetch-depth in bump-update=0 actions/checkout#1471 - setup uv
1 parent 2c44d67 commit 611f3f3

21 files changed

+622
-130
lines changed

.dockerignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
assets/sample_data.json
2+
sgb_advisor.log
3+
14
tmp/
25
output/
36
testing.py
47
test.py
58
*.log
69
.python-version
710
pyproject.toml
11+
py.typed
812

913
.git
1014
.github
@@ -13,7 +17,6 @@ Dockerfile
1317
.dockerignore
1418
uv.lock
1519
.pre-commit-config.yaml
16-
build-and-run.sh
1720

1821
# python generated files
1922
__pycache__/

.github/workflows/bump-patch-version.yml

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,67 @@ permissions:
44
contents: none
55
on:
66
schedule:
7-
- cron: "30 10 20 11/6 *" # 20th of every November and May at 10:30 UTC
7+
- cron: "30 10 27 5/5 *" # 20th of every November and May at 10:30 UTC
88
workflow_dispatch:
99

1010
jobs:
1111
bump-patch-version:
1212
name: Bump project version
1313
runs-on: ubuntu-latest
1414
permissions:
15-
contents: read
15+
contents: write
1616
steps:
1717
- name: Checkout the repo ⬇️
1818
uses: actions/checkout@v4
1919
with:
20-
fetch-depth: 1
20+
fetch-depth: 0 # actions/checkout#1471
21+
fetch-tags: true
22+
23+
- name: Setup uv ⛏️
24+
uses: astral-sh/setup-uv@f0ec1fc3b38f5e7cd731bb6ce540c5af426746bb
2125

2226
- name: Bump patch version 🔧
2327
run: |
24-
# If triggered by schedule, bump the patch version to not conflict with the tag version
25-
# and to ensure that the version is always incremented.
28+
export SGB_ADVISOR_CURRENT_RELEASE_VERSION="v`uv version --short`"
29+
30+
echo "> echo \${SGB_ADVISOR_CURRENT_RELEASE_VERSION}"
31+
echo "${SGB_ADVISOR_CURRENT_RELEASE_VERSION}"
32+
33+
if [[ ${SGB_ADVISOR_CURRENT_RELEASE_VERSION} == "v" ]]; then
34+
echo "Current version ('${SGB_ADVISOR_CURRENT_RELEASE_VERSION}') could not be properly determined."
35+
exit 1
36+
fi
37+
38+
echo "> git tag"
39+
git tag
40+
echo "> git describe --tags $(git rev-list --tags --max-count=1)"
41+
git describe --tags $(git rev-list --tags --max-count=1)
42+
43+
if [[ ${SGB_ADVISOR_CURRENT_RELEASE_VERSION} != "`git describe --tags $(git rev-list --tags --max-count=1)`" ]]; then
44+
echo "Current version ('${SGB_ADVISOR_CURRENT_RELEASE_VERSION}') has not been tagged yet. Skipping the version bump."
45+
exit 0
46+
fi
47+
48+
# Bump patch version
2649
uv version --bump patch
50+
uv lock --upgrade
51+
uv export --no-default-groups --quiet --no-emit-project --format requirements-txt --output-file requirements.txt
52+
2753
export SGB_ADVISOR_BUMPED_RELEASE_VERSION="v`uv version --short`"
54+
55+
echo "> echo \${SGB_ADVISOR_BUMPED_RELEASE_VERSION}"
56+
echo "${SGB_ADVISOR_BUMPED_RELEASE_VERSION}"
57+
2858
if [[ ${SGB_ADVISOR_BUMPED_RELEASE_VERSION} == "v" ]]; then
29-
echo "Exiting because the version is not set properly"
59+
echo "Exiting because '${SGB_ADVISOR_BUMPED_RELEASE_VERSION}' is not a valid release version."
3060
exit 1
3161
fi
32-
git tag -a -m "Bumped version to ${SGB_ADVISOR_BUMPED_RELEASE_VERSION} "${SGB_ADVISOR_BUMPED_RELEASE_VERSION}"
62+
63+
# Tag and push the new version
64+
git config user.name github-actions
65+
git config user.email github-actions@github.com
66+
git add . -v pyproject.toml uv.lock requirements.txt
67+
git commit -m "Bump patch version to ${SGB_ADVISOR_BUMPED_RELEASE_VERSION}"
68+
git push origin master
69+
git tag -a -m "Bumped version to ${SGB_ADVISOR_BUMPED_RELEASE_VERSION}" "${SGB_ADVISOR_BUMPED_RELEASE_VERSION}"
3370
git push origin tag "${SGB_ADVISOR_BUMPED_RELEASE_VERSION}"

.github/workflows/create-docker-image.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ jobs:
1313
permissions:
1414
contents: read
1515
packages: write
16+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
1617
steps:
1718
- name: Checkout the repo ⬇️
1819
uses: actions/checkout@v4
1920
with:
2021
fetch-depth: 1
2122

2223
- name: Login to GitHub Container Registry 📖
23-
uses: docker/login-action@v3
24+
uses: docker/login-action@74a5d142397b4f367a81961eba4e8cd7edddf772
2425
with:
2526
registry: ghcr.io
2627
username: ${{ github.actor }}

.github/workflows/publish-pypi.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ jobs:
3131
python-version-file: ".python-version"
3232

3333
- name: Setup uv 🔧
34-
uses: astral-sh/setup-uv@6b9c6063abd6010835644d4c2e1bef4cf5cd0fca
34+
uses: astral-sh/setup-uv@f0ec1fc3b38f5e7cd731bb6ce540c5af426746bb
3535
with:
3636
enable-cache: true
3737

3838
- name: Install dependencies ⬇️ 📦
3939
run: |
40-
uv sync --no-default-groups --locked
40+
uv sync --only-group build --frozen
4141
4242
- name: Build package 👷‍♂️
4343
run: |

.pre-commit-config.yaml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,15 @@ repos:
99
- id: check-merge-conflict
1010
- id: check-symlinks
1111
- repo: https://github.com/astral-sh/uv-pre-commit
12-
# uv version.
13-
rev: 0.7.3
12+
rev: 0.7.5
1413
hooks:
1514
# Update the uv lockfile
1615
- id: uv-lock
1716
- id: uv-export
18-
# uv export --no-group dev --quiet --no-emit-project --format requirements-txt --output-file requirements.txt
17+
# uv export --no-default-groups --quiet --no-emit-project --format requirements-txt --output-file requirements.txt
1918
args:
2019
[
21-
"--no-group",
22-
"dev",
20+
"--no-default-groups",
2321
"--quiet",
2422
"--no-emit-project",
2523
"--format",
@@ -28,8 +26,7 @@ repos:
2826
"requirements.txt",
2927
]
3028
- repo: https://github.com/astral-sh/ruff-pre-commit
31-
# Ruff version.
32-
rev: v0.11.9
29+
rev: v0.11.10
3330
hooks:
3431
# Run the linter.
3532
- id: ruff

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ LABEL \
2424
org.opencontainers.image.title="SGB Advisor" \
2525
org.opencontainers.image.authors="Vishal Nandagopal (dev@vishalnandagopal.com)" \
2626
org.opencontainers.image.description="A tool to analyse Sovereign Gold Bonds and compare their yields" \
27-
org.opencontainers.image.source="https://github.com/vishalnandagopal/sgb-advisor.git" \
2827
org.opencontainers.image.url="https://github.com/vishalnandagopal/sgb-advisor" \
28+
org.opencontainers.image.source="https://github.com/vishalnandagopal/sgb-advisor.git" \
2929
org.opencontainers.image.documentation="https://github.com/vishalnandagopal/sgb-advisor/blob/master/README.md#running-the-app" \
30-
org.opencontainers.image.licenses="MIT"
30+
org.opencontainers.image.licenses="GPL-3.0-only"
3131

3232
ENTRYPOINT ["python3", "app.py"]

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This tool tries to use publically available data and ✨maths✨ to advise you o
88

99
**This does not recommend anything. Calculations, data or something else can be wrong. Do your own research before investing your money anywhere.**
1010

11-
**Demo**: Output will being sent in [this](https://t.me/sgb_advisor) public Telegram channel at 10:00 AM IST every weekday!
11+
~~**Demo**: Output is being sent in [this](https://t.me/sgb_advisor) public Telegram channel at ~10:00 AM IST every weekday!~~
1212

1313
## Tools used:
1414

@@ -26,14 +26,14 @@ You can use any of the 3 methods given below
2626
# Highly recommend creating a venv using `python -m venv .venv` and then activating it (https://docs.python.org/3/library/venv.html#how-venvs-work) first.
2727
pip install sgb-advisor
2828
playwright install --with-deps firefox
29-
# Setup env before this
29+
# Setup .env in same folder
3030
sgb-advisor
3131
```
3232

3333
2. Docker
3434

3535
```sh
36-
# Setup env before this
36+
# Setup .env in same folder
3737
docker run --env-file .env ghcr.io/vishalnandagopal/sgb-advisor:latest
3838
```
3939

@@ -51,6 +51,7 @@ Place the required env variables in an [`.env`](.env) file.
5151
```env
5252
# How to notify the user. Accepted values are "telegram", "email" or "both"
5353
SGB_MODE=telegram
54+
SGB_LOG_LEVEL=info
5455
5556
# Get token from BotFather on Telegram
5657
SGB_TELEGRAM_BOT_TOKEN=xxxxxxxxxx:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
load_dotenv(".env")
55

66

7-
def main():
7+
def main() -> None:
88
"Entry fuction for the script"
99
from src.sgb_advisor import main as main
1010

pyproject.toml

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
[project]
22
name = "sgb-advisor"
3-
version = "0.1.4"
3+
version = "0.1.7"
44
description = "A tool to analyse Sovereign Gold Bonds and compare their yields."
55
readme = "README.md"
6-
authors = [
7-
{name = "Vishal Nandagopal", email="dev@vishalnandagopal.com"}
8-
]
9-
license= "GPL-3.0-only"
6+
authors = [{ name = "Vishal Nandagopal", email = "dev@vishalnandagopal.com" }]
7+
license = "GPL-3.0-only"
108
requires-python = ">=3.13"
119
dependencies = [
1210
"loguru>=0.7.3",
@@ -16,38 +14,45 @@ dependencies = [
1614
"boto3>=1.38.12",
1715
"playwright>=1.52.0",
1816
]
17+
keywords = ["sovereign-gold-bonds", "sgb", "india-finance", "finance"]
1918

20-
[tool.uv]
21-
dev-dependencies = [
19+
[dependency-groups]
20+
dev = [
2221
"boto3-stubs>=1.38.12",
2322
"icecream>=2.1.4",
2423
"mypy>=1.15.0",
2524
"pre-commit>=4.2.0",
26-
"ruff>=0.11.9",
25+
"ruff>=0.11.10",
26+
"ty>=0.0.1a5",
2727
"types-requests>=2.32.0.20250328",
28-
"uv>=0.7.3",
28+
"uv>=0.7.5",
2929
]
30+
build = ["hatch>=1.14.1"]
3031

31-
[tool.ruff.format]
32-
docstring-code-format = true
33-
docstring-code-line-length = 100
34-
35-
[dependency-groups]
36-
dev = [
37-
"ty>=0.0.0a7",
38-
]
32+
[project.urls]
33+
homepage = "https://github.com/vishalnandagopal/sgb-advisor"
34+
source = "https://github.com/vishalnandagopal/sgb-advisor.git"
35+
documentation = "https://github.com/vishalnandagopal/sgb-advisor/blob/master/README.md#running-the-app"
36+
issues = "https://github.com/vishalnandagopal/sgb-advisor/issues"
3937

4038
[project.scripts]
4139
sgb-advisor = "sgb_advisor.__main__:main"
4240

41+
[tool.uv]
42+
default-groups = "all"
43+
44+
[tool.ruff.format]
45+
docstring-code-format = true
46+
docstring-code-line-length = 100
47+
4348
[build-system]
44-
build-backend = 'hatchling.build'
45-
requires = ['hatchling']
49+
build-backend = 'hatchling.build'
50+
requires = ['hatchling']
4651

4752
[tool.hatch.build.targets.sdist]
4853
include = [
49-
"src/sgb_advisor/assets/scrips.csv",
50-
"src/sgb_advisor/assets/template.html",
51-
"src/sgb_advisor/assets/telegram_template.html",
52-
"src/sgb_advisor/**/*.py"
54+
"src/sgb_advisor/assets/scrips.csv",
55+
"src/sgb_advisor/assets/template.html",
56+
"src/sgb_advisor/assets/telegram_template.html",
57+
"src/sgb_advisor/**/*.py",
5358
]

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This file was autogenerated by uv via the following command:
2-
# uv export --no-group dev --no-emit-project --format requirements-txt --output-file requirements.txt
2+
# uv export --no-default-groups --no-emit-project --format requirements-txt --output-file requirements.txt
33
boto3==1.38.12 \
44
--hash=sha256:9939b65b0bf04781f531245f110dd0ada6825f06cf9b95350efb830b9f69d214 \
55
--hash=sha256:ca06315fdb20821fc1084a7b08557556eed97cb917a30ff19d8524b495383889

src/sgb_advisor/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,4 @@
22
A tool to analyse Sovereign Gold Bonds and compare their yields.
33
"""
44

5-
from .data import get_sgbs as get_sgbs
6-
from .notify import notify as notify
75
from .__main__ import main as main

src/sgb_advisor/__main__.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,23 @@
1-
from dotenv import load_dotenv
1+
from os import getenv
2+
from pathlib import Path
23

3-
# Need to load dotenv before importing/running any file, since they use API keys from env modules
4-
load_dotenv(".env")
4+
from dotenv import load_dotenv
55

66

77
def main():
8+
# Need to load dotenv before importing/running any module file, since they use API keys from env modules
9+
SGB_ENV_FILE_PATH: Path = Path(
10+
getenv("SGB_ENV_FILE_PATH", str(Path.cwd() / ".env"))
11+
)
12+
load_dotenv(SGB_ENV_FILE_PATH)
13+
14+
from .data import get_sgbs as get_sgbs
15+
from .logg import logger as logger
16+
from .notify import notify as notify
17+
18+
if SGB_ENV_FILE_PATH.exists():
19+
logger.debug(f"Loaded environment variables from {SGB_ENV_FILE_PATH}")
820
"Entry fuction for the script"
9-
from sgb_advisor import get_sgbs, notify
1021

1122
sgbs = get_sgbs()
1223
notify(sgbs)

src/sgb_advisor/data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from playwright.sync_api import TimeoutError as PlaywrightTimeoutError
1010
from playwright.sync_api import sync_playwright
1111

12-
from .logger import logger
12+
from .logg import logger
1313
from .models import SGB
1414
from .quick_mafs import calculate_sgb_xirr
1515

File renamed without changes.

src/sgb_advisor/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def __init__(
6969
"""The date of maturity of the bond"""
7070

7171
self.xirr: float = 0
72-
"""XIRR which will be calculated and set later"""
72+
"""XIRR which can be calculated and set later"""
7373

7474
def __str__(self) -> str:
7575
"""

src/sgb_advisor/notify/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from os import getenv
22

3-
from ..logger import logger
3+
from ..logg import logger
44
from ..models import SGB
55
from .common import tmp_folder
66
from .email_sender import AWS_ACCESS_KEY_ENV, send_mail

src/sgb_advisor/notify/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from typing import Optional
1212

1313
from ..data import get_price_of_gold
14-
from ..logger import logger
14+
from ..logg import logger
1515
from ..models import SGB
1616

1717
tmp_folder = Path(f"{gettempdir()}/sgb_advisor")

src/sgb_advisor/notify/email_sender.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from botocore.exceptions import ClientError
99

1010
from ..data import SGB
11-
from ..logger import logger
11+
from ..logg import logger
1212
from .common import generate_html_from_template
1313

1414
AWS_ACCESS_KEY_ENV: str = "SGB_AWS_ACCESS_KEY"

0 commit comments

Comments
 (0)