Skip to content

Commit

Permalink
Replaced the use of pep517 with pyproject-hooks because of the re…
Browse files Browse the repository at this point in the history
…name.
  • Loading branch information
KOLANICH committed Nov 22, 2022
1 parent 4475cf1 commit edcd0fd
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 40 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[![PyPI version](https://badge.fury.io/py/build.svg)](https://pypi.org/project/build/)
[![Discord](https://img.shields.io/discord/803025117553754132?label=Discord%20chat%20%23build&style=flat-square)](https://discord.gg/pypa)

A simple, correct PEP 517 build frontend.
A simple, correct python package build frontend.

See the [documentation](https://pypa-build.readthedocs.io/en/latest/) for more information.

Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "flit_core.buildapi"
[project]
name = "build"
version = "0.9.0"
description = "A simple, correct PEP 517 build frontend"
description = "A simple, correct python package build frontend"
readme = "README.md"
requires-python = ">= 3.7"
license.file = "LICENSE"
Expand All @@ -32,7 +32,7 @@ urls.changelog = "https://pypa-build.readthedocs.io/en/stable/changelog.html"

dependencies = [
"packaging >= 19.0",
"pep517 >= 0.9.1",
"pyproject_hooks",
# not actually a runtime dependency, only supplied as there is not "recommended dependency" support
'colorama; os_name == "nt"',
'importlib-metadata >= 0.22; python_version < "3.8"',
Expand Down Expand Up @@ -124,7 +124,7 @@ enable_error_code = ["ignore-without-code", "truthy-bool", "redundant-expr"]
[[tool.mypy.overrides]]
module = [
"colorama", # Optional dependency
"pep517.*", # Untyped
"pyproject_hooks.*", # Untyped
"virtualenv", # Optional dependency
]
ignore_missing_imports = true
Expand Down
10 changes: 5 additions & 5 deletions src/build/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from collections.abc import Iterator, Set
from typing import Any, Callable, Mapping, MutableMapping, Optional, Sequence, Tuple, Type, Union

import pep517.wrappers
import pyproject_hooks


TOMLDecodeError: type[Exception]
Expand Down Expand Up @@ -243,7 +243,7 @@ def __init__(
srcdir: PathType,
python_executable: str = sys.executable,
scripts_dir: str | None = None,
runner: RunnerType = pep517.wrappers.default_subprocess_runner,
runner: RunnerType = pyproject_hooks.default_subprocess_runner,
) -> None:
"""
:param srcdir: The source directory
Expand Down Expand Up @@ -282,7 +282,7 @@ def __init__(
self._backend = self._build_system['build-backend']
self._scripts_dir = scripts_dir
self._hook_runner = runner
self._hook = pep517.wrappers.Pep517HookCaller(
self._hook = pyproject_hooks.BuildBackendHookCaller(
self.srcdir,
self._backend,
backend_path=self._build_system.get('backend-path'),
Expand Down Expand Up @@ -388,7 +388,7 @@ def prepare(
_allow_fallback=False,
)
except BuildBackendException as exception:
if isinstance(exception.exception, pep517.wrappers.HookMissing):
if isinstance(exception.exception, pyproject_hooks.HookMissing):
return None
raise

Expand Down Expand Up @@ -464,7 +464,7 @@ def _call_backend(
def _handle_backend(self, hook: str) -> Iterator[None]:
try:
yield
except pep517.wrappers.BackendUnavailable as exception:
except pyproject_hooks.BackendUnavailable as exception:
raise BuildBackendException( # noqa: B904 # use raise from
exception,
f"Backend '{self._backend}' is not available.",
Expand Down
4 changes: 2 additions & 2 deletions src/build/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import sys
import tempfile

import pep517
import pyproject_hooks

import build
import build.env
Expand Down Expand Up @@ -43,7 +43,7 @@ def project_wheel_metadata(
"""
builder = build.ProjectBuilder(
os.fspath(srcdir),
runner=pep517.quiet_subprocess_runner,
runner=pyproject_hooks.quiet_subprocess_runner,
)

if not isolated:
Expand Down
4 changes: 2 additions & 2 deletions tests/constraints.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
importlib-metadata==0.22
packaging==19.0
pep517==0.9.1
pyproject_hooks==1.0
setuptools==42.0.0; python_version < "3.10"
setuptools==56.0.0; python_version >= "3.10"
toml==0.10.0
tomli==1.0.0
tomli==1.1.0
virtualenv==20.0.35
wheel==0.36.0
54 changes: 27 additions & 27 deletions tests/test_projectbuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import sys
import textwrap

import pep517.wrappers
import pyproject_hooks
import pytest

import build
Expand Down Expand Up @@ -185,25 +185,25 @@ def test_bad_project(package_test_no_project):


def test_init(mocker, package_test_flit, package_legacy, test_no_permission, package_test_bad_syntax):
mocker.patch('pep517.wrappers.Pep517HookCaller')
mocker.patch('pyproject_hooks.BuildBackendHookCaller')

# correct flit pyproject.toml
builder = build.ProjectBuilder(package_test_flit)
pep517.wrappers.Pep517HookCaller.assert_called_with(
pyproject_hooks.BuildBackendHookCaller.assert_called_with(
package_test_flit, 'flit_core.buildapi', backend_path=None, python_executable=sys.executable, runner=builder._runner
)
pep517.wrappers.Pep517HookCaller.reset_mock()
pyproject_hooks.BuildBackendHookCaller.reset_mock()

# custom python
builder = build.ProjectBuilder(package_test_flit, python_executable='some-python')
pep517.wrappers.Pep517HookCaller.assert_called_with(
pyproject_hooks.BuildBackendHookCaller.assert_called_with(
package_test_flit, 'flit_core.buildapi', backend_path=None, python_executable='some-python', runner=builder._runner
)
pep517.wrappers.Pep517HookCaller.reset_mock()
pyproject_hooks.BuildBackendHookCaller.reset_mock()

# FileNotFoundError
builder = build.ProjectBuilder(package_legacy)
pep517.wrappers.Pep517HookCaller.assert_called_with(
pyproject_hooks.BuildBackendHookCaller.assert_called_with(
package_legacy,
'setuptools.build_meta:__legacy__',
backend_path=None,
Expand Down Expand Up @@ -263,15 +263,15 @@ def test_build_missing_backend(packages_path, distribution, tmpdir):


def test_check_dependencies(mocker, package_test_flit):
mocker.patch('pep517.wrappers.Pep517HookCaller.get_requires_for_build_sdist')
mocker.patch('pep517.wrappers.Pep517HookCaller.get_requires_for_build_wheel')
mocker.patch('pyproject_hooks.BuildBackendHookCaller.get_requires_for_build_sdist')
mocker.patch('pyproject_hooks.BuildBackendHookCaller.get_requires_for_build_wheel')

builder = build.ProjectBuilder(package_test_flit)

side_effects = [
[],
['something'],
pep517.wrappers.BackendUnavailable,
pyproject_hooks.BackendUnavailable,
]

builder._hook.get_requires_for_build_sdist.side_effect = copy.copy(side_effects)
Expand All @@ -293,7 +293,7 @@ def test_check_dependencies(mocker, package_test_flit):


def test_build(mocker, package_test_flit, tmp_dir):
mocker.patch('pep517.wrappers.Pep517HookCaller', autospec=True)
mocker.patch('pyproject_hooks.BuildBackendHookCaller', autospec=True)

builder = build.ProjectBuilder(package_test_flit)

Expand All @@ -314,37 +314,37 @@ def test_build(mocker, package_test_flit, tmp_dir):


def test_default_backend(mocker, package_legacy):
mocker.patch('pep517.wrappers.Pep517HookCaller', autospec=True)
mocker.patch('pyproject_hooks.BuildBackendHookCaller', autospec=True)

builder = build.ProjectBuilder(package_legacy)

assert builder._build_system == DEFAULT_BACKEND


def test_missing_backend(mocker, package_test_no_backend):
mocker.patch('pep517.wrappers.Pep517HookCaller', autospec=True)
mocker.patch('pyproject_hooks.BuildBackendHookCaller', autospec=True)

builder = build.ProjectBuilder(package_test_no_backend)

assert builder._build_system == {'requires': [], 'build-backend': DEFAULT_BACKEND['build-backend']}


def test_missing_requires(mocker, package_test_no_requires):
mocker.patch('pep517.wrappers.Pep517HookCaller', autospec=True)
mocker.patch('pyproject_hooks.BuildBackendHookCaller', autospec=True)

with pytest.raises(build.BuildException):
build.ProjectBuilder(package_test_no_requires)


def test_build_system_typo(mocker, package_test_typo):
mocker.patch('pep517.wrappers.Pep517HookCaller', autospec=True)
mocker.patch('pyproject_hooks.BuildBackendHookCaller', autospec=True)

with pytest.warns(build.TypoWarning):
build.ProjectBuilder(package_test_typo)


def test_missing_outdir(mocker, tmp_dir, package_test_flit):
mocker.patch('pep517.wrappers.Pep517HookCaller', autospec=True)
mocker.patch('pyproject_hooks.BuildBackendHookCaller', autospec=True)

builder = build.ProjectBuilder(package_test_flit)
builder._hook.build_sdist.return_value = 'dist.tar.gz'
Expand All @@ -356,7 +356,7 @@ def test_missing_outdir(mocker, tmp_dir, package_test_flit):


def test_relative_outdir(mocker, tmp_dir, package_test_flit):
mocker.patch('pep517.wrappers.Pep517HookCaller', autospec=True)
mocker.patch('pyproject_hooks.BuildBackendHookCaller', autospec=True)

builder = build.ProjectBuilder(package_test_flit)
builder._hook.build_sdist.return_value = 'dist.tar.gz'
Expand All @@ -367,7 +367,7 @@ def test_relative_outdir(mocker, tmp_dir, package_test_flit):


def test_build_not_dir_outdir(mocker, tmp_dir, package_test_flit):
mocker.patch('pep517.wrappers.Pep517HookCaller', autospec=True)
mocker.patch('pyproject_hooks.BuildBackendHookCaller', autospec=True)

builder = build.ProjectBuilder(package_test_flit)
builder._hook.build_sdist.return_value = 'dist.tar.gz'
Expand Down Expand Up @@ -437,7 +437,7 @@ def test_build_with_dep_on_console_script(tmp_path, demo_pkg_inline, capfd, mock


def test_prepare(mocker, tmp_dir, package_test_flit):
mocker.patch('pep517.wrappers.Pep517HookCaller', autospec=True)
mocker.patch('pyproject_hooks.BuildBackendHookCaller', autospec=True)

builder = build.ProjectBuilder(package_test_flit)
builder._hook.prepare_metadata_for_build_wheel.return_value = 'dist-1.0.dist-info'
Expand All @@ -447,17 +447,17 @@ def test_prepare(mocker, tmp_dir, package_test_flit):


def test_prepare_no_hook(mocker, tmp_dir, package_test_flit):
mocker.patch('pep517.wrappers.Pep517HookCaller', autospec=True)
mocker.patch('pyproject_hooks.BuildBackendHookCaller', autospec=True)

builder = build.ProjectBuilder(package_test_flit)
failure = pep517.wrappers.HookMissing('prepare_metadata_for_build_wheel')
failure = pyproject_hooks.HookMissing('prepare_metadata_for_build_wheel')
builder._hook.prepare_metadata_for_build_wheel.side_effect = failure

assert builder.prepare('wheel', tmp_dir) is None


def test_prepare_error(mocker, tmp_dir, package_test_flit):
mocker.patch('pep517.wrappers.Pep517HookCaller', autospec=True)
mocker.patch('pyproject_hooks.BuildBackendHookCaller', autospec=True)

builder = build.ProjectBuilder(package_test_flit)
builder._hook.prepare_metadata_for_build_wheel.side_effect = Exception
Expand All @@ -467,7 +467,7 @@ def test_prepare_error(mocker, tmp_dir, package_test_flit):


def test_prepare_not_dir_outdir(mocker, tmp_dir, package_test_flit):
mocker.patch('pep517.wrappers.Pep517HookCaller', autospec=True)
mocker.patch('pyproject_hooks.BuildBackendHookCaller', autospec=True)

builder = build.ProjectBuilder(package_test_flit)

Expand All @@ -479,7 +479,7 @@ def test_prepare_not_dir_outdir(mocker, tmp_dir, package_test_flit):


def test_no_outdir_single(mocker, tmp_dir, package_test_flit):
mocker.patch('pep517.wrappers.Pep517HookCaller.prepare_metadata_for_build_wheel', return_value='')
mocker.patch('pyproject_hooks.BuildBackendHookCaller.prepare_metadata_for_build_wheel', return_value='')

builder = build.ProjectBuilder(package_test_flit)

Expand All @@ -490,7 +490,7 @@ def test_no_outdir_single(mocker, tmp_dir, package_test_flit):


def test_no_outdir_multiple(mocker, tmp_dir, package_test_flit):
mocker.patch('pep517.wrappers.Pep517HookCaller.prepare_metadata_for_build_wheel', return_value='')
mocker.patch('pyproject_hooks.BuildBackendHookCaller.prepare_metadata_for_build_wheel', return_value='')

builder = build.ProjectBuilder(package_test_flit)

Expand Down Expand Up @@ -564,7 +564,7 @@ def mock_tomli_not_available(mocker):

@pytest.mark.skipif(sys.version_info >= (3, 11), reason='No need to test old toml support on 3.11+')
def test_toml_instead_of_tomli(mocker, mock_tomli_not_available, tmp_dir, package_test_flit):
mocker.patch('pep517.wrappers.Pep517HookCaller', autospec=True)
mocker.patch('pyproject_hooks.BuildBackendHookCaller', autospec=True)

builder = build.ProjectBuilder(package_test_flit)
builder._hook.build_sdist.return_value = 'dist.tar.gz'
Expand All @@ -575,7 +575,7 @@ def test_toml_instead_of_tomli(mocker, mock_tomli_not_available, tmp_dir, packag


def test_log(mocker, caplog, package_test_flit):
mocker.patch('pep517.wrappers.Pep517HookCaller', autospec=True)
mocker.patch('pyproject_hooks.BuildBackendHookCaller', autospec=True)
mocker.patch('build.ProjectBuilder._call_backend', return_value='some_path')
caplog.set_level(logging.DEBUG)

Expand Down

0 comments on commit edcd0fd

Please sign in to comment.