Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/pycharting/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@
- `get_server_status`: Function to check the status of the background server.
"""

from importlib.metadata import version as _distribution_version

Comment on lines +41 to +42
from .api.interface import get_server_status, plot, stop_server

__all__ = ["__version__", "get_server_status", "plot", "stop_server"]

# Keep this in sync with pyproject.toml
__version__ = "0.2.14"
# Resolved from the installed distribution metadata, which is generated from the
# version in pyproject.toml. That is the single place to bump; nothing here needs
# to be kept in sync by hand.
__version__ = _distribution_version("pycharting")
3 changes: 2 additions & 1 deletion src/pycharting/core/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import logging
import socket
from collections.abc import MutableMapping
from importlib.metadata import version as _distribution_version
from pathlib import Path
from typing import Any

Expand Down Expand Up @@ -118,7 +119,7 @@ def create_app() -> FastAPI:
app = FastAPI(
title="PyCharting",
description="Interactive charting and data visualization API",
version="0.1.0",
version=_distribution_version("pycharting"),
docs_url="/api/docs",
Comment on lines 119 to 123
redoc_url="/api/redoc",
)
Expand Down
21 changes: 18 additions & 3 deletions tests/pycharting/core/test_server.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
"""Tests for FastAPI server."""

from importlib.metadata import version as distribution_version

import pytest
from fastapi.testclient import TestClient

import pycharting
from pycharting.core.server import NoCacheStaticFiles, create_app, find_free_port, run_server


Expand Down Expand Up @@ -136,10 +139,10 @@ def test_openapi_has_title(client):


def test_openapi_has_version(client):
"""Test that OpenAPI spec has version."""
"""The OpenAPI spec advertises the installed distribution version."""
response = client.get("/openapi.json")
data = response.json()
assert data["info"]["version"] == "0.1.0"
assert data["info"]["version"] == distribution_version("pycharting")


def test_docs_endpoint_available(client):
Expand Down Expand Up @@ -190,7 +193,19 @@ def test_app_has_correct_metadata(client):

assert data["info"]["title"] == "PyCharting"
assert data["info"]["description"] == "Interactive charting and data visualization API"
assert data["info"]["version"] == "0.1.0"
assert data["info"]["version"] == distribution_version("pycharting")


def test_advertised_version_matches_the_package_attribute(client):
"""The version served over HTTP is the same one ``pycharting.__version__`` reports.

These used to be independent literals — ``0.1.0`` here and ``0.2.14`` in
``__init__.py``, against ``0.2.16`` in the manifest — and the suite pinned the
stale values rather than catching the drift.
"""
served = client.get("/openapi.json").json()["info"]["version"]

assert served == pycharting.__version__ == distribution_version("pycharting")


class TestNoCacheStaticFiles:
Expand Down