Skip to content

Commit

Permalink
Use single source of truth for package version
Browse files Browse the repository at this point in the history
  • Loading branch information
gi0baro committed Jan 24, 2024
1 parent f496e07 commit 18dc258
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions granian/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from ._granian import __version__ # noqa
from .server import Granian # noqa
1 change: 0 additions & 1 deletion granian/__version__.py

This file was deleted.

2 changes: 2 additions & 0 deletions granian/_granian.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ from typing import Any, Dict, List, Optional, Tuple

from ._types import WebsocketMessage

__version__: str

class ASGIScope:
def as_dict(self, root_path: str) -> Dict[str, Any]: ...

Expand Down
2 changes: 1 addition & 1 deletion granian/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import typer

from .__version__ import __version__
from . import __version__
from .constants import HTTPModes, Interfaces, Loops, ThreadModes
from .http import HTTP1Settings, HTTP2Settings
from .log import LogLevels
Expand Down
11 changes: 11 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;

use pyo3::prelude::*;
use std::sync::OnceLock;

mod asgi;
mod callbacks;
Expand All @@ -17,8 +18,18 @@ mod workers;
mod ws;
mod wsgi;

pub fn get_granian_version() -> &'static str {
static GRANIAN_VERSION: OnceLock<String> = OnceLock::new();

GRANIAN_VERSION.get_or_init(|| {
let version = env!("CARGO_PKG_VERSION");
version.replace("-alpha", "a").replace("-beta", "b")
})
}

#[pymodule]
fn _granian(py: Python, module: &PyModule) -> PyResult<()> {
module.add("__version__", get_granian_version())?;
asgi::init_pymodule(module)?;
rsgi::init_pymodule(py, module)?;
tcp::init_pymodule(module)?;
Expand Down

0 comments on commit 18dc258

Please sign in to comment.