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

Align builder with pip when backend is missing #177

Merged
merged 1 commit into from Nov 1, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
37 changes: 21 additions & 16 deletions src/build/__init__.py
Expand Up @@ -133,26 +133,31 @@ def __init__(self, srcdir, config_settings=None, python_executable=sys.executabl

try:
with open(spec_file) as f:
self._spec = toml.load(f)
spec = toml.load(f)
except FileNotFoundError:
self._spec = {}
spec = {}
except PermissionError as e:
raise BuildException("{}: '{}' ".format(e.strerror, e.filename))
except toml.decoder.TomlDecodeError as e:
raise BuildException('Failed to parse pyproject.toml: {} '.format(e))

_find_typo(self._spec, 'build-system')
self._build_system = self._spec.get('build-system', _DEFAULT_BACKEND)

if 'build-backend' not in self._build_system:
_find_typo(self._build_system, 'build-backend')
_find_typo(self._build_system, 'requires')
self._build_system['build-backend'] = _DEFAULT_BACKEND['build-backend']
self._build_system['requires'] = self._build_system.get('requires', []) + _DEFAULT_BACKEND['requires']

if 'requires' not in self._build_system:
raise BuildException("Missing 'build-system.requires' in pyproject.toml")

raise BuildException('Failed to parse {}: {} '.format(spec_file, e))

build_system = spec.get('build-system')
# if pyproject.toml is missing (per PEP 517) or [build-system] is missing (pep PEP 518),
# use default values.
if build_system is None:
_find_typo(spec, 'build-system')
build_system = _DEFAULT_BACKEND
# if [build-system] is present, it must have a ``requires`` field (per PEP 518).
elif 'requires' not in build_system:
_find_typo(build_system, 'requires')
raise BuildException("Missing 'build-system.requires' in {}".format(spec_file))
# if ``build-backend`` is missing, inject the legacy setuptools backend
# but leave ``requires`` alone to emulate pip.
elif 'build-backend' not in build_system:
_find_typo(build_system, 'build-backend')
build_system['build-backend'] = _DEFAULT_BACKEND['build-backend']

self._build_system = build_system
self._backend = self._build_system['build-backend']

self._hook = pep517.wrappers.Pep517HookCaller(
Expand Down
2 changes: 1 addition & 1 deletion tests/test_projectbuilder.py
Expand Up @@ -238,7 +238,7 @@ def test_missing_backend(mocker, test_no_backend_path):

builder = build.ProjectBuilder(test_no_backend_path)

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


def test_missing_requires(mocker, test_no_requires_path):
Expand Down