Skip to content

Commit

Permalink
use bun instead of node
Browse files Browse the repository at this point in the history
  • Loading branch information
DetachHead committed Mar 25, 2024
1 parent 211d5b0 commit 8f54b84
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 65 deletions.
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,7 @@ Thumbs.db
**/__pycache__
/.venv/

# js files copied into the basedpyright pypi package
basedpyright/*.js
# js files copied into the basedpyright pypi package:
basedpyright/*.js
# bun installed into the basedpyright pypi package:
basedpyright/bin
2 changes: 1 addition & 1 deletion basedpyright/langserver.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from basedpyright.run_node import run
from basedpyright.run_bun import run


def main():
Expand Down
2 changes: 1 addition & 1 deletion basedpyright/pyright.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from basedpyright.run_node import run
from basedpyright.run_bun import run


def main():
Expand Down
17 changes: 17 additions & 0 deletions basedpyright/run_bun.py
Original file line number Diff line number Diff line change
@@ -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:],
])
)
10 changes: 0 additions & 10 deletions basedpyright/run_node.py

This file was deleted.

54 changes: 19 additions & 35 deletions pdm.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 16 additions & 15 deletions pdm_build.py
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ dynamic = ["version"]
authors = [
{ name = "detachhead", email = "[email protected]" },
]
dependencies = ["nodejs-bin>=18.4.0a4"]
requires-python = ">=3.8"
readme = "README.md"
license = { text = "MIT" }
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 8f54b84

Please sign in to comment.