From 6e5c9c1e2534c716d4015280c9ff96632d674095 Mon Sep 17 00:00:00 2001 From: detachhead Date: Mon, 18 Nov 2024 23:08:44 +1000 Subject: [PATCH 1/9] fix issue where an outdated version of typeshed can be installed when installing the project if the docstubs have already been generated --- based_build/generate_docstubs.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/based_build/generate_docstubs.py b/based_build/generate_docstubs.py index c9ac1e0c3..d3e9a8ee2 100644 --- a/based_build/generate_docstubs.py +++ b/based_build/generate_docstubs.py @@ -1,7 +1,7 @@ from __future__ import annotations from pathlib import Path -from shutil import copytree +from shutil import copytree, rmtree from docify import main as docify # pyright:ignore[reportMissingTypeStubs] @@ -15,8 +15,9 @@ def main(): version and OS.""" stubs_path = Path("packages/pyright-internal/typeshed-fallback") stubs_with_docs_path = Path("docstubs") - if not stubs_with_docs_path.exists(): - copytree(stubs_path, stubs_with_docs_path, dirs_exist_ok=True) + if stubs_with_docs_path.exists(): + rmtree(stubs_with_docs_path) + copytree(stubs_path, stubs_with_docs_path, dirs_exist_ok=True) docify([str(stubs_with_docs_path / "stdlib"), "--if-needed", "--in-place"]) From b918f184eedc96c033b726380da6967256454e43 Mon Sep 17 00:00:00 2001 From: detachhead Date: Mon, 18 Nov 2024 23:21:49 +1000 Subject: [PATCH 2/9] update `install dependencies` vscode task to always reinstall the current project in case docstubs need to be updated --- .vscode/tasks.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.vscode/tasks.json b/.vscode/tasks.json index e786bd12d..db6bb5f98 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -80,7 +80,8 @@ "label": "install dependencies", "type": "shell", "command": "./pw", - "args": ["uv", "sync"], + // need to always reinstall the current project because docstubs may be outdated + "args": ["uv", "sync", "--reinstall-package", "basedpyright"], "presentation": { "clear": true }, From 2752d72209e2efa833b2fdb9ad7dcc4df0b9155f Mon Sep 17 00:00:00 2001 From: detachhead Date: Tue, 15 Oct 2024 22:01:25 +1000 Subject: [PATCH 3/9] don't overwrite existing docstubs when running the script for all platforms --- based_build/generate_docstubs.py | 25 ++++++++++++++++++------- pdm_build.py | 2 +- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/based_build/generate_docstubs.py b/based_build/generate_docstubs.py index d3e9a8ee2..2d1ba719e 100644 --- a/based_build/generate_docstubs.py +++ b/based_build/generate_docstubs.py @@ -6,20 +6,31 @@ from docify import main as docify # pyright:ignore[reportMissingTypeStubs] -def main(): - """adds docstrings to the stubs located in `../stubdocs` for any modules that are compiled, +def main(*, overwrite: bool): + """ + adds docstrings to the stubs located in `../stubdocs` for any modules that are compiled, because otherwise pyright would have no way to see the docstrings because there's no source code. note that it only generates stubs for modules and objects that exist on your current python - version and OS.""" + version and OS. + + :param overwrite: + whether to overwrite existing generated docstubs if they already exist. should be `True` + when running locally to avoid running with a potentially outdated version of typeshed, but + `False` in CI when generating them for all platforms because it needs to run multiple times + on the previously generated output + """ stubs_path = Path("packages/pyright-internal/typeshed-fallback") stubs_with_docs_path = Path("docstubs") - if stubs_with_docs_path.exists(): - rmtree(stubs_with_docs_path) - copytree(stubs_path, stubs_with_docs_path, dirs_exist_ok=True) + if overwrite: + if stubs_with_docs_path.exists(): + rmtree(stubs_with_docs_path) + copytree(stubs_path, stubs_with_docs_path, dirs_exist_ok=False) + elif not stubs_with_docs_path.exists(): + copytree(stubs_path, stubs_with_docs_path, dirs_exist_ok=True) docify([str(stubs_with_docs_path / "stdlib"), "--if-needed", "--in-place"]) if __name__ == "__main__": - main() + main(overwrite=False) diff --git a/pdm_build.py b/pdm_build.py index 9dafe1d5d..f00f54197 100644 --- a/pdm_build.py +++ b/pdm_build.py @@ -38,7 +38,7 @@ def pdm_build_update_files(self, context: Context, files: dict[str, Path]): npm_script_paths = cast(PackageJson, loads((npm_package_dir / package_json).read_text()))[ "bin" ].values() - generate_docstubs() + generate_docstubs(overwrite=True) run_npm("ci") run_npm("run", "build:cli:dev") From f57f62b77042d7e0fd99e17901e6ec7cc9a48316 Mon Sep 17 00:00:00 2001 From: detachhead Date: Tue, 19 Nov 2024 17:14:59 +1000 Subject: [PATCH 4/9] enable a couple ruff docstring rules for consistency --- based_build/__init__.py | 3 ++- pyproject.toml | 2 -- tests/__init__.py | 6 ++++-- tests/test_python_command.py | 6 ++++-- 4 files changed, 10 insertions(+), 7 deletions(-) diff --git a/based_build/__init__.py b/based_build/__init__.py index 0e5bcc193..a2a80f621 100644 --- a/based_build/__init__.py +++ b/based_build/__init__.py @@ -1,3 +1,4 @@ -"""this folder only exists because the `build` folder has upstream code full of basedpyright and +""" +this folder only exists because the `build` folder has upstream code full of basedpyright and ruff errors, so these scripts serve the same purpose but this one has basedpyright and ruff enabled """ diff --git a/pyproject.toml b/pyproject.toml index 6973ca8d1..eb7e4d013 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -249,9 +249,7 @@ ignore = [ "D10", # Missing docstring "D203", # 1 blank line required before class docstring "D205", # 1 blank line required between summary line and description - "D209", # Multi-line docstring closing quotes should be on a separate line "D212", # Multi-line docstring summary should start at the first line - "D213", # Multi-line docstring summary should start at the second line "D400", # First line should end with a period "D401", # First line should be in imperative mood "D403", # First word of the first line should be properly capitalized diff --git a/tests/__init__.py b/tests/__init__.py index 284220f12..96b81b08b 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1,2 +1,4 @@ -"""tests for python code. any tests for typescript code should go in -`packages/pyright-internal/src/tests` instead""" +""" +tests for python code. any tests for typescript code should go in +`packages/pyright-internal/src/tests` instead +""" diff --git a/tests/test_python_command.py b/tests/test_python_command.py index 25e05ef2e..9a891f4a3 100644 --- a/tests/test_python_command.py +++ b/tests/test_python_command.py @@ -4,8 +4,10 @@ def test_version(): - """pretty useless test, this is mainly just making sure the python wrapper scripts aren't - busted""" + """ + pretty useless test, this is mainly just making sure the python wrapper scripts aren't + busted + """ result = run(["basedpyright", "--version"], check=True, capture_output=True) assert result.returncode == 0 assert result.stdout.startswith(b"basedpyright ") From 29d557cc69752ca389efee524c3556fa17140c3c Mon Sep 17 00:00:00 2001 From: detachhead Date: Tue, 19 Nov 2024 17:40:56 +1000 Subject: [PATCH 5/9] bump pyprojectx --- pw | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pw b/pw index 2fcb0e4b1..14f0573ef 100755 --- a/pw +++ b/pw @@ -15,7 +15,7 @@ import sys from pathlib import Path from venv import EnvBuilder -VERSION = "3.0.9" +VERSION = "3.1.3" PYPROJECTX_INSTALL_DIR_ENV_VAR = "PYPROJECTX_INSTALL_DIR" PYPROJECTX_PACKAGE_ENV_VAR = "PYPROJECTX_PACKAGE" From 1bbe75cc7af8394d0580f6938c6f0a93ab4ee671 Mon Sep 17 00:00:00 2001 From: detachhead Date: Tue, 19 Nov 2024 17:42:13 +1000 Subject: [PATCH 6/9] disable a pylint rule that's now covered by ruff --- pyproject.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index eb7e4d013..f03402a34 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -163,7 +163,6 @@ enable = [ "redefined-slots-in-subclass", "redundant-returns-doc", "redundant-yields-doc", - "shallow-copy-environ", "useless-param-doc", "useless-parent-delegation", "useless-type-doc", From 6a2c8d89c7fc50f80a9f4e9b4d75a0b965315688 Mon Sep 17 00:00:00 2001 From: detachhead Date: Tue, 19 Nov 2024 17:46:24 +1000 Subject: [PATCH 7/9] add `regenerate_docstubs` config setting to prevent generated docstubs from being replaced in ci --- .github/workflows/build_and_release.yml | 6 ++++-- pdm_build.py | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build_and_release.yml b/.github/workflows/build_and_release.yml index ded0621d0..5d2da43d7 100644 --- a/.github/workflows/build_and_release.yml +++ b/.github/workflows/build_and_release.yml @@ -7,6 +7,8 @@ env: VSIX_DIR: packages/vscode-pyright NPM_PACKAGE_DIR: packages/pyright BROWSER_NPM_PACKAGE_DIR: packages/browser-pyright + # prevent uv from constantly reinstalling the project and overwriting docstubs + UV_NO_SYNC: true on: push @@ -87,7 +89,7 @@ jobs: name: docstubs path: docstubs - - run: ./pw uv sync + - run: ./pw uv sync --config-setting regenerate_docstubs=false # using relative path for npm scripts because it needs to work in the package directories too - name: add pyprojectx and npm scripts to PATH @@ -177,7 +179,7 @@ jobs: run: npm version ${{ steps.current-version.outputs.CURRENT_UPSTREAM_VERSION }} --workspaces --no-git-tag-version - name: build package - pypi - run: uv build + run: uv build --config-setting regenerate_docstubs=false - uses: actions/upload-artifact@v4 with: name: dist diff --git a/pdm_build.py b/pdm_build.py index f00f54197..06ce8db28 100644 --- a/pdm_build.py +++ b/pdm_build.py @@ -38,7 +38,8 @@ def pdm_build_update_files(self, context: Context, files: dict[str, Path]): npm_script_paths = cast(PackageJson, loads((npm_package_dir / package_json).read_text()))[ "bin" ].values() - generate_docstubs(overwrite=True) + if context.builder.config_settings.get("regenerate_docstubs") != "false": + generate_docstubs(overwrite=True) run_npm("ci") run_npm("run", "build:cli:dev") From dff7abe83439dc2143f0d2167e24241843730444 Mon Sep 17 00:00:00 2001 From: detachhead Date: Tue, 19 Nov 2024 18:51:48 +1000 Subject: [PATCH 8/9] fix all dependencies being incorrectly installed in `generateAllDocstubs.sh` --- based_build/generateAllDocstubs.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/based_build/generateAllDocstubs.sh b/based_build/generateAllDocstubs.sh index c4e37df55..8dc6735ae 100755 --- a/based_build/generateAllDocstubs.sh +++ b/based_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 npm run generate-docstubs + ./pw uv run --no-sync based_build/generate_docstubs.py done \ No newline at end of file From 9b336fa07d85d3f0bbaa8764be1d742ae13e2894 Mon Sep 17 00:00:00 2001 From: detachhead Date: Tue, 19 Nov 2024 20:00:48 +1000 Subject: [PATCH 9/9] disable `T201` ruff rule (print statements) for build scripts --- pyproject.toml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index f03402a34..cf93dde4b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -270,8 +270,13 @@ ignore-overlong-task-comments = true [tool.ruff.lint.per-file-ignores] "*.pyi" = ["A001", "A002", "N"] # we don't control names in 3rd party modules "{tests,based_build}/**/*.py" = [ - "S", # none of these security focused rules are relevant for tests/build scripts + "S", # none of these security focused rules are relevant for tests/build scripts + "T201", ] +"based_build/**/*.py" = [ + "T201", # print +] + [tool.ruff.lint.isort] combine-as-imports = true required-imports = ["from __future__ import annotations"]