Skip to content
Merged
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
35 changes: 35 additions & 0 deletions .github/workflows/check-python-versions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Check Python Versions

on:
pull_request:
branches: [main]
paths:
- '.github/workflows/check-python-versions.yml'
- '.github/workflows/pr-check.yml'
- '.github/workflows/push-check.yml'
schedule:
- cron: '0 12 * * 1'
workflow_dispatch:

permissions:
contents: read

concurrency:
group: check-python-versions-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: false

jobs:
check:
name: Python Version Coverage
if: github.repository_owner == 'microsoft'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: microsoft/vscode-python-ci/actions/check-python-versions@066d9e604a509ec5cbc11141280cdfb48d7700b7
with:
files: |
- path: .github/workflows/pr-check.yml
key: python
- path: .github/workflows/push-check.yml
key: python
create-issue: 'false'
2 changes: 1 addition & 1 deletion .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
python: ["3.10", "3.11", "3.12", "3.13", "3.14"]
python: ["3.10", "3.11", "3.12", "3.13", "3.14", "3.15"]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Use Python ${{ matrix.python }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/push-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
python: ["3.10", "3.11", "3.12", "3.13", "3.14"]
python: ["3.10", "3.11", "3.12", "3.13", "3.14", "3.15"]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Use Python ${{ matrix.python }}
Expand Down
42 changes: 42 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,48 @@ Use the [supported architecture and adoption guide](docs/supported-apis.md) when
choosing extension-owned policy, shared public APIs or private implementation
boundaries. Recommended facade adoption does not deprecate manual composition.

### Python compatibility coverage

Both PR and push CI run `nox -s tests` on stable Python 3.10-3.15 on Ubuntu and
Windows. Each session installs `./python[dev]` into a fresh environment and logs
the resolved dependency versions with `pip list --format=freeze`. This tests
the resolver-selected, mutually compatible runtime and development dependencies
available for that interpreter at run time, not a locked or minimum-version
combination. Runtime requirements are `pygls>=1.1.0`,
`lsprotocol>=2023.0.0` and `packaging>=22.0`; transitive requirements also
participate in resolution.

The suite includes a real subprocess worker using shared `JsonRpc`,
`run_message_loop` and `run_module`, with tool output, exception recovery and
process cleanup checks. It does not depend on Pylint or another external tool.
The target-install smoke builds a clean staged copy using
`pip install --target ... --no-deps --no-cache-dir --no-build-isolation --upgrade`.
The development extra supplies the build backend (`setuptools` and `wheel`);
the nox environment supplies runtime dependencies. An isolated (`python -I`)
subprocess verifies package and distribution metadata originate in the target
and executes the installed runner. Staging keeps build artifacts out of the
source package. `--no-build-isolation` avoids downloading build tools in this
smoke; consumers may retain pip's normal isolated-build behavior.

These runs do not establish compatibility with every minimum dependency
combination, consumers' reviewed dependency locks/bundles, or consumer-provided
optional `debugpy`. Those require separate consumer validation. In particular,
shared-runtime coverage does not diagnose or fix downstream Pylint failures.
Older local Python 3.15 alphas are not stable-3.15 evidence, and CI does not pin
pytest to accommodate such alphas. Source-only, pinned-submodule consumption
and the consumer-owned dependency policy remain unchanged.

The dedicated `Check Python Versions` workflow invokes the SHA-pinned
`microsoft/vscode-python-ci/actions/check-python-versions` action for both
matrices. It runs on relevant PR workflow changes, weekly on Mondays at 12:00
UTC, and on manual dispatch. The action compares declared versions with the
newest Python 3 series that has a published release candidate; it does not run
tests or establish stable-interpreter support itself. This rollout uses
read-only, check-only mode: missing coverage is reported in the job summary,
not treated as a failing check, and no issues are created. Upstream issue mode
does not yet deduplicate issues. Release lookup or action/configuration errors
still fail the job.

### Settings boundary tests

The JSON corpus in `python/tests/fixtures/settings/` characterizes the existing
Expand Down
1 change: 1 addition & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def install(session: nox.Session) -> None:
def tests(session: nox.Session) -> None:
"""Run Python tests."""
session.install("-e", "./python[dev]")
session.run("python", "-m", "pip", "list", "--format=freeze")
session.run("pytest", "python/tests", "-v")


Expand Down
2 changes: 2 additions & 0 deletions python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ dev = [
"black",
"isort",
"flake8",
"setuptools>=68.0",
"wheel",
]

[tool.setuptools.packages.find]
Expand Down
30 changes: 30 additions & 0 deletions python/tests/fixtures/bundled_smoke.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
"""Executed with -I so environment paths and the checkout cannot supply the package."""

import importlib
import importlib.metadata
import json
import pathlib
import sys

target = pathlib.Path(sys.argv[1]).resolve()
sys.path.insert(0, str(target))
package = importlib.import_module("vscode_common_python_lsp")
assert pathlib.Path(package.__file__).resolve().is_relative_to(target)
distribution = importlib.metadata.distribution("vscode-python-tool-internal")
assert distribution.locate_file("").resolve() == target
assert distribution.version

runner = importlib.import_module("vscode_common_python_lsp.runner")
assert pathlib.Path(runner.__file__).resolve().is_relative_to(target)
result = runner.run_module(
"json.tool",
["json.tool"],
use_stdin=True,
cwd=str(target.parent),
source='{"message": "héllo 日本語"}',
)
assert json.loads(result.stdout) == {"message": "héllo 日本語"}
assert result.stderr == ""
assert result.exit_code in (None, 0)
14 changes: 14 additions & 0 deletions python/tests/fixtures/worker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
"""Test-only worker using the same shared runner primitives as consumers."""

import sys

from vscode_common_python_lsp.jsonrpc import JsonRpc
from vscode_common_python_lsp.process_runner import run_message_loop
from vscode_common_python_lsp.runner import RunResult, run_module

if __name__ == "__main__":
run_message_loop(
JsonRpc(sys.stdin.buffer, sys.stdout.buffer), run_module, RunResult
)
23 changes: 23 additions & 0 deletions python/tests/fixtures/worker_tool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.
"""Deterministic tool for real worker transport tests."""

import json
import os
import sys

if __name__ == "__main__":
if "--fail" in sys.argv:
raise RuntimeError("worker tool failure")
print(
json.dumps(
{
"pid": os.getpid(),
"executable": sys.executable,
"cwd": os.getcwd(),
"argv": sys.argv,
"source": sys.stdin.read(),
}
)
)
print("worker tool stderr", file=sys.stderr)
60 changes: 60 additions & 0 deletions python/tests/test_jsonrpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@
"""Tests for vscode_common_python_lsp.jsonrpc."""

import io
import json
import os
import pathlib
import sys
import threading
import unittest
from unittest.mock import MagicMock, patch

import pytest

from vscode_common_python_lsp import jsonrpc
from vscode_common_python_lsp.jsonrpc import (
CONTENT_LENGTH,
JsonRpc,
Expand All @@ -19,6 +24,61 @@
)


def test_real_worker_roundtrip_exception_recovery_and_cleanup(tmp_path):
"""Execute a tool in a real worker, including recovery after a failed request."""
python_root = pathlib.Path(__file__).resolve().parents[1]
worker = pathlib.Path(__file__).parent / "fixtures" / "worker.py"
workspace = str(tmp_path)
cwd = tmp_path / "workspace café"
cwd.mkdir()

def run_tool(*args):
return run_over_json_rpc(
workspace,
[sys.executable],
"worker_tool",
["worker_tool", *args],
True,
str(cwd),
str(worker),
source="héllo 日本語\n",
env={"PYTHONPATH": str(python_root)},
timeout=20,
)

process = None
try:
result = run_tool("--argument", "café")
process = jsonrpc._process_manager._processes[workspace]
payload = json.loads(result.stdout)
worker_pid = payload.pop("pid")
assert worker_pid != os.getpid()
assert payload == {
"executable": sys.executable,
"cwd": str(cwd),
"argv": ["worker_tool", "--argument", "café"],
"source": "héllo 日本語\n",
}
assert result.stderr == "worker tool stderr\n"
assert result.exception is None

failure = run_tool("--fail")
assert failure.stdout == ""
assert failure.stderr == ""
assert "RuntimeError: worker tool failure" in failure.exception

recovered = run_tool("--recovered")
assert json.loads(recovered.stdout)["pid"] == worker_pid
assert recovered.exception is None
finally:
jsonrpc._process_manager.stop_process(workspace)

assert process.poll() is not None
assert process.stdin.closed and process.stdout.closed
with pytest.raises(StreamClosedException):
jsonrpc._process_manager.get_json_rpc(workspace)


class TestJsonRpcReadWrite(unittest.TestCase):
"""Tests for JsonRpc read/write round-trip."""

Expand Down
50 changes: 50 additions & 0 deletions python/tests/test_package.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,59 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

import pathlib
import shutil
import subprocess
import sys

import vscode_common_python_lsp


def test_package_importable():
"""Verify the package is importable."""
assert hasattr(vscode_common_python_lsp, "classify_python_file")


def test_noneditable_target_install(tmp_path):
"""Build from clean sources and execute the installed target, not this checkout."""
python_root = pathlib.Path(__file__).resolve().parents[1]
source = tmp_path / "source"
source.mkdir()
for name in ("pyproject.toml", "README.md"):
shutil.copy2(python_root / name, source / name)
shutil.copytree(
python_root / "vscode_common_python_lsp",
source / "vscode_common_python_lsp",
ignore=shutil.ignore_patterns("__pycache__", "*.pyc"),
)
target = tmp_path / "bundled" / "libs"
subprocess.run(
[
sys.executable,
"-m",
"pip",
"--disable-pip-version-check",
"install",
"--target",
str(target),
"--no-deps",
"--no-cache-dir",
"--no-build-isolation",
"--upgrade",
str(source),
],
cwd=tmp_path,
check=True,
timeout=120,
)
subprocess.run(
[
sys.executable,
"-I",
str(pathlib.Path(__file__).parent / "fixtures" / "bundled_smoke.py"),
str(target),
],
cwd=tmp_path,
check=True,
timeout=20,
)