Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Can't include nested data files in built wheel #206

Merged
merged 2 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: [3.7, 3.8, 3.9, "3.10", "3.11", "pypy-3.7", "pypy-3.8"]
python-version: [3.7, 3.8, 3.9, "3.10", "3.11", "3.12", "pypy-3.7", "pypy-3.8"]
os: [ubuntu-latest, macOS-latest, windows-latest]

steps:
Expand Down
9 changes: 7 additions & 2 deletions src/pdm/backend/hooks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,16 @@ def ensure_build_dir(self) -> Path:
return self.build_dir

def expand_paths(self, path: str) -> Iterable[Path]:
def path_filter(p: Path) -> bool:
return p.is_file() or p.is_symlink()

plib_path = Path(path)
if plib_path.parts and plib_path.parts[0] == "${BUILD_DIR}":
return self.build_dir.glob(Path(*plib_path.parts[1:]).as_posix())
return filter(
path_filter, self.build_dir.glob(Path(*plib_path.parts[1:]).as_posix())
)

return self.root.glob(path)
return filter(path_filter, self.root.glob(path))


class BuildHookInterface(Protocol):
Expand Down
5 changes: 3 additions & 2 deletions src/pdm/backend/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,10 @@ def get_files(self, context: Context) -> Iterable[tuple[str, Path]]:
def _get_wheel_data(self, context: Context) -> Iterable[tuple[str, Path]]:
for name, paths in context.config.build_config.wheel_data.items():
for path in paths:
relative_to: str | None = None
relative_to: Path | None = None
if not isinstance(path, str):
relative_to = path.get("relative-to")
if path.get("relative-to"):
relative_to = context.root / path["relative-to"]
path = path["path"]
for child in context.expand_paths(path):
relpath = (
Expand Down
35 changes: 23 additions & 12 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
import shutil
import subprocess
from pathlib import Path
from typing import Generator

import pytest

from pdm.backend import utils
from tests import FIXTURES


@pytest.fixture()
def project_with_scm(tmp_path):
project = FIXTURES / "projects/demo-using-scm"
shutil.copytree(project, tmp_path / project.name)
with utils.cd(tmp_path / project.name):
subprocess.check_call(["git", "init"])
subprocess.check_call(["git", "config", "user.email", "[email protected]"])
subprocess.check_call(["git", "config", "user.name", "Name"])
subprocess.check_call(["git", "add", "."])
subprocess.check_call(["git", "commit", "-m", "initial commit"])
subprocess.check_call(["git", "tag", "-a", "0.1.0", "-m", "version 0.1.0"])
yield tmp_path / project.name
@pytest.fixture
def fixture_project(tmp_path: Path, name: str) -> Generator[Path, None, None]:
project = FIXTURES / "projects" / name
shutil.copytree(project, tmp_path / name)
with utils.cd(tmp_path / name):
yield tmp_path / name


@pytest.fixture
def dist(tmp_path: Path) -> Path:
return tmp_path / "dist"


@pytest.fixture
def scm(fixture_project: Path) -> None:
subprocess.check_call(["git", "init"])
subprocess.check_call(["git", "config", "user.email", "[email protected]"])
subprocess.check_call(["git", "config", "user.name", "Name"])
subprocess.check_call(["git", "add", "."])
subprocess.check_call(["git", "commit", "-m", "initial commit"])
subprocess.check_call(["git", "tag", "-a", "0.1.0", "-m", "version 0.1.0"])
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ excludes = [
source-includes = ["scripts/"]

[tool.pdm.build.wheel-data]
scripts = ["scripts/*"]
scripts = ["scripts/**/*"]
Loading