Skip to content
Closed
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
8 changes: 7 additions & 1 deletion examples/plugins/wikipedia/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
52 changes: 52 additions & 0 deletions misc/tag-release.sh
Original file line number Diff line number Diff line change
@@ -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
97 changes: 88 additions & 9 deletions misc/update-sdk-schema.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF
Usage: $(basename "$0") [--branch BRANCH] [--no-pull]

# Update submodule to tip of the lmstudio-js main branch and regenerate the exported schema
# (to incorporate Python data model template changes, just run `tox -e sync-sdk-schema`)
Update the `sdk-schema/lmstudio-js` submodule to the specified branch (default: main)
and regenerate the exported schema by running tox -e sync-sdk-schema -- --regen-schema.

pushd "$script_dir/../sdk-schema/lmstudio-js" || exit 1
git switch main
git pull
Options:
--branch BRANCH Branch to switch the submodule to (default: main)
--no-pull Don't run 'git pull' in the submodule
-h, --help Show this help message
EOF
}

branch="main"
do_pull=true

while [ "$#" -gt 0 ]; do
case "$1" in
--branch)
shift
branch=${1:-}
;;
--no-pull)
do_pull=false
;;
-h|--help)
usage
exit 0
;;
*)
echo "Unknown arg: $1" >&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
13 changes: 9 additions & 4 deletions tests/async2sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import subprocess
from pathlib import Path
from os.path import commonpath
from typing import List

GENERATED_FILE_HEADER = """\
#####################################################################
Expand All @@ -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*", ""),
Expand All @@ -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()"),
Expand All @@ -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
Expand Down
Loading