Skip to content

Commit 0ea30c1

Browse files
feat: fix warnings related to repository and number of files bundled. add update message suggesting to update pywire version in project. bundle deps improved. use latest prettierp lugin
1 parent f65d374 commit 0ea30c1

8 files changed

Lines changed: 462 additions & 237 deletions

File tree

package.json

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,14 @@
1212
"categories": [
1313
"Programming Languages"
1414
],
15+
"repository": {
16+
"type": "git",
17+
"url": "https://github.com/pywire/pywire"
18+
},
1519
"main": "./out/extension.cjs",
20+
"activationEvents": [
21+
"onStartupFinished"
22+
],
1623
"extensionDependencies": [
1724
"ms-python.python"
1825
],
@@ -64,10 +71,19 @@
6471
"type": "boolean",
6572
"default": false,
6673
"description": "If true, bypasses Pylance middleware and uses the bundled Pyright from the language server. Useful for testing fallback mode."
74+
},
75+
"pywire.disableUpdateNotifications": {
76+
"type": "boolean",
77+
"default": false,
78+
"description": "Disable periodic checks for PyWire updates."
6779
}
6880
}
6981
},
7082
"commands": [
83+
{
84+
"command": "pywire.update",
85+
"title": "PyWire: Attempt Upgrade"
86+
},
7187
{
7288
"command": "pywire.toggleComment",
7389
"title": "PyWire: Toggle Comment"
@@ -168,4 +184,4 @@
168184
"vscode-languageclient": "^9.0.1",
169185
"web-tree-sitter": "^0.26.3"
170186
}
171-
}
187+
}

pnpm-lock.yaml

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/bundle-deps

Lines changed: 51 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/sh -e
22

3+
export PYO3_USE_ABI3_FORWARD_COMPATIBILITY=1
4+
35
ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
46
TARGET_DIR="$ROOT_DIR/bundled/libs"
57
if [ -d "$TARGET_DIR" ]; then
@@ -12,103 +14,79 @@ if ! command -v "$PYTHON_BIN" >/dev/null 2>&1; then
1214
PYTHON_BIN="python3"
1315
fi
1416

15-
resolve_pywire_src() {
16-
if [ -z "$1" ]; then
17-
return 1
18-
fi
17+
PYWIRE_REPO="https://github.com/pywire/pywire.git"
18+
PYWIRE_LS_REPO="https://github.com/pywire/pywire-language-server.git"
1919

20+
resolve_local_src() {
2021
src="$1"
2122
case "$src" in
2223
/*) ;;
2324
*) src="$ROOT_DIR/$src" ;;
2425
esac
2526

26-
if [ ! -d "$src" ]; then
27-
return 1
28-
fi
29-
30-
if [ -f "$src/pyproject.toml" ] || [ -f "$src/setup.py" ] || [ -f "$src/setup.cfg" ]; then
27+
if [ -d "$src" ] && { [ -f "$src/pyproject.toml" ] || [ -f "$src/setup.py" ]; }; then
3128
echo "$src"
3229
return 0
3330
fi
34-
3531
return 1
3632
}
3733

3834
get_latest_tag() {
39-
REPO_URL="$1"
40-
# Get the latest tag matching v* sorted by version number
41-
TAG=$(git ls-remote --tags --sort='v:refname' "$REPO_URL" 'refs/tags/v*' | tail -n1 | sed 's|.*refs/tags/||')
42-
if [ -z "$TAG" ]; then
35+
repo_url="$1"
36+
tag=$(git ls-remote --tags --sort='v:refname' "$repo_url" 'refs/tags/v*' | tail -n1 | sed 's|.*refs/tags/||')
37+
if [ -z "$tag" ]; then
4338
echo "main"
4439
else
45-
echo "$TAG"
40+
echo "$tag"
4641
fi
4742
}
4843

49-
pywire_src="$(resolve_pywire_src "$PYWIRE_SRC")" || pywire_src=""
50-
if [ -z "$pywire_src" ]; then
51-
pywire_src="$(resolve_pywire_src "../pywire")" || pywire_src=""
52-
fi
53-
if [ -z "$pywire_src" ]; then
54-
pywire_src="$(resolve_pywire_src "pywire")" || pywire_src=""
55-
fi
56-
57-
pywire_ls_src="$(resolve_pywire_src "$PYWIRE_LANGUAGE_SERVER_SRC")" || pywire_ls_src=""
58-
if [ -z "$pywire_ls_src" ]; then
59-
pywire_ls_src="$(resolve_pywire_src "../pywire-language-server")" || pywire_ls_src=""
60-
fi
61-
if [ -z "$pywire_ls_src" ]; then
62-
pywire_ls_src="$(resolve_pywire_src "pywire-language-server")" || pywire_ls_src=""
44+
# Determine build mode
45+
if [ "$PYWIRE_RELEASE" = "1" ]; then
46+
MODE="publish"
47+
elif [ "$GITHUB_ACTIONS" = "true" ]; then
48+
MODE="ci"
49+
else
50+
MODE="local"
6351
fi
6452

65-
if [ -n "$pywire_src" ] || [ -n "$pywire_ls_src" ]; then
66-
set -- pygls pyright
67-
if [ -n "$pywire_src" ]; then
68-
set -- "$@" "$pywire_src"
69-
fi
70-
if [ -n "$pywire_ls_src" ]; then
71-
set -- "$@" "$pywire_ls_src"
72-
fi
73-
if "$PYTHON_BIN" -m pip --version >/dev/null 2>&1; then
74-
"$PYTHON_BIN" -m pip install "$@" -t "$TARGET_DIR"
75-
elif "$PYTHON_BIN" -m ensurepip --upgrade >/dev/null 2>&1; then
76-
"$PYTHON_BIN" -m pip install "$@" -t "$TARGET_DIR"
77-
elif command -v uv >/dev/null 2>&1; then
78-
uv pip install "$@" --target "$TARGET_DIR"
79-
else
80-
echo "pip is not available and uv is missing; cannot bundle deps" >&2
81-
exit 1
82-
fi
83-
exit 0
84-
fi
53+
echo "Bundling mode: $MODE"
8554

86-
PYWIRE_REPO="https://github.com/pywire/pywire.git"
87-
PYWIRE_LS_REPO="https://github.com/pywire/pywire-language-server.git"
55+
case "$MODE" in
56+
publish)
57+
PYWIRE_REF="$(get_latest_tag "$PYWIRE_REPO")"
58+
PYWIRE_LS_REF="$(get_latest_tag "$PYWIRE_LS_REPO")"
59+
DEPS="pygls pyright git+$PYWIRE_REPO@$PYWIRE_REF git+$PYWIRE_LS_REPO@$PYWIRE_LS_REF"
60+
;;
61+
ci)
62+
DEPS="pygls pyright git+$PYWIRE_REPO@main git+$PYWIRE_LS_REPO@main"
63+
;;
64+
*)
65+
# Local development mode
66+
pywire_path="$(resolve_local_src "${PYWIRE_SRC:-../pywire}")" || pywire_path=""
67+
pywire_ls_path="$(resolve_local_src "${PYWIRE_LANGUAGE_SERVER_SRC:-../pywire-language-server}")" || pywire_ls_path=""
68+
69+
DEPS="pygls pyright"
70+
if [ -n "$pywire_path" ]; then
71+
DEPS="$DEPS $pywire_path"
72+
else
73+
DEPS="$DEPS git+$PYWIRE_REPO@main"
74+
fi
75+
76+
if [ -n "$pywire_ls_path" ]; then
77+
DEPS="$DEPS $pywire_ls_path"
78+
else
79+
DEPS="$DEPS git+$PYWIRE_LS_REPO@main"
80+
fi
81+
;;
82+
esac
8883

89-
if [ "$PYWIRE_RELEASE" = "1" ]; then
90-
echo "Release mode detected. Fetching latest tags..."
91-
PYWIRE_REF="$(get_latest_tag "$PYWIRE_REPO")"
92-
PYWIRE_LS_REF="$(get_latest_tag "$PYWIRE_LS_REPO")"
93-
echo "Using pywire@$PYWIRE_REF and pywire-language-server@$PYWIRE_LS_REF"
94-
else
95-
PYWIRE_REF="main"
96-
PYWIRE_LS_REF="main"
97-
fi
84+
echo "Installing dependencies: $DEPS"
9885

9986
if command -v uv >/dev/null 2>&1; then
100-
uv pip install \
101-
pygls \
102-
pyright \
103-
"git+$PYWIRE_REPO@$PYWIRE_REF" \
104-
"git+$PYWIRE_LS_REPO@$PYWIRE_LS_REF" \
105-
--target "$TARGET_DIR"
87+
# shellcheck disable=SC2086
88+
uv pip install $DEPS --target "$TARGET_DIR"
10689
else
107-
"$PYTHON_BIN" -m pip install \
108-
pygls \
109-
pyright \
110-
"git+$PYWIRE_REPO@$PYWIRE_REF" \
111-
"git+$PYWIRE_LS_REPO@$PYWIRE_LS_REF" \
112-
-t "$TARGET_DIR"
90+
# shellcheck disable=SC2086
91+
"$PYTHON_BIN" -m pip install $DEPS -t "$TARGET_DIR"
11392
fi
114-

scripts/sync-node-deps

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,32 @@ get_latest_tag() {
1515
fi
1616
}
1717

18+
# Determine build mode
1819
if [ "$PYWIRE_RELEASE" = "1" ]; then
19-
echo "Release mode detected for Node dependencies. Fetching latest tag..."
20-
REF=$(get_latest_tag)
21-
echo "Using prettier-plugin-pywire@$REF"
20+
MODE="publish"
21+
elif [ "$GITHUB_ACTIONS" = "true" ]; then
22+
MODE="ci"
2223
else
23-
REF="main"
24-
echo "Dev/CI mode. Using prettier-plugin-pywire@main"
24+
MODE="local"
2525
fi
2626

27+
case "$MODE" in
28+
publish)
29+
echo "Release mode detected. Fetching latest tag..."
30+
REF=$(get_latest_tag)
31+
;;
32+
ci)
33+
echo "CI mode. Using main."
34+
REF="main"
35+
;;
36+
*)
37+
echo "Local mode. Using main."
38+
REF="main"
39+
;;
40+
esac
41+
42+
echo "Using prettier-plugin-pywire@$REF"
43+
2744
# Check current version in package.json to avoid unnecessary pnpm add
2845
CURRENT=$(grep -o "prettier-plugin-pywire\": \"git+$REPO_URL#[^\"]*" package.json | sed "s|.*#||" || echo "")
2946

src/extension.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import {
3838
ProvideReferencesSignature,
3939
ProvideCompletionItemsSignature,
4040
} from 'vscode-languageclient/node'
41+
import { setupUpdateCheck, performUpdate } from './updateCheck'
4142

4243
type PrettierModule = typeof import('prettier')
4344
type PrettierPlugin = import('prettier').Plugin
@@ -1137,6 +1138,13 @@ export function activate(context: ExtensionContext) {
11371138
})
11381139
context.subscriptions.push(restartCmd)
11391140

1141+
// Register Update command
1142+
context.subscriptions.push(
1143+
commands.registerCommand('pywire.update', async () => {
1144+
await performUpdate()
1145+
})
1146+
)
1147+
11401148
// Register Open Docs commands
11411149
context.subscriptions.push(
11421150
commands.registerCommand('pywire.openDocs', () => {
@@ -1198,6 +1206,9 @@ export function activate(context: ExtensionContext) {
11981206

11991207
// Start the client initially
12001208
startLanguageClient()
1209+
1210+
// Setup periodic update checks
1211+
setupUpdateCheck(context)
12011212
}
12021213

12031214
export function deactivate(): Promise<void> | undefined {

src/lsp_launcher.py

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,49 @@
1-
import sys
2-
import os
31
import json
2+
import os
3+
import sys
44
import time
55

66
# Add bundled libs to path
7-
BUNDLED_LIBS = os.path.join(os.path.dirname(__file__), '..', 'bundled', 'libs')
7+
BUNDLED_LIBS = os.path.join(os.path.dirname(__file__), "..", "bundled", "libs")
88
sys.path.insert(0, BUNDLED_LIBS)
99

1010
# Add bundled libs/bin to PATH so pyright-langserver can be found
11-
BUNDLED_BIN = os.path.join(BUNDLED_LIBS, 'bin')
11+
BUNDLED_BIN = os.path.join(BUNDLED_LIBS, "bin")
1212
if os.path.exists(BUNDLED_BIN):
1313
os.environ["PATH"] = BUNDLED_BIN + os.pathsep + os.environ.get("PATH", "")
1414

1515
# FOR DEVELOPMENT ONLY: Add the sibling pywire-language-server/src to path
1616
# In a real build, we would bundle this too.
17-
DEV_SERVER_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'pywire-language-server'))
18-
DEV_SERVER_SRC = os.path.join(DEV_SERVER_ROOT, 'src')
17+
DEV_SERVER_ROOT = os.path.abspath(
18+
os.path.join(os.path.dirname(__file__), "..", "..", "pywire-language-server")
19+
)
20+
DEV_SERVER_SRC = os.path.join(DEV_SERVER_ROOT, "src")
1921
sys.path.insert(0, DEV_SERVER_SRC)
2022

2123
# Check for sibling .venv and add site-packages
22-
venv_dir = os.path.join(DEV_SERVER_ROOT, '.venv')
24+
venv_dir = os.path.join(DEV_SERVER_ROOT, ".venv")
2325
if os.path.exists(venv_dir):
2426
# Try to find site-packages
2527
# Unix: lib/pythonX.X/site-packages
26-
lib_dir = os.path.join(venv_dir, 'lib')
28+
lib_dir = os.path.join(venv_dir, "lib")
2729
if os.path.exists(lib_dir):
2830
for item in os.listdir(lib_dir):
29-
if item.startswith('python'):
30-
site_packages = os.path.join(lib_dir, item, 'site-packages')
31+
if item.startswith("python"):
32+
site_packages = os.path.join(lib_dir, item, "site-packages")
3133
if os.path.exists(site_packages):
3234
sys.path.insert(0, site_packages)
3335
# Also add bin path for potential executable lookup helpers involving PATH
34-
bin_dir = os.path.join(venv_dir, 'bin')
35-
os.environ["PATH"] = bin_dir + os.pathsep + os.environ.get("PATH", "")
36+
bin_dir = os.path.join(venv_dir, "bin")
37+
os.environ["PATH"] = (
38+
bin_dir + os.pathsep + os.environ.get("PATH", "")
39+
)
3640
break
3741

3842

39-
# #region agent log
40-
try:
41-
from pathlib import Path
42-
with open('/Users/rholmdahl/projects/pywire/.cursor/debug.log', 'a') as f:
43-
log_entry = {
44-
"sessionId": "debug-session",
45-
"runId": "run_launcher",
46-
"hypothesisId": "H4_vendored",
47-
"location": "lsp_launcher:start",
48-
"message": "Launcher started",
49-
"data": {
50-
"sys.path": sys.path,
51-
"bundled_libs": BUNDLED_LIBS,
52-
"dev_src": DEV_SERVER_SRC
53-
},
54-
"timestamp": int(time.time() * 1000)
55-
}
56-
f.write(json.dumps(log_entry) + "\n")
57-
except Exception:
58-
pass
59-
# #endregion
60-
6143
try:
6244
from pywire_language_server.server import start
63-
if __name__ == '__main__':
45+
46+
if __name__ == "__main__":
6447
start()
6548
except ImportError as e:
6649
# Log failure to stderr so it shows up in LS output

0 commit comments

Comments
 (0)