From c6820a9476f4c7440dfd8c8e8fc60048683fce86 Mon Sep 17 00:00:00 2001 From: AC Date: Thu, 15 Oct 2026 15:43:29 +0800 Subject: [PATCH] Include Python runtime in CLI version output --- README.md | 4 ++++ pylsp/__main__.py | 6 +++++- test/test_main.py | 23 +++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 test/test_main.py diff --git a/README.md b/README.md index 6f6cb19b..c3a0805d 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,10 @@ Only on Alpine Linux the package is named differently. You can install it there apk add py3-lsp-server ``` +Run `pylsp --version` (or `pylsp -V`) to see both the server version and the +Python version running it. This reports the server runtime, which may differ +from the interpreter or target Python version configured for individual plugins. + ### 3rd Party Plugins Installing these plugins will add extra functionality to the language server: diff --git a/pylsp/__main__.py b/pylsp/__main__.py index 760f8829..f8cb6194 100644 --- a/pylsp/__main__.py +++ b/pylsp/__main__.py @@ -4,6 +4,7 @@ import argparse import logging import logging.config +import platform import sys import time @@ -63,7 +64,10 @@ def add_arguments(parser) -> None: ) parser.add_argument( - "-V", "--version", action="version", version="%(prog)s v" + __version__ + "-V", + "--version", + action="version", + version=f"%(prog)s v{__version__} (Python {platform.python_version()})", ) diff --git a/test/test_main.py b/test/test_main.py new file mode 100644 index 00000000..fbc7b793 --- /dev/null +++ b/test/test_main.py @@ -0,0 +1,23 @@ +# Copyright 2021- Python Language Server Contributors. + +import platform +import subprocess +import sys + +import pytest + +from pylsp._version import __version__ + + +@pytest.mark.parametrize("flag", ["--version", "-V"]) +def test_version_includes_python_runtime(flag): + result = subprocess.run( + [sys.executable, "-m", "pylsp", flag], + capture_output=True, + text=True, + check=True, + timeout=10, + ) + assert f"v{__version__}" in result.stdout + assert f"Python {platform.python_version()}" in result.stdout + assert result.stderr == ""