how do i add additional files to a wheel? #2946
-
i'm having a lot of trouble figuring out how to build the wheel for my package. for context, my project is an npm package wrapped in a python package, so the build process needs to install the npm dependencies and build the npm package, then move it into the wheel. currently, i have a to fix this, i tried rewriting it to use def pdm_build_update_files(context: Context, files: dict[str, Path]):
run_npm("ci")
run_npm("run", "build:cli:dev")
npm_package_dir = Path("packages/pyright")
pypi_package_dir = Path("basedpyright")
dist_dir = Path("dist")
npm_script_paths = cast(PackageJson, loads((npm_package_dir / "package.json").read_text()))[
"bin"
].values()
for file in (npm_package_dir / dist_dir).rglob("**/*"):
if not file.is_dir():
files[str(file.relative_to(npm_package_dir))] = file
for script_path in npm_script_paths:
files[script_path] = pypi_package_dir / script_path so then i rewrote it to be more like what i had originally, where it just manually copies the files into the python package's directory: def pdm_build_update_files(context: Context, files: dict[str, Path]):
run_npm("ci")
run_npm("run", "build:cli:dev")
npm_package_dir = Path("packages/pyright")
pypi_package_dir = Path("basedpyright")
dist_dir = Path("dist")
npm_script_paths = cast(PackageJson, loads((npm_package_dir / "package.json").read_text()))[
"bin"
].values()
copytree(npm_package_dir / dist_dir, pypi_package_dir / dist_dir, dirs_exist_ok=True)
for script_path in npm_script_paths:
_ = copyfile(npm_package_dir / script_path, pypi_package_dir / script_path) this works with editable installs, but when installing it in non-editable mode, the files don't seem to get copied into the wheel. the last thing i tried was using a def pdm_build_initialize(context: Context) -> None:
_ = context.ensure_build_dir()
run_npm("ci")
run_npm("run", "build:cli:dev") [tool.pdm.build.wheel-data]
include = [
{ path = "packages/pyright/dist/**/*", relative-to = "packages/pyright/" },
{ path = "packages/pyright/*.js", relative-to = "packages/" },
] this didn't work either. when attempting to install it, i get this error:
any guidance would be appreciated as i have no clue what i'm doing lol |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
ok so i got it working. it turns out i need to update the here's what my hook looks like now, which seems to work: def pdm_build_update_files(context: Context, files: dict[str, Path]):
context.ensure_build_dir()
run_npm("ci")
run_npm("run", "build:cli:dev")
npm_package_dir = Path("packages/pyright")
pypi_package_dir = Path("basedpyright")
dist_dir = Path("dist")
npm_script_paths = cast(PackageJson, loads((npm_package_dir / "package.json").read_text()))[
"bin"
].values()
if context.target == "editable":
copytree(npm_package_dir / dist_dir, pypi_package_dir / dist_dir, dirs_exist_ok=True)
for script_path in npm_script_paths:
_ = copyfile(npm_package_dir / script_path, pypi_package_dir / script_path)
else:
for file in (npm_package_dir / dist_dir).rglob("**/*"):
if file.is_file():
files[str(pypi_package_dir / file.relative_to(npm_package_dir))] = file
for script_path in npm_script_paths:
files[str(pypi_package_dir / script_path)] = npm_package_dir / script_path as for i did find out by digging through the source code of the also, those docs mention have a lot of references to this |
Beta Was this translation helpful? Give feedback.
ok so i got it working. it turns out i need to update the
files
dict when building the wheel, but copy the files normally when doing an editable install. i also realized the files were being copied to the same level as my package, instead of inside the package itself (ie. it was copying the files to a separate package calleddist
insite-packages
instead of inbasedpyright/dist
) because i wasn't includingpypi_package_dir
in the keys when updating thefiles
dict.here's what my hook looks like now, which seems to work: