diff --git a/.gitignore b/.gitignore index 614bc49..a841a95 100644 --- a/.gitignore +++ b/.gitignore @@ -110,3 +110,6 @@ venv.bak/ .mypy_cache/ .dmypy.json dmypy.json + +# hatch-vcs +src/norwegianblue/_version.py diff --git a/pyproject.toml b/pyproject.toml index 4baf7fe..53f380f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -64,6 +64,9 @@ norwegianblue = "norwegianblue.cli:main" [tool.hatch] version.source = "vcs" +[tool.hatch.build.hooks.vcs] +version-file = "src/norwegianblue/_version.py" + [tool.hatch.version.raw-options] local_scheme = "no-local-version" diff --git a/src/norwegianblue/__init__.py b/src/norwegianblue/__init__.py index 1e70c9f..f5fc198 100644 --- a/src/norwegianblue/__init__.py +++ b/src/norwegianblue/__init__.py @@ -6,7 +6,6 @@ from __future__ import annotations import datetime as dt -import importlib.metadata import json import logging from functools import lru_cache @@ -14,15 +13,13 @@ from dateutil.relativedelta import relativedelta from termcolor import colored -from norwegianblue import _cache - -__version__ = importlib.metadata.version(__name__) +from norwegianblue import _cache, _version +__version__ = _version.__version__ __all__ = ["__version__"] BASE_URL = "https://endoflife.date/api/" -USER_AGENT = f"norwegianblue/{__version__}" def error_404_text(product: str, suggestion: str) -> str: @@ -63,7 +60,11 @@ def norwegianblue( # No cache, or couldn't load cache import httpx - r = httpx.get(url, follow_redirects=True, headers={"User-Agent": USER_AGENT}) + r = httpx.get( + url, + follow_redirects=True, + headers={"User-Agent": f"norwegianblue/{__version__}"}, + ) logging.info("HTTP status code: %d", r.status_code) if r.status_code == 404: