Skip to content

Commit

Permalink
[router] setuptools_scm to support version argument (#155)
Browse files Browse the repository at this point in the history
* [router] setuptools_scm to support version argument

Signed-off-by: Ce Gao <[email protected]>
  • Loading branch information
gaocegege authored Feb 20, 2025
1 parent 286a3f4 commit e10ec06
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/functionality-helm-chart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ jobs:
- run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
- name: Deploy via helm charts
env:
DOCKER_BUILDKIT: 1
run: |
cd ${{ github.workspace }}
sudo docker build -t localhost:5000/git-act-router -f docker/Dockerfile .
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,6 @@ perf-test.py

values-*.yaml
helm/examples

# version files
src/vllm_router/_version.py
17 changes: 11 additions & 6 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
# Stage 1: Build
FROM python:3.10-slim as builder
FROM python:3.10-slim

WORKDIR /app

# Copy only the setup.py first to leverage Docker layer caching
# hadolint ignore=DL3008
RUN --mount=type=cache,target=/var/lib/apt --mount=type=cache,target=/var/cache/apt \
apt-get update && \
apt-get install -y --no-install-recommends git && \
rm -rf /var/lib/apt/lists/*

# Copy the setup.dot py and the git metadata first (leverage Docker layer caching)
COPY setup.py .
COPY .git/ .git/

# Copy the rest of the application code
COPY src/ src/

# Install dependencies (no cache to reduce size)
RUN --mount=type=cache,target=/root/.cache/pip \
pip install --no-cache-dir --upgrade pip && \
# Install dependencies (use cache, and delete after install, to speed up the build)
RUN pip install --upgrade --no-cache-dir pip setuptools_scm && \
pip install --no-cache-dir .

# Set the entrypoint
Expand Down
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
[build-system]
requires = ["setuptools>=68", "setuptools_scm[toml]>=8.0"]

[tool.setuptools_scm]
write_to = "src/vllm_router/_version.py"

[tool.isort]
profile = "black"
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

setup(
name="vllm-router",
version="0.1.0",
use_scm_version=True,
setup_requires=["setuptools_scm"],
packages=find_packages(where="src"),
package_dir={"": "src"},
# Should be the same as src/router/requirements.txt
Expand Down
15 changes: 12 additions & 3 deletions src/vllm_router/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@
ServiceDiscoveryType,
)
from vllm_router.utils import set_ulimit, validate_url
from vllm_router.version import __version__

httpx_client_wrapper = HTTPXClientWrapper()
logger = logging.getLogger("uvicorn")

STACK_VERSION = "0.0.1"


@asynccontextmanager
async def lifespan(app: FastAPI):
Expand Down Expand Up @@ -460,7 +459,8 @@ async def route_completition(request: Request):

@app.get("/version")
async def show_version():
return JSONResponse(content={"version": STACK_VERSION})
ver = {"version": __version__}
return JSONResponse(content=ver)


@app.get("/v1/models")
Expand Down Expand Up @@ -699,6 +699,15 @@ def parse_args():
default=10,
help="The interval in seconds to log statistics.",
)

# Add --version argument
parser.add_argument(
"--version",
action="version",
version=f"%(prog)s {__version__}",
help="Show version and exit",
)

args = parser.parse_args()
validate_args(args)
return args
Expand Down
9 changes: 9 additions & 0 deletions src/vllm_router/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
try:
from ._version import __version__, __version_tuple__
except Exception as e:
import warnings

warnings.warn(f"Failed to read commit hash:\n{e}", RuntimeWarning, stacklevel=2)

__version__ = "dev"
__version_tuple__ = (0, 0, __version__)

0 comments on commit e10ec06

Please sign in to comment.