From 7c119b45b290b435f75bec3f74b597450a2fb5a6 Mon Sep 17 00:00:00 2001 From: detachhead Date: Mon, 25 Nov 2024 20:57:41 +1000 Subject: [PATCH 1/2] pin the python version used for local development and separate build scripts into separate modules based on which python versions they can run on --- .basedpyright/baseline.json | 116 ++++++-------------- .python-version | 1 + build/generateAllDocstubs.sh | 2 +- build/py3_13/__init__.py | 4 + build/{ => py3_13}/docs_macros.py | 4 +- build/{ => py3_13}/generateUnicodeTables.py | 0 build/{ => py3_13}/localization_helper.py | 0 build/py3_13/ruff.toml | 2 + build/py3_8/__init__.py | 1 + build/{ => py3_8}/generate_docstubs.py | 0 build/{ => py3_8}/get_version.py | 4 +- mkdocs.yml | 2 +- package.json | 4 +- pdm_build.py | 2 +- pyproject.toml | 9 +- 15 files changed, 59 insertions(+), 92 deletions(-) create mode 100644 .python-version create mode 100644 build/py3_13/__init__.py rename build/{ => py3_13}/docs_macros.py (93%) rename build/{ => py3_13}/generateUnicodeTables.py (100%) rename build/{ => py3_13}/localization_helper.py (100%) create mode 100644 build/py3_13/ruff.toml create mode 100644 build/py3_8/__init__.py rename build/{ => py3_8}/generate_docstubs.py (100%) rename build/{ => py3_8}/get_version.py (60%) diff --git a/.basedpyright/baseline.json b/.basedpyright/baseline.json index 5fe309e6bc..6d95e6af7f 100644 --- a/.basedpyright/baseline.json +++ b/.basedpyright/baseline.json @@ -1,14 +1,6 @@ { "files": { - "./build/generateUnicodeTables.py": [ - { - "code": "reportGeneralTypeIssues", - "range": { - "startColumn": 61, - "endColumn": 62, - "lineCount": 1 - } - }, + "./build/py3_13/generateUnicodeTables.py": [ { "code": "reportUnannotatedClassAttribute", "range": { @@ -65,54 +57,6 @@ "lineCount": 1 } }, - { - "code": "reportIndexIssue", - "range": { - "startColumn": 32, - "endColumn": 36, - "lineCount": 1 - } - }, - { - "code": "reportIndexIssue", - "range": { - "startColumn": 30, - "endColumn": 34, - "lineCount": 1 - } - }, - { - "code": "reportIndexIssue", - "range": { - "startColumn": 50, - "endColumn": 54, - "lineCount": 1 - } - }, - { - "code": "reportGeneralTypeIssues", - "range": { - "startColumn": 41, - "endColumn": 42, - "lineCount": 1 - } - }, - { - "code": "reportGeneralTypeIssues", - "range": { - "startColumn": 28, - "endColumn": 29, - "lineCount": 1 - } - }, - { - "code": "reportIndexIssue", - "range": { - "startColumn": 65, - "endColumn": 69, - "lineCount": 1 - } - }, { "code": "reportUnusedCallResult", "range": { @@ -129,14 +73,6 @@ "lineCount": 1 } }, - { - "code": "reportGeneralTypeIssues", - "range": { - "startColumn": 41, - "endColumn": 42, - "lineCount": 1 - } - }, { "code": "reportUnusedCallResult", "range": { @@ -161,14 +97,6 @@ "lineCount": 1 } }, - { - "code": "reportIndexIssue", - "range": { - "startColumn": 59, - "endColumn": 63, - "lineCount": 1 - } - }, { "code": "reportUnusedCallResult", "range": { @@ -185,14 +113,6 @@ "lineCount": 3 } }, - { - "code": "reportGeneralTypeIssues", - "range": { - "startColumn": 38, - "endColumn": 39, - "lineCount": 1 - } - }, { "code": "reportUnusedCallResult", "range": { @@ -249,6 +169,40 @@ "lineCount": 18 } } + ], + "./build/py3_13/localization_helper.py": [ + { + "code": "reportDeprecated", + "range": { + "startColumn": 44, + "endColumn": 48, + "lineCount": 1 + } + }, + { + "code": "reportDeprecated", + "range": { + "startColumn": 61, + "endColumn": 66, + "lineCount": 1 + } + }, + { + "code": "reportDeprecated", + "range": { + "startColumn": 14, + "endColumn": 18, + "lineCount": 1 + } + }, + { + "code": "reportDeprecated", + "range": { + "startColumn": 24, + "endColumn": 29, + "lineCount": 1 + } + } ] } } \ No newline at end of file diff --git a/.python-version b/.python-version new file mode 100644 index 0000000000..24ee5b1be9 --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.13 diff --git a/build/generateAllDocstubs.sh b/build/generateAllDocstubs.sh index a4d5d32a66..d55c854a1f 100755 --- a/build/generateAllDocstubs.sh +++ b/build/generateAllDocstubs.sh @@ -1,5 +1,5 @@ for pythonVersion in 3.13 3.12 3.11 3.10 3.9 3.8; do ./pw uv venv --python $pythonVersion ./pw uv sync --only-group=docstubs --no-install-project - ./pw uv run --no-sync build/generate_docstubs.py + ./pw uv run --no-sync build/py3_8/generate_docstubs.py done \ No newline at end of file diff --git a/build/py3_13/__init__.py b/build/py3_13/__init__.py new file mode 100644 index 0000000000..40bb4eb60d --- /dev/null +++ b/build/py3_13/__init__.py @@ -0,0 +1,4 @@ +""" +scripts that are only run during development so they only need to be compatible with the version of +python pinned in `.python-version` +""" diff --git a/build/docs_macros.py b/build/py3_13/docs_macros.py similarity index 93% rename from build/docs_macros.py rename to build/py3_13/docs_macros.py index ae50439bfa..dc77d0c34f 100644 --- a/build/docs_macros.py +++ b/build/py3_13/docs_macros.py @@ -3,9 +3,11 @@ import json from functools import partial from subprocess import run as stupid_run -from typing import TYPE_CHECKING, Iterable +from typing import TYPE_CHECKING if TYPE_CHECKING: + from collections.abc import Iterable + from mkdocs_macros.plugin import MacrosPlugin run = partial(stupid_run, check=True, capture_output=True) diff --git a/build/generateUnicodeTables.py b/build/py3_13/generateUnicodeTables.py similarity index 100% rename from build/generateUnicodeTables.py rename to build/py3_13/generateUnicodeTables.py diff --git a/build/localization_helper.py b/build/py3_13/localization_helper.py similarity index 100% rename from build/localization_helper.py rename to build/py3_13/localization_helper.py diff --git a/build/py3_13/ruff.toml b/build/py3_13/ruff.toml new file mode 100644 index 0000000000..b257eca357 --- /dev/null +++ b/build/py3_13/ruff.toml @@ -0,0 +1,2 @@ +extend = "../../pyproject.toml" +target-version = "py313" diff --git a/build/py3_8/__init__.py b/build/py3_8/__init__.py new file mode 100644 index 0000000000..ca5cff40dc --- /dev/null +++ b/build/py3_8/__init__.py @@ -0,0 +1 @@ +"""scripts that may be run on older versions of python so need to be compatible with 3.8""" diff --git a/build/generate_docstubs.py b/build/py3_8/generate_docstubs.py similarity index 100% rename from build/generate_docstubs.py rename to build/py3_8/generate_docstubs.py diff --git a/build/get_version.py b/build/py3_8/get_version.py similarity index 60% rename from build/get_version.py rename to build/py3_8/get_version.py index f43ddc3733..776a8ac695 100644 --- a/build/get_version.py +++ b/build/py3_8/get_version.py @@ -9,8 +9,6 @@ def get_version() -> str: return cast( str, loads( - ( - Path(__file__).parent.parent / "packages/pyright-internal/src/version.json" - ).read_text() + (Path(__file__).parents[2] / "packages/pyright-internal/src/version.json").read_text() ), ) diff --git a/mkdocs.yml b/mkdocs.yml index 2836d867c9..acf025ef15 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -51,7 +51,7 @@ plugins: # https://github.com/wilhelmer/mkdocs-unused-files/issues/12 # - unused_files - macros: - module_name: build/docs_macros + module_name: build/py3_13/docs_macros on_undefined: strict nav: - index.md diff --git a/package.json b/package.json index 1d5c1e9d26..0aaf37db04 100644 --- a/package.json +++ b/package.json @@ -24,8 +24,8 @@ "ruff-fix": "uv run --no-sync ruff check --fix && pw uv run --no-sync ruff format --fix", "pylint": "uv run --no-sync pylint basedpyright build pdm_build.py", "test-python": "uv run --no-sync pytest tests", - "generate-docstubs": "uv run --no-sync build/generate_docstubs.py", - "localization-helper": "uv run --no-sync build/localization_helper.py", + "generate-docstubs": "uv run --no-sync build/py3_8/generate_docstubs.py", + "localization-helper": "uv run --no-sync build/py3_8/localization_helper.py", "docs": "uv run --no-sync mkdocs serve" }, "devDependencies": { diff --git a/pdm_build.py b/pdm_build.py index 11e2cb40c7..cd5f4ec87e 100644 --- a/pdm_build.py +++ b/pdm_build.py @@ -9,7 +9,7 @@ from pdm.backend.hooks.base import BuildHookInterface from typing_extensions import override -from build.generate_docstubs import main as generate_docstubs +from build.py3_8.generate_docstubs import main as generate_docstubs if TYPE_CHECKING: from pdm.backend.hooks import Context diff --git a/pyproject.toml b/pyproject.toml index fa0bfd313d..43488a64af 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -72,7 +72,7 @@ default-groups = ["dev", "docstubs", "lochelper"] [tool.pdm.version] source = "call" -getter = "build.get_version:get_version" +getter = "build.py3_8.get_version:get_version" [tool.pdm.build] excludes = ["tests/", "pdm_build.py"] @@ -197,6 +197,8 @@ ignore = ["pw", "basedpyright/dist", "packages", "docstubs"] exclude = ["pw", "basedpyright/dist", "packages", "docstubs"] reportImplicitStringConcatenation = false # conflicts with ruff formatter +executionEnvironments = [{ root = 'build/py3_13', pythonVersion = '3.13' }] + # currently commented out due to https://github.com/DetachHead/basedpyright/issues/570 # only seem to be needed when using pycharm, which i dont really care about anyway because pycharm sucks # venvPath = "." @@ -214,7 +216,7 @@ extend-exclude = [ "packages/pyright-internal/typeshed-fallback", "docstubs", "packages/pyright-internal/src/tests/samples", - "build/generateUnicodeTables.py", # comes from upstream + "build/py3_13/generateUnicodeTables.py", # comes from upstream ] [tool.ruff.lint] @@ -229,6 +231,9 @@ ignore = [ "ISC001", # single-line-implicit-string-concatenation (conflicts with formatter) "COM812", # missing-trailing-comma (conflicts with formatter) "PLC0414", # Import alias does not rename original package (used by basedpyright for explicit re-export) + "UP035", # deprecated-import (covered by basedpyright deprecateTypingAliases) + "UP006", # non-pep585-annotation (covered by basedpyright deprecateTypingAliases) + "UP007", # non-pep604-annotation (covered by basedpyright deprecateTypingAliases) # rules i disabled because i don't like them: "EM", # flake8-errmsg From 8bbc6ebd735033bec2df5c753456783ac0d3bbde Mon Sep 17 00:00:00 2001 From: detachhead Date: Mon, 25 Nov 2024 23:12:41 +1000 Subject: [PATCH 2/2] update ci stuff that wasn't configured to run on 3.13 --- .github/workflows/build_and_release.yml | 2 +- .github/workflows/validation.yml | 2 +- pyproject.toml | 5 ++++- tests/ruff.toml | 2 ++ tests/test_generate_docstubs.py | 9 +++------ 5 files changed, 11 insertions(+), 9 deletions(-) create mode 100644 tests/ruff.toml diff --git a/.github/workflows/build_and_release.yml b/.github/workflows/build_and_release.yml index bb63600893..1255ba8632 100644 --- a/.github/workflows/build_and_release.yml +++ b/.github/workflows/build_and_release.yml @@ -1,7 +1,7 @@ name: 'build and release' env: - PYTHON_VERSION: '3.12' + PYTHON_VERSION: '3.13' ARTIFACT_NAME_VSIX: vsix VSIX_NAME: vscode-pyright.vsix VSIX_DIR: packages/vscode-pyright diff --git a/.github/workflows/validation.yml b/.github/workflows/validation.yml index 0e50f4edee..bbf39c7774 100644 --- a/.github/workflows/validation.yml +++ b/.github/workflows/validation.yml @@ -1,7 +1,7 @@ name: 'Validation' env: - PYTHON_VERSION: 3.11 + PYTHON_VERSION: 3.13 on: pull_request: diff --git a/pyproject.toml b/pyproject.toml index 43488a64af..aa593110c8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -197,7 +197,10 @@ ignore = ["pw", "basedpyright/dist", "packages", "docstubs"] exclude = ["pw", "basedpyright/dist", "packages", "docstubs"] reportImplicitStringConcatenation = false # conflicts with ruff formatter -executionEnvironments = [{ root = 'build/py3_13', pythonVersion = '3.13' }] +executionEnvironments = [ + { root = 'build/py3_13', pythonVersion = '3.13' }, + { root = 'tests', pythonVersion = '3.13' }, +] # currently commented out due to https://github.com/DetachHead/basedpyright/issues/570 # only seem to be needed when using pycharm, which i dont really care about anyway because pycharm sucks diff --git a/tests/ruff.toml b/tests/ruff.toml new file mode 100644 index 0000000000..6f6016d74d --- /dev/null +++ b/tests/ruff.toml @@ -0,0 +1,2 @@ +extend = "../pyproject.toml" +target-version = "py313" diff --git a/tests/test_generate_docstubs.py b/tests/test_generate_docstubs.py index 20b64bf2e8..023e83bd4f 100644 --- a/tests/test_generate_docstubs.py +++ b/tests/test_generate_docstubs.py @@ -10,15 +10,12 @@ from functools import wraps from locale import getpreferredencoding from pathlib import Path -from typing import TYPE_CHECKING, Callable +from typing import Callable from pytest import mark -if TYPE_CHECKING: - from basedtyping import P, T - -def needs_all_docstubs( +def needs_all_docstubs[T, **P]( condition_to_run_locally: bool, # noqa: FBT001 ) -> Callable[[Callable[P, T]], Callable[P, T]]: def decorator(fn: Callable[P, T]) -> Callable[P, T]: @@ -45,7 +42,7 @@ def read_module_text(name: str): def test_builtin_docstring(): assert ''' class float: - """Convert a string or number to a floating point number, if possible.""" + """Convert a string or number to a floating-point number, if possible.""" ''' in read_module_text("builtins.pyi")