Skip to content

Commit

Permalink
revert changes to pdm_build script because it was broken or somethi…
Browse files Browse the repository at this point in the history
…ng. no clue how it works but it seems to run too early before pdm actually does anything, and i dont have the patience to figure out why
  • Loading branch information
DetachHead committed Mar 29, 2024
1 parent 64640d4 commit 94ab71d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 83 deletions.
79 changes: 19 additions & 60 deletions pdm.lock

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

38 changes: 16 additions & 22 deletions pdm_build.py
Original file line number Diff line number Diff line change
@@ -1,43 +1,37 @@
from __future__ import annotations

import os
from json import loads
from pathlib import Path
from shutil import copyfile, copytree
from typing import TYPE_CHECKING, TypedDict, cast

from nodejs import node

# https://github.com/samwillis/nodejs-pypi/pull/23
if TYPE_CHECKING:
# https://github.com/samwillis/nodejs-pypi/pull/23
# https://github.com/astral-sh/ruff/issues/9528
from subprocess import run # noqa: S404

from pdm.backend.hooks import Context
else:
from nodejs.npm import run
import os


# these are hook functions where all args are required regardless of whether or not they are used
# ruff: noqa: ARG001
from nodejs import node


class PackageJson(TypedDict):
bin: dict[str, str]


def pdm_build_update_files(context: Context, files: dict[str, Path]):
# ah yes, the classic "wrong path" moment!
os.environ["PATH"] = os.pathsep.join([str(Path(node.__file__).parent), os.environ["PATH"]])
# ah yes, the classic "wrong path" moment!
os.environ["PATH"] = os.pathsep.join([str(Path(node.__file__).parent), os.environ["PATH"]])

if not Path("node_modules").exists():
_ = run(["ci"], check=True)
_ = run(["run", "build:cli:dev"], check=True)
if not Path("node_modules").exists():
_ = run(["ci"], check=True)
_ = run(["run", "build:cli:dev"], check=True)

npm_package_dir = Path("packages/pyright")
pypi_package_dir = Path("basedpyright")
npm_package_dir = Path("packages/pyright")
pypi_package_dir = Path("basedpyright")

copytree(npm_package_dir / "dist", pypi_package_dir / "dist", dirs_exist_ok=True)
for script_path in cast(PackageJson, loads((npm_package_dir / "package.json").read_text()))[
"bin"
].values():
_ = copyfile(npm_package_dir / script_path, pypi_package_dir / script_path)
copytree(npm_package_dir / "dist", pypi_package_dir / "dist", dirs_exist_ok=True)
for script_path in cast(PackageJson, loads((npm_package_dir / "package.json").read_text()))[
"bin"
].values():
_ = copyfile(npm_package_dir / script_path, pypi_package_dir / script_path)
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ distribution = true
dev = [
"pylint>=3.0.0a7",
"ruff>=0.2.2",
"pdm-backend>=2.1.8", # only used here for types in pdm_build.py
]

[tool.pdm.version]
Expand Down

0 comments on commit 94ab71d

Please sign in to comment.