diff --git a/examples/plugins/wikipedia/manifest.json b/examples/plugins/wikipedia/manifest.json index 0a9ddc6..f59c989 100644 --- a/examples/plugins/wikipedia/manifest.json +++ b/examples/plugins/wikipedia/manifest.json @@ -3,5 +3,11 @@ "runner": "python", "owner": "lmstudio", "name": "py-wikipedia", - "revision": 1 + "revision": 1, + "version": "0.1.0", + "description": "A small Wikipedia lookup plugin for examples/demos.", + "entry": "py_wikipedia.py", + "requirements": ["requests>=2.28"], + "license": "MIT", + "homepage": "https://example.org/py-wikipedia" } diff --git a/misc/tag-release.sh b/misc/tag-release.sh index b473bbe..d5f518b 100755 --- a/misc/tag-release.sh +++ b/misc/tag-release.sh @@ -1,3 +1,55 @@ #!/bin/sh +set -eu + +usage() { + echo "Usage: $(basename "$0") [--push]" + echo + echo "Create an annotated git tag from the current pdm project version." + echo " --push Push the created tag to 'origin' after creating it." +} + +if [ "${1:-}" = "--help" ] || [ "${1:-}" = "-h" ]; then + usage + exit 0 +fi + +PUSH=false +if [ "${1:-}" = "--push" ]; then + PUSH=true +fi + +if ! command -v pdm >/dev/null 2>&1; then + echo "Error: 'pdm' command not found. Please install PDM or run this from an environment with pdm available." >&2 + exit 2 +fi + version_tag="$(pdm show --version)" +if [ -z "$version_tag" ]; then + echo "Error: pdm did not return a version." >&2 + exit 3 +fi + +# Ensure tag doesn't already exist +if git rev-parse --verify "refs/tags/$version_tag" >/dev/null 2>&1; then + echo "Error: tag '$version_tag' already exists." >&2 + exit 4 +fi + +# Ensure working tree is clean to avoid tagging uncommitted changes +if [ -n "$(git status --porcelain)" ]; then + echo "Error: working directory has uncommitted changes. Commit or stash them before tagging." >&2 + git status --short + exit 5 +fi + +echo "Creating annotated tag: $version_tag" git tag -a "$version_tag" -m "$version_tag" +echo "Tag '$version_tag' created locally." + +if [ "$PUSH" = true ]; then + echo "Pushing tag '$version_tag' to origin..." + git push origin "refs/tags/$version_tag" + echo "Push complete." +else + echo "Run 'git push origin refs/tags/$version_tag' to push the tag to the remote." +fi diff --git a/misc/update-sdk-schema.sh b/misc/update-sdk-schema.sh index 25ea5d0..152e87a 100755 --- a/misc/update-sdk-schema.sh +++ b/misc/update-sdk-schema.sh @@ -1,18 +1,97 @@ -#!/bin/bash +#!/usr/bin/env bash # See http://redsymbol.net/articles/unofficial-bash-strict-mode/ for benefit of these options set -euo pipefail IFS=$'\n\t' -# Note: `readlink -f` (long available in GNU coreutils) is available on macOS 12.3 and later -script_dir="$(cd -- "$(dirname -- "$(readlink -f "${BASH_SOURCE[0]}")")" &> /dev/null && pwd)" +usage() { + cat <&2 + usage + exit 2 + ;; + esac + shift || true +done + +# Resolve script directory portably. Prefer readlink -f when available. +resolve_path() { + local path="$1" + if command -v readlink >/dev/null 2>&1 && readlink -f / >/dev/null 2>&1; then + readlink -f "$path" + else + # macOS or systems without GNU readlink: fall back to python if available + if command -v python3 >/dev/null 2>&1; then + python3 -c "import os,sys; print(os.path.realpath(sys.argv[1]))" -- "$path" + else + # Best-effort fallback: canonicalize using pwd + (cd "$(dirname -- "$path")" && pwd -P)/$(basename -- "$path") + fi + fi +} + +script_dir="$(resolve_path "${BASH_SOURCE[0]}")" +script_dir="$(cd -- "$(dirname -- "$script_dir")" &> /dev/null && pwd)" + +# Ensure required commands are present +for cmd in git tox; do + if ! command -v "$cmd" >/dev/null 2>&1; then + echo "Error: required command '$cmd' not found in PATH." >&2 + exit 3 + fi +done + +submodule_dir="$script_dir/../sdk-schema/lmstudio-js" +if [ ! -d "$submodule_dir" ]; then + echo "Error: expected submodule directory '$submodule_dir' not found." >&2 + exit 4 +fi + +echo "Updating submodule at: $submodule_dir" +pushd "$submodule_dir" >/dev/null || exit 1 + +echo "Switching to branch: $branch" +git switch "$branch" +if [ "$do_pull" = true ]; then + echo "Pulling latest changes for $branch" + git pull --ff-only +else + echo "Skipping git pull as requested (--no-pull)" +fi + +echo "Initializing/updating nested submodules" git submodule update --init --recursive -popd || exit 1 + +popd >/dev/null || exit 1 + +echo "Regenerating Python SDK schema with tox" tox -e sync-sdk-schema -- --regen-schema diff --git a/tests/async2sync.py b/tests/async2sync.py index d31766d..89f177a 100644 --- a/tests/async2sync.py +++ b/tests/async2sync.py @@ -8,6 +8,7 @@ import subprocess from pathlib import Path from os.path import commonpath +from typing import List GENERATED_FILE_HEADER = """\ ##################################################################### @@ -29,7 +30,7 @@ def convert_file(input_file: Path, sync_dir: Path) -> None: # Note: some replacements will only be relevant after dropping 3.10 support # (as the native asyncio API were only added in 3.11) - replacements = [ + replacements: List[tuple[str, str]] = [ (r"AsyncPredictionC", "SyncPredictionC"), # Channel & CM (r"AsyncSession", "SyncSession"), (r"@pytest\.mark\.asyncio\n*", ""), @@ -46,7 +47,7 @@ def convert_file(input_file: Path, sync_dir: Path) -> None: (r"aexit", "exit"), (r"anext", "next"), (r"Async", ""), - (r"await +", ""), + (r"await\s+", ""), # Switch to native asyncio APIs when dropping Python 3.10 support (r"import anyio\n", ""), (r"anyio\.fail_after\([^)]*\)", "nullcontext()"), @@ -64,8 +65,12 @@ def convert_file(input_file: Path, sync_dir: Path) -> None: content, ) - # Use commonpath, as there's no `walk_up` parameter on `relative_to`` in Python 3.11 - base_path = commonpath((input_file, output_file)) + # Ensure the output directory exists + sync_dir.mkdir(parents=True, exist_ok=True) + + # Use commonpath, as there's no `walk_up` parameter on `relative_to` in Python 3.11 + # commonpath expects strings + base_path = commonpath((str(input_file), str(output_file))) relative_input_path = str(input_file.relative_to(base_path).as_posix()) output_header = GENERATED_FILE_HEADER.format(relative_input_path) output_text = output_header + content