Skip to content

Commit

Permalink
➖ deps: rm pdm-pyfuture dep
Browse files Browse the repository at this point in the history
  • Loading branch information
zrr1999 committed Dec 16, 2023
1 parent 2004d4c commit ffc4ec5
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 6 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
permissions:
contents: write
jobs:
deploy:
build:
strategy:
matrix:
python-version: [3.12]
Expand All @@ -25,5 +25,5 @@ jobs:
python-version: ${{ matrix.python-version }}
- name: Publish package distributions to PyPI
run: |
pdm install --no-isolation
pdm install
pdm build --no-isolation
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
python-version: "3.12"
- name: Build package 👷‍♂️
run: |
pdm install --no-isolation
pdm install
PDM_BUILD_SCM_VERSION=${{ github.ref_name }} PYFUTURE_TARGET=${{ matrix.target-version }} pdm build --no-isolation
- name: Upload wheels 👷‍♂️
uses: actions/upload-artifact@v3
Expand Down
21 changes: 20 additions & 1 deletion pdm_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os
import sys
from pathlib import Path
from typing import TYPE_CHECKING

if TYPE_CHECKING:
Expand All @@ -14,4 +15,22 @@ def pdm_build_hook_enabled(context: Context):
if context.target == "editable" and not os.path.exists(".pdm-python"):
with open(".pdm-python", "w") as f:
f.write(sys.executable)
return False

return context.target == "wheel"


def pdm_build_initialize(context: Context) -> None:
from pyfuture.hooks import pdm as pyfuture_pdm_hooks

hook_config = pyfuture_pdm_hooks.get_hook_config(context)
target_str = pyfuture_pdm_hooks.get_target_str(hook_config)
pyfuture_pdm_hooks.pdm_build_initialize(context, target_str)


def pdm_build_update_files(context: Context, files: dict[str, Path]) -> None:
from pyfuture.hooks import pdm as pyfuture_pdm_hooks

hook_config = pyfuture_pdm_hooks.get_hook_config(context)
target_str = pyfuture_pdm_hooks.get_target_str(hook_config)
target = pyfuture_pdm_hooks.get_target(target_str)
pyfuture_pdm_hooks.pdm_build_update_files(context, files, target)
Empty file added pyfuture/hooks/__init__.py
Empty file.
48 changes: 48 additions & 0 deletions pyfuture/hooks/pdm.py
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)
5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ required-imports = ["from __future__ import annotations"]
[tool.pyright]
include = ["pyfuture"]
exclude = [
"pdm_build.py"
"pdm_build.py",
"pyfuture/hooks/",
]

[tool.pdm.dev-dependencies]
Expand All @@ -77,5 +78,5 @@ includes = ["pyfuture"]
target = "py38"

[build-system]
requires = ["pdm-backend", "pdm-pyfuture"]
requires = ["pdm-backend"]
build-backend = "pdm.backend"

0 comments on commit ffc4ec5

Please sign in to comment.