From 8f54b8447b892f64f99c65fbcea25a4b6e95a091 Mon Sep 17 00:00:00 2001 From: detachhead Date: Mon, 25 Mar 2024 17:45:38 +1000 Subject: [PATCH] use bun instead of node --- .gitignore | 6 +++-- basedpyright/langserver.py | 2 +- basedpyright/pyright.py | 2 +- basedpyright/run_bun.py | 17 ++++++++++++ basedpyright/run_node.py | 10 ------- pdm.lock | 54 ++++++++++++++------------------------ pdm_build.py | 31 +++++++++++----------- pyproject.toml | 3 ++- 8 files changed, 60 insertions(+), 65 deletions(-) create mode 100644 basedpyright/run_bun.py delete mode 100644 basedpyright/run_node.py diff --git a/.gitignore b/.gitignore index 196f2c70d..a22a3ddad 100644 --- a/.gitignore +++ b/.gitignore @@ -130,5 +130,7 @@ Thumbs.db **/__pycache__ /.venv/ -# js files copied into the basedpyright pypi package -basedpyright/*.js \ No newline at end of file +# js files copied into the basedpyright pypi package: +basedpyright/*.js +# bun installed into the basedpyright pypi package: +basedpyright/bin \ No newline at end of file diff --git a/basedpyright/langserver.py b/basedpyright/langserver.py index df9545ac4..9b5af686f 100644 --- a/basedpyright/langserver.py +++ b/basedpyright/langserver.py @@ -1,6 +1,6 @@ from __future__ import annotations -from basedpyright.run_node import run +from basedpyright.run_bun import run def main(): diff --git a/basedpyright/pyright.py b/basedpyright/pyright.py index 0ab6e768a..dbe986bbf 100644 --- a/basedpyright/pyright.py +++ b/basedpyright/pyright.py @@ -1,6 +1,6 @@ from __future__ import annotations -from basedpyright.run_node import run +from basedpyright.run_bun import run def main(): diff --git a/basedpyright/run_bun.py b/basedpyright/run_bun.py new file mode 100644 index 000000000..7db243f5f --- /dev/null +++ b/basedpyright/run_bun.py @@ -0,0 +1,17 @@ +from __future__ import annotations + +import sys +from pathlib import Path +from subprocess import call + +current_dir = Path(__file__).parent + + +def run(script_name: str): + sys.exit( + call([ + str(current_dir / "bin/bun") + (".exe" if sys.platform == "win32" else ""), + current_dir / f"{script_name}.js", + *sys.argv[1:], + ]) + ) diff --git a/basedpyright/run_node.py b/basedpyright/run_node.py deleted file mode 100644 index 08e9369a8..000000000 --- a/basedpyright/run_node.py +++ /dev/null @@ -1,10 +0,0 @@ -from __future__ import annotations - -import sys -from pathlib import Path - -from nodejs import node - - -def run(script_name: str): - sys.exit(node.call([Path(__file__).parent / f"{script_name}.js", *sys.argv[1:]])) diff --git a/pdm.lock b/pdm.lock index 35ab9fc03..87c6fc09e 100644 --- a/pdm.lock +++ b/pdm.lock @@ -5,7 +5,7 @@ groups = ["default", "dev"] strategy = ["cross_platform", "inherit_metadata"] lock_version = "4.4.1" -content_hash = "sha256:b54e5de2309b06990a20aa2e65d0214fed4936658f0fd43e9750dcd19b253878" +content_hash = "sha256:5296cdea41db2fb07ad7c5957779cf34e9097fe9ec8267a9d8edee74b1ced78d" [[package]] name = "astroid" @@ -66,22 +66,6 @@ files = [ {file = "mccabe-0.7.0.tar.gz", hash = "sha256:348e0240c33b60bbdf4e523192ef919f28cb2c3d7d5c7794f74009290f236325"}, ] -[[package]] -name = "nodejs-bin" -version = "18.4.0a4" -requires_python = "~=3.5" -summary = " Node.js is an open-source, cross-platform, back-end JavaScript\nruntime environment that runs on the V8 engine and executes JavaScript code\noutside a web browser." -groups = ["default"] -files = [ - {file = "nodejs_bin-18.4.0a4-py3-none-macosx_10_9_x86_64.whl", hash = "sha256:16cb1abf7fe8c11c574e1e474d9f934a0df49a480290eae6e733d8bb09512e22"}, - {file = "nodejs_bin-18.4.0a4-py3-none-macosx_11_0_arm64.whl", hash = "sha256:068ca987ed83ea1123775fafe5dc22d8f2ff920d7d31571e1bfe6fb1093833eb"}, - {file = "nodejs_bin-18.4.0a4-py3-none-manylinux_2_12_x86_64.manylinux2010_x86_64.whl", hash = "sha256:06cfeaa4d26eec94d8edb9927525ce94eb96dadc81f7d1daed42d1a7d003a4c9"}, - {file = "nodejs_bin-18.4.0a4-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:431ee3529f4fb226ddcfd4f14cb37e7df31238c42dfd051f4bf8f0c21029b133"}, - {file = "nodejs_bin-18.4.0a4-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:21f1f77ddc8fe05353bb6d6ee8e5a62edb3a8dcdb2740a5f9307fd8d9eef6691"}, - {file = "nodejs_bin-18.4.0a4-py3-none-win32.whl", hash = "sha256:59671fdc563dabb8be8a0b6dae4169d780482b3c9e0fba3f9aa2b7ee8d2261ac"}, - {file = "nodejs_bin-18.4.0a4-py3-none-win_amd64.whl", hash = "sha256:cbd509218b4b17f75ee7841f9c21d5cacc1626d3b823a652a6627dbad18228ec"}, -] - [[package]] name = "platformdirs" version = "4.1.0" @@ -119,28 +103,28 @@ files = [ [[package]] name = "ruff" -version = "0.3.2" +version = "0.3.4" requires_python = ">=3.7" summary = "An extremely fast Python linter and code formatter, written in Rust." groups = ["dev"] files = [ - {file = "ruff-0.3.2-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl", hash = "sha256:77f2612752e25f730da7421ca5e3147b213dca4f9a0f7e0b534e9562c5441f01"}, - {file = "ruff-0.3.2-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:9966b964b2dd1107797be9ca7195002b874424d1d5472097701ae8f43eadef5d"}, - {file = "ruff-0.3.2-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:b83d17ff166aa0659d1e1deaf9f2f14cbe387293a906de09bc4860717eb2e2da"}, - {file = "ruff-0.3.2-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:bb875c6cc87b3703aeda85f01c9aebdce3d217aeaca3c2e52e38077383f7268a"}, - {file = "ruff-0.3.2-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:be75e468a6a86426430373d81c041b7605137a28f7014a72d2fc749e47f572aa"}, - {file = "ruff-0.3.2-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:967978ac2d4506255e2f52afe70dda023fc602b283e97685c8447d036863a302"}, - {file = "ruff-0.3.2-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:1231eacd4510f73222940727ac927bc5d07667a86b0cbe822024dd00343e77e9"}, - {file = "ruff-0.3.2-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:2c6d613b19e9a8021be2ee1d0e27710208d1603b56f47203d0abbde906929a9b"}, - {file = "ruff-0.3.2-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:c8439338a6303585d27b66b4626cbde89bb3e50fa3cae86ce52c1db7449330a7"}, - {file = "ruff-0.3.2-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:de8b480d8379620cbb5ea466a9e53bb467d2fb07c7eca54a4aa8576483c35d36"}, - {file = "ruff-0.3.2-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:b74c3de9103bd35df2bb05d8b2899bf2dbe4efda6474ea9681280648ec4d237d"}, - {file = "ruff-0.3.2-py3-none-musllinux_1_2_i686.whl", hash = "sha256:f380be9fc15a99765c9cf316b40b9da1f6ad2ab9639e551703e581a5e6da6745"}, - {file = "ruff-0.3.2-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:0ac06a3759c3ab9ef86bbeca665d31ad3aa9a4b1c17684aadb7e61c10baa0df4"}, - {file = "ruff-0.3.2-py3-none-win32.whl", hash = "sha256:9bd640a8f7dd07a0b6901fcebccedadeb1a705a50350fb86b4003b805c81385a"}, - {file = "ruff-0.3.2-py3-none-win_amd64.whl", hash = "sha256:0c1bdd9920cab5707c26c8b3bf33a064a4ca7842d91a99ec0634fec68f9f4037"}, - {file = "ruff-0.3.2-py3-none-win_arm64.whl", hash = "sha256:5f65103b1d76e0d600cabd577b04179ff592064eaa451a70a81085930e907d0b"}, - {file = "ruff-0.3.2.tar.gz", hash = "sha256:fa78ec9418eb1ca3db392811df3376b46471ae93792a81af2d1cbb0e5dcb5142"}, + {file = "ruff-0.3.4-py3-none-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl", hash = "sha256:60c870a7d46efcbc8385d27ec07fe534ac32f3b251e4fc44b3cbfd9e09609ef4"}, + {file = "ruff-0.3.4-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:6fc14fa742e1d8f24910e1fff0bd5e26d395b0e0e04cc1b15c7c5e5fe5b4af91"}, + {file = "ruff-0.3.4-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d3ee7880f653cc03749a3bfea720cf2a192e4f884925b0cf7eecce82f0ce5854"}, + {file = "ruff-0.3.4-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:cf133dd744f2470b347f602452a88e70dadfbe0fcfb5fd46e093d55da65f82f7"}, + {file = "ruff-0.3.4-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:3f3860057590e810c7ffea75669bdc6927bfd91e29b4baa9258fd48b540a4365"}, + {file = "ruff-0.3.4-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:986f2377f7cf12efac1f515fc1a5b753c000ed1e0a6de96747cdf2da20a1b369"}, + {file = "ruff-0.3.4-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:c4fd98e85869603e65f554fdc5cddf0712e352fe6e61d29d5a6fe087ec82b76c"}, + {file = "ruff-0.3.4-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:64abeed785dad51801b423fa51840b1764b35d6c461ea8caef9cf9e5e5ab34d9"}, + {file = "ruff-0.3.4-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:df52972138318bc7546d92348a1ee58449bc3f9eaf0db278906eb511889c4b50"}, + {file = "ruff-0.3.4-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:98e98300056445ba2cc27d0b325fd044dc17fcc38e4e4d2c7711585bd0a958ed"}, + {file = "ruff-0.3.4-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:519cf6a0ebed244dce1dc8aecd3dc99add7a2ee15bb68cf19588bb5bf58e0488"}, + {file = "ruff-0.3.4-py3-none-musllinux_1_2_i686.whl", hash = "sha256:bb0acfb921030d00070539c038cd24bb1df73a2981e9f55942514af8b17be94e"}, + {file = "ruff-0.3.4-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:cf187a7e7098233d0d0c71175375c5162f880126c4c716fa28a8ac418dcf3378"}, + {file = "ruff-0.3.4-py3-none-win32.whl", hash = "sha256:af27ac187c0a331e8ef91d84bf1c3c6a5dea97e912a7560ac0cef25c526a4102"}, + {file = "ruff-0.3.4-py3-none-win_amd64.whl", hash = "sha256:de0d5069b165e5a32b3c6ffbb81c350b1e3d3483347196ffdf86dc0ef9e37dd6"}, + {file = "ruff-0.3.4-py3-none-win_arm64.whl", hash = "sha256:6810563cc08ad0096b57c717bd78aeac888a1bfd38654d9113cb3dc4d3f74232"}, + {file = "ruff-0.3.4.tar.gz", hash = "sha256:f0f4484c6541a99862b693e13a151435a279b271cff20e37101116a21e2a1ad1"}, ] [[package]] diff --git a/pdm_build.py b/pdm_build.py index 029ac9bda..7ed851adc 100644 --- a/pdm_build.py +++ b/pdm_build.py @@ -1,31 +1,32 @@ from __future__ import annotations +import os +import sys from json import loads from pathlib import Path from shutil import copyfile, copytree -from typing import TYPE_CHECKING, TypedDict, cast - -# https://github.com/samwillis/nodejs-pypi/pull/23 -if TYPE_CHECKING: - # https://github.com/astral-sh/ruff/issues/9528 - from subprocess import run # noqa: S404 -else: - from nodejs.npm import run -import os - -from nodejs import node +from subprocess import run +from typing import TypedDict, cast class PackageJson(TypedDict): bin: dict[str, str] -# ah yes, the classic "wrong path" moment! -os.environ["PATH"] = os.pathsep.join([str(Path(node.__file__).parent), os.environ["PATH"]]) +bun_install_dir = Path("./basedpyright") + +os.environ["BUN_INSTALL"] = str(bun_install_dir) + +bun_exe = bun_install_dir / ("bin/bun" + (".exe" if sys.platform == "win32" else "")) + +if sys.platform == "win32": + _ = run(["powershell.exe", "-c", "irm bun.sh/install.ps1|iex"], check=True) +else: + _ = run("curl -fsSL https://bun.sh/install | bash -s", shell=True, check=True) if not Path("node_modules").exists(): - _ = run(["ci"], check=True) -_ = run(["run", "build:cli:dev"], check=True) + _ = run([bun_exe, "install", "--frozen-lockfile"], check=True) +_ = run([bun_exe, "build:cli:dev"], check=True) npm_package_dir = Path("packages/pyright") pypi_package_dir = Path("basedpyright") diff --git a/pyproject.toml b/pyproject.toml index 191e0e6ff..abc47a8cc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,7 +26,6 @@ dynamic = ["version"] authors = [ { name = "detachhead", email = "detachhead@users.noreply.github.com" }, ] -dependencies = ["nodejs-bin>=18.4.0a4"] requires-python = ">=3.8" readme = "README.md" license = { text = "MIT" } @@ -157,6 +156,7 @@ max-line-length = 200 [tool.basedpyright] ignore = ["pw", "basedpyright/dist", "packages"] pythonVersion = "3.8" +pythonPlatform = "All" include = ["basedpyright", "get_version.py", "pdm_build.py"] exclude = ["pw", "basedpyright/dist", "packages"] typeCheckingMode = "all" @@ -211,6 +211,7 @@ ignore = [ "C901", # max-complexity "ISC001", # single-line-implicit-string-concatenation (conflicts with formatter) "COM812", # missing-trailing-comma (conflicts with formatter) + "S" # flake8-bandit (we aren't working with any untrusted input) ] [tool.ruff.lint.pycodestyle]