-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
74 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from __future__ import annotations | ||
|
||
import os | ||
import sys | ||
from pathlib import Path | ||
from typing import TYPE_CHECKING | ||
|
||
from pyfuture.utils import transfer_file | ||
|
||
if TYPE_CHECKING: | ||
from pdm.backend.hooks.base import Context | ||
|
||
|
||
def get_target_str(hook_config: dict) -> str | None: | ||
target_str = os.environ.get("PYFUTURE_TARGET", None) | ||
if target_str is None: | ||
target_str = hook_config.get("target", None) | ||
return target_str | ||
|
||
|
||
def get_target(target_str: str | None) -> tuple[int, int]: | ||
if target_str is None: | ||
return sys.version_info[:2] | ||
else: | ||
return (int(target_str[2:3]), int(target_str[3:])) | ||
|
||
|
||
def get_hook_config(context: Context) -> dict: | ||
return context.config.data.get("tool", {}).get("pdm", {}).get("build", {}).get("hooks", {}).get("pyfuture", {}) | ||
|
||
|
||
def pdm_build_initialize(context: Context, target_str: str | None) -> None: | ||
context.config.build_config["is-purelib"] = True | ||
if target_str is not None: | ||
context.builder.config_settings["--python-tag"] = target_str | ||
|
||
|
||
def pdm_build_update_files(context: Context, files: dict[str, Path], target: tuple[int, int]) -> None: | ||
build_dir = context.ensure_build_dir() | ||
package_dir = Path(context.config.build_config.package_dir) | ||
includes = context.config.build_config.includes | ||
for include in includes: | ||
src_path = package_dir / include | ||
tgt_path = build_dir / include | ||
for src_file in src_path.glob("**/*.py"): | ||
tgt_file = tgt_path / src_file.relative_to(src_path) | ||
files[f"{tgt_file.relative_to(build_dir)}"] = tgt_file | ||
transfer_file(src_file, tgt_file, target=target) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters