Skip to content

Commit

Permalink
chore: update update_schema.py for basedpyright (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
jfcherng authored Mar 30, 2024
1 parent 93628e3 commit 7089a9a
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 6 deletions.
70 changes: 70 additions & 0 deletions .github/workflows/schema.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
name: Update schema in Dependabot PR

on:
pull_request:
branches:
- master
paths:
- 'language-server/package.json'

permissions:
contents: write
pull-requests: write
repository-projects: write

jobs:
update_schema:
name: Run schema update
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: 3.12

- name: Update schema
id: update-schema
run: |
{
echo 'OUTPUT<<EOF'
make update-schema
echo EOF
} >> "$GITHUB_OUTPUT"
- name: Check for modified files
id: git-check
run: echo "GIT_MODIFIED=$(if [ -n "$(git status --porcelain)" ]; then echo "true"; else echo "false"; fi)" >> "$GITHUB_OUTPUT"

- name: Update changes in the PR
if: steps.git-check.outputs.GIT_MODIFIED == 'true'
run: |
git config --global user.name github-actions[bot]
git config --global user.email github-actions[bot]@users.noreply.github.com
git add -A
git commit -m '[automated commit] update schema'
git push
- name: Find Comment
uses: peter-evans/find-comment@v3
id: find-comment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'

- name: Create or update comment
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.find-comment.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
Following are the schema changes in the new version. Make sure that those are reflected in `LSP-basedpyright.sublime-settings` and `sublime-package.json` files.
```
${{ steps.update-schema.outputs.OUTPUT }}
```
edit-mode: replace
10 changes: 4 additions & 6 deletions scripts/update_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
from typing import Any
from urllib.request import urlopen

PACKAGE_NAME = "LSP-pyright"
PACKAGE_NAME = "LSP-basedpyright"

PROJECT_ROOT = Path(__file__).parents[1]
PYRIGHTCONFIG_SCHEMA_ID = "sublime://pyrightconfig"
PYRIGHT_CONFIGURATION_SCHEMA_URL = (
"https://raw.githubusercontent.com/microsoft/pyright/main/packages/vscode-pyright/schemas/pyrightconfig.schema.json" # noqa: E501
)
PYRIGHT_CONFIGURATION_SCHEMA_URL = "https://raw.githubusercontent.com/DetachHead/basedpyright/main/packages/vscode-pyright/schemas/pyrightconfig.schema.json"
SUBLIME_PACKAGE_JSON_PATH = PROJECT_ROOT / "sublime-package.json"
# Keys that are in the pyrightconfig.json schema but should not raise a comment when not present in the LSP schema.
IGNORED_PYRIGHTCONFIG_KEYS = {
Expand Down Expand Up @@ -81,7 +79,7 @@ def update_schema(sublime_package_json: JsonDict, pyrightconfig_schema_json: Jso
last_component_key = setting_key.rpartition(".")[2]
if last_component_key in pyrightconfig_properties:
update_property_ref(last_component_key, setting_value, pyrightconfig_properties)
if setting_key == "python.analysis.diagnosticSeverityOverrides":
if setting_key == "basedpyright.analysis.diagnosticSeverityOverrides":
overrides_properties: JsonDict = setting_value["properties"]
for override_key, override_value in overrides_properties.items():
if override_key in pyrightconfig_properties:
Expand All @@ -92,7 +90,7 @@ def update_schema(sublime_package_json: JsonDict, pyrightconfig_schema_json: Jso
# If the property is neither in `diagnosticSeverityOverrides`, the root LSP settings nor in ignored keys
# then it might have to be added manually.
all_settings_keys = [key.rpartition(".")[2] for key in settings_properties.keys()]
all_overrides_keys = settings_properties["python.analysis.diagnosticSeverityOverrides"]["properties"].keys()
all_overrides_keys = settings_properties["basedpyright.analysis.diagnosticSeverityOverrides"]["properties"].keys()
new_schema_keys = []
for pyrightconfig_key in pyrightconfig_properties.keys():
if (
Expand Down
45 changes: 45 additions & 0 deletions sublime-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,21 @@
"reportWildcardImportFromLibrary": {
"$ref": "sublime://pyrightconfig#/properties/reportWildcardImportFromLibrary"
},
"reportUnreachable": {
"$ref": "sublime://pyrightconfig#/properties/reportUnreachable"
},
"reportAny": {
"$ref": "sublime://pyrightconfig#/properties/reportAny"
},
"reportIgnoreCommentWithoutRule": {
"$ref": "sublime://pyrightconfig#/properties/reportIgnoreCommentWithoutRule"
},
"reportPrivateLocalImportUsage": {
"$ref": "sublime://pyrightconfig#/properties/reportPrivateLocalImportUsage"
},
"reportImplicitRelativeImport": {
"$ref": "sublime://pyrightconfig#/properties/reportImplicitRelativeImport"
},
"strictDictionaryInference": {
"$ref": "sublime://pyrightconfig#/properties/strictDictionaryInference"
},
Expand Down Expand Up @@ -1068,6 +1083,36 @@
"default": "warning",
"title": "Controls reporting of wildcard import from external library"
},
"reportUnreachable": {
"$id": "#/properties/reportUnreachable",
"$ref": "#/definitions/diagnostic",
"title": "Controls reporting of unreachable code",
"default": "none"
},
"reportAny": {
"$id": "#/properties/reportAny",
"$ref": "#/definitions/diagnostic",
"title": "Controls reporting of values typed as `Any`",
"default": "none"
},
"reportIgnoreCommentWithoutRule": {
"$id": "#/properties/reportIgnoreCommentWithoutRule",
"$ref": "#/definitions/diagnostic",
"title": "Controls reporting `# type: ignore` and `# pyright: ignore` comments without specifying a rule",
"default": "none"
},
"reportPrivateLocalImportUsage": {
"$id": "#/properties/reportPrivateLocalImportUsage",
"$ref": "#/definitions/diagnostic",
"title": "Controls reporting of improper usage of symbols imported from a non-\"py.typed\" module that are not re-exported from that module. Should be used along with `reportPrivateImportUsage`",
"default": "none"
},
"reportImplicitRelativeImport": {
"$id": "#/properties/reportImplicitRelativeImport",
"$ref": "#/definitions/diagnostic",
"title": "Controls reporting of non-relative imports that do not specify the full path to the module.",
"default": "none"
},
"strict": {
"$id": "#/properties/strict",
"items": {
Expand Down

0 comments on commit 7089a9a

Please sign in to comment.