From 3492e4ad16507cfb23f70b9ad65bfac06bffd7a9 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Sun, 14 Jun 2020 22:31:03 +0100 Subject: [PATCH 01/10] Pull out high-level interfaces as an extended example --- README.rst | 48 ++++---------- buildtool_demo/__init__.py | 0 {pep517 => buildtool_demo}/build.py | 46 +------------- {pep517 => buildtool_demo}/check.py | 0 {pep517 => buildtool_demo}/colorlog.py | 0 {pep517 => buildtool_demo}/dirtools.py | 0 {pep517 => buildtool_demo}/envbuild.py | 37 ++++++++++- {pep517 => buildtool_demo}/meta.py | 4 +- buildtool_demo/tests/__init__.py | 0 .../tests/samples/buildsys_pkgs/buildsys.py | 62 +++++++++++++++++++ .../samples/buildsys_pkgs/buildsys_minimal.py | 34 ++++++++++ .../samples/pkg1/pkg1-0.5.dist-info/LICENSE | 21 +++++++ .../samples/pkg1/pkg1-0.5.dist-info/METADATA | 9 +++ .../samples/pkg1/pkg1-0.5.dist-info/RECORD | 5 ++ .../samples/pkg1/pkg1-0.5.dist-info/WHEEL | 5 ++ buildtool_demo/tests/samples/pkg1/pkg1.py | 3 + .../tests/samples/pkg1/pyproject.toml | 3 + .../tests}/test_envbuild.py | 2 +- {tests => buildtool_demo/tests}/test_meta.py | 2 +- pep517/__init__.py | 2 + pep517/pyproject.py | 52 ++++++++++++++++ pep517/wrappers.py | 47 ++++---------- pyproject.toml | 2 - tests/test_build.py | 27 -------- tests/test_hook_fallbacks.py | 2 +- tests/test_inplace_hooks.py | 2 +- tests/test_pyproject.py | 27 ++++++++ 27 files changed, 289 insertions(+), 153 deletions(-) create mode 100644 buildtool_demo/__init__.py rename {pep517 => buildtool_demo}/build.py (62%) rename {pep517 => buildtool_demo}/check.py (100%) rename {pep517 => buildtool_demo}/colorlog.py (100%) rename {pep517 => buildtool_demo}/dirtools.py (100%) rename {pep517 => buildtool_demo}/envbuild.py (87%) rename {pep517 => buildtool_demo}/meta.py (94%) create mode 100644 buildtool_demo/tests/__init__.py create mode 100644 buildtool_demo/tests/samples/buildsys_pkgs/buildsys.py create mode 100644 buildtool_demo/tests/samples/buildsys_pkgs/buildsys_minimal.py create mode 100644 buildtool_demo/tests/samples/pkg1/pkg1-0.5.dist-info/LICENSE create mode 100644 buildtool_demo/tests/samples/pkg1/pkg1-0.5.dist-info/METADATA create mode 100644 buildtool_demo/tests/samples/pkg1/pkg1-0.5.dist-info/RECORD create mode 100644 buildtool_demo/tests/samples/pkg1/pkg1-0.5.dist-info/WHEEL create mode 100644 buildtool_demo/tests/samples/pkg1/pkg1.py create mode 100644 buildtool_demo/tests/samples/pkg1/pyproject.toml rename {tests => buildtool_demo/tests}/test_envbuild.py (95%) rename {tests => buildtool_demo/tests}/test_meta.py (97%) create mode 100644 pep517/pyproject.py delete mode 100644 tests/test_build.py create mode 100644 tests/test_pyproject.py diff --git a/README.rst b/README.rst index b5ebb3b..8582c29 100644 --- a/README.rst +++ b/README.rst @@ -8,38 +8,21 @@ provides: the current process. - Fallbacks for the optional hooks, so that frontends can call the hooks without checking which are defined. -- Higher-level functions which install the build dependencies into a - temporary environment and build a wheel/sdist using them. +- Functions to load the build system table from ``pyproject.toml``, with + optional fallback to setuptools. Run the tests with ``pytest`` or `tox `_. -High level usage, with build requirements handled: +Usage: .. code-block:: python import os - from pep517.envbuild import build_wheel, build_sdist + from pep517 import Pep517HookCaller + from pep517.pyproject import load_system src = 'path/to/source' # Folder containing 'pyproject.toml' - destination = 'also/a/folder' - whl_filename = build_wheel(src, destination) - assert os.path.isfile(os.path.join(destination, whl_filename)) - - targz_filename = build_sdist(src, destination) - assert os.path.isfile(os.path.join(destination, targz_filename)) - -Lower level usage—you are responsible for ensuring build requirements are -available: - -.. code-block:: python - - import os - import toml - from pep517.wrappers import Pep517HookCaller - - src = 'path/to/source' # Folder containing 'pyproject.toml' - with open(os.path.join(src, 'pyproject.toml')) as f: - build_sys = toml.load(f)['build-system'] + build_sys = load_system(src) print(build_sys['requires']) # List of static requirements @@ -57,18 +40,9 @@ available: whl_filename = hooks.build_wheel(destination, config_options) assert os.path.isfile(os.path.join(destination, whl_filename)) -To test the build backend for a project, run in a system shell: - -.. code-block:: shell - - python3 -m pep517.check path/to/source # source dir containing pyproject.toml - -To build a backend into source and/or binary distributions, run in a shell: - -.. code-block:: shell - - python -m pep517.build path/to/source # source dir containing pyproject.toml +The caller is responsible for installing build dependencies. +The static requirements should be installed before trying to call any hooks. -This 'build' module should be considered experimental while the PyPA `decides -on the best place for this functionality -`_. +The ``buildtool_demo`` package in this repository gives a more complete +example of how to use the hooks. This is an example, and doesn't get installed +with the ``pep517`` package. diff --git a/buildtool_demo/__init__.py b/buildtool_demo/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pep517/build.py b/buildtool_demo/build.py similarity index 62% rename from pep517/build.py rename to buildtool_demo/build.py index 7618c78..f24a332 100644 --- a/pep517/build.py +++ b/buildtool_demo/build.py @@ -3,58 +3,16 @@ import argparse import logging import os -import toml import shutil from .envbuild import BuildEnvironment -from .wrappers import Pep517HookCaller +from pep517 import Pep517HookCaller +from pep517.pyproject import load_system, validate_system from .dirtools import tempdir, mkdir_p -from .compat import FileNotFoundError log = logging.getLogger(__name__) -def validate_system(system): - """ - Ensure build system has the requisite fields. - """ - required = {'requires', 'build-backend'} - if not (required <= set(system)): - message = "Missing required fields: {missing}".format( - missing=required-set(system), - ) - raise ValueError(message) - - -def load_system(source_dir): - """ - Load the build system from a source dir (pyproject.toml). - """ - pyproject = os.path.join(source_dir, 'pyproject.toml') - with open(pyproject) as f: - pyproject_data = toml.load(f) - return pyproject_data['build-system'] - - -def compat_system(source_dir): - """ - Given a source dir, attempt to get a build system backend - and requirements from pyproject.toml. Fallback to - setuptools but only if the file was not found or a build - system was not indicated. - """ - try: - system = load_system(source_dir) - except (FileNotFoundError, KeyError): - system = {} - system.setdefault( - 'build-backend', - 'setuptools.build_meta:__legacy__', - ) - system.setdefault('requires', ['setuptools', 'wheel']) - return system - - def _do_build(hooks, env, dist, dest): get_requires_name = 'get_requires_for_build_{dist}'.format(**locals()) get_requires = getattr(hooks, get_requires_name) diff --git a/pep517/check.py b/buildtool_demo/check.py similarity index 100% rename from pep517/check.py rename to buildtool_demo/check.py diff --git a/pep517/colorlog.py b/buildtool_demo/colorlog.py similarity index 100% rename from pep517/colorlog.py rename to buildtool_demo/colorlog.py diff --git a/pep517/dirtools.py b/buildtool_demo/dirtools.py similarity index 100% rename from pep517/dirtools.py rename to buildtool_demo/dirtools.py diff --git a/pep517/envbuild.py b/buildtool_demo/envbuild.py similarity index 87% rename from pep517/envbuild.py rename to buildtool_demo/envbuild.py index cacd2b1..4dd1536 100644 --- a/pep517/envbuild.py +++ b/buildtool_demo/envbuild.py @@ -9,8 +9,9 @@ import sys from sysconfig import get_paths from tempfile import mkdtemp +import threading -from .wrappers import Pep517HookCaller, LoggerWrapper +from pep517 import Pep517HookCaller log = logging.getLogger(__name__) @@ -26,6 +27,40 @@ def _load_pyproject(source_dir): ) +class LoggerWrapper(threading.Thread): + """ + Read messages from a pipe and redirect them + to a logger (see python's logging module). + """ + + def __init__(self, logger, level): + threading.Thread.__init__(self) + self.daemon = True + + self.logger = logger + self.level = level + + # create the pipe and reader + self.fd_read, self.fd_write = os.pipe() + self.reader = os.fdopen(self.fd_read) + + self.start() + + def fileno(self): + return self.fd_write + + @staticmethod + def remove_newline(msg): + return msg[:-1] if msg.endswith(os.linesep) else msg + + def run(self): + for line in self.reader: + self._write(self.remove_newline(line)) + + def _write(self, message): + self.logger.log(self.level, message) + + class BuildEnvironment(object): """Context manager to install build deps in a simple temporary environment diff --git a/pep517/meta.py b/buildtool_demo/meta.py similarity index 94% rename from pep517/meta.py rename to buildtool_demo/meta.py index d525de5..1704c42 100644 --- a/pep517/meta.py +++ b/buildtool_demo/meta.py @@ -17,9 +17,9 @@ from zipp import Path from .envbuild import BuildEnvironment -from .wrappers import Pep517HookCaller, quiet_subprocess_runner +from pep517 import Pep517HookCaller, quiet_subprocess_runner +from pep517.pyproject import validate_system, load_system, compat_system from .dirtools import tempdir, mkdir_p, dir_to_zipfile -from .build import validate_system, load_system, compat_system log = logging.getLogger(__name__) diff --git a/buildtool_demo/tests/__init__.py b/buildtool_demo/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/buildtool_demo/tests/samples/buildsys_pkgs/buildsys.py b/buildtool_demo/tests/samples/buildsys_pkgs/buildsys.py new file mode 100644 index 0000000..e1750c1 --- /dev/null +++ b/buildtool_demo/tests/samples/buildsys_pkgs/buildsys.py @@ -0,0 +1,62 @@ +"""This is a very stupid backend for testing purposes. + +Don't use this for any real code. +""" + +from glob import glob +from os.path import join as pjoin +import shutil +import tarfile +from zipfile import ZipFile + + +def get_requires_for_build_wheel(config_settings): + return ['wheelwright'] + + +def prepare_metadata_for_build_wheel(metadata_directory, config_settings): + for distinfo in glob('*.dist-info'): + shutil.copytree(distinfo, pjoin(metadata_directory, distinfo)) + + +def prepare_build_wheel_files(build_directory, config_settings): + shutil.copy('pyproject.toml', build_directory) + for pyfile in glob('*.py'): + shutil.copy(pyfile, build_directory) + for distinfo in glob('*.dist-info'): + shutil.copytree(distinfo, pjoin(build_directory, distinfo)) + + +def build_wheel(wheel_directory, config_settings, metadata_directory=None): + whl_file = 'pkg1-0.5-py2.py3-none-any.whl' + with ZipFile(pjoin(wheel_directory, whl_file), 'w') as zf: + for pyfile in glob('*.py'): + zf.write(pyfile) + for metadata in glob('*.dist-info/*'): + zf.write(metadata) + return whl_file + + +def get_requires_for_build_sdist(config_settings): + return ['frog'] + + +class UnsupportedOperation(Exception): + pass + + +def build_sdist(sdist_directory, config_settings): + if config_settings.get('test_unsupported', False): + raise UnsupportedOperation + + target = 'pkg1-0.5.tar.gz' + with tarfile.open(pjoin(sdist_directory, target), 'w:gz', + format=tarfile.PAX_FORMAT) as tf: + def _add(relpath): + tf.add(relpath, arcname='pkg1-0.5/' + relpath) + + _add('pyproject.toml') + for pyfile in glob('*.py'): + _add(pyfile) + + return target diff --git a/buildtool_demo/tests/samples/buildsys_pkgs/buildsys_minimal.py b/buildtool_demo/tests/samples/buildsys_pkgs/buildsys_minimal.py new file mode 100644 index 0000000..6a286b1 --- /dev/null +++ b/buildtool_demo/tests/samples/buildsys_pkgs/buildsys_minimal.py @@ -0,0 +1,34 @@ +"""Test backend defining only the mandatory hooks. + +Don't use this for any real code. +""" +from glob import glob +from os.path import join as pjoin +import tarfile +from zipfile import ZipFile + + +def build_wheel(wheel_directory, config_settings, metadata_directory=None): + whl_file = 'pkg2-0.5-py2.py3-none-any.whl' + with ZipFile(pjoin(wheel_directory, whl_file), 'w') as zf: + for pyfile in glob('*.py'): + zf.write(pyfile) + for metadata in glob('*.dist-info/*'): + zf.write(metadata) + return whl_file + + +def build_sdist(sdist_directory, config_settings): + target = 'pkg2-0.5.tar.gz' + with tarfile.open(pjoin(sdist_directory, target), 'w:gz', + format=tarfile.PAX_FORMAT) as tf: + def _add(relpath): + tf.add(relpath, arcname='pkg2-0.5/' + relpath) + + _add('pyproject.toml') + for pyfile in glob('*.py'): + _add(pyfile) + for distinfo in glob('*.dist-info'): + _add(distinfo) + + return target diff --git a/buildtool_demo/tests/samples/pkg1/pkg1-0.5.dist-info/LICENSE b/buildtool_demo/tests/samples/pkg1/pkg1-0.5.dist-info/LICENSE new file mode 100644 index 0000000..b0ae9db --- /dev/null +++ b/buildtool_demo/tests/samples/pkg1/pkg1-0.5.dist-info/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2017 Thomas Kluyver + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/buildtool_demo/tests/samples/pkg1/pkg1-0.5.dist-info/METADATA b/buildtool_demo/tests/samples/pkg1/pkg1-0.5.dist-info/METADATA new file mode 100644 index 0000000..7bf2758 --- /dev/null +++ b/buildtool_demo/tests/samples/pkg1/pkg1-0.5.dist-info/METADATA @@ -0,0 +1,9 @@ +Metadata-Version: 1.2 +Name: pkg1 +Version: 0.5 +Summary: Sample package for tests +Home-page: https://github.com/takluyver/pep517 +License: UNKNOWN +Author: Thomas Kluyver +Author-email: thomas@kluyver.me.uk +Classifier: License :: OSI Approved :: MIT License diff --git a/buildtool_demo/tests/samples/pkg1/pkg1-0.5.dist-info/RECORD b/buildtool_demo/tests/samples/pkg1/pkg1-0.5.dist-info/RECORD new file mode 100644 index 0000000..74e8cbf --- /dev/null +++ b/buildtool_demo/tests/samples/pkg1/pkg1-0.5.dist-info/RECORD @@ -0,0 +1,5 @@ +pkg1.py,sha256=ZawKBtrxtdGEheOCWvwzGZsO8Q1OSzEzecGNsRz-ekc,52 +pkg1-0.5.dist-info/LICENSE,sha256=GyKwSbUmfW38I6Z79KhNjsBLn9-xpR02DkK0NCyLQVQ,1081 +pkg1-0.5.dist-info/WHEEL,sha256=jxKvNaDKHDacpaLi69-vnLKkBSynwBzmMS82pipt1T0,100 +pkg1-0.5.dist-info/METADATA,sha256=GDliGDwDPM11hoO79KhjyJuFgcm-TOj30gewsPNjkHw,251 +pkg1-0.5.dist-info/RECORD,, diff --git a/buildtool_demo/tests/samples/pkg1/pkg1-0.5.dist-info/WHEEL b/buildtool_demo/tests/samples/pkg1/pkg1-0.5.dist-info/WHEEL new file mode 100644 index 0000000..1612133 --- /dev/null +++ b/buildtool_demo/tests/samples/pkg1/pkg1-0.5.dist-info/WHEEL @@ -0,0 +1,5 @@ +Wheel-Version: 1.0 +Generator: buildsys 0.1 +Root-Is-Purelib: true +Tag: py2-none-any +Tag: py3-none-any diff --git a/buildtool_demo/tests/samples/pkg1/pkg1.py b/buildtool_demo/tests/samples/pkg1/pkg1.py new file mode 100644 index 0000000..b76d0a9 --- /dev/null +++ b/buildtool_demo/tests/samples/pkg1/pkg1.py @@ -0,0 +1,3 @@ +"""Sample package for tests""" + +__version__ = '0.5' diff --git a/buildtool_demo/tests/samples/pkg1/pyproject.toml b/buildtool_demo/tests/samples/pkg1/pyproject.toml new file mode 100644 index 0000000..95ff87f --- /dev/null +++ b/buildtool_demo/tests/samples/pkg1/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["eg_buildsys"] +build-backend = "buildsys" diff --git a/tests/test_envbuild.py b/buildtool_demo/tests/test_envbuild.py similarity index 95% rename from tests/test_envbuild.py rename to buildtool_demo/tests/test_envbuild.py index 79c094b..12fbb82 100644 --- a/tests/test_envbuild.py +++ b/buildtool_demo/tests/test_envbuild.py @@ -8,7 +8,7 @@ from mock import patch, call # Python 2 fallback import zipfile -from pep517.envbuild import build_sdist, build_wheel, BuildEnvironment +from ..envbuild import build_sdist, build_wheel, BuildEnvironment SAMPLES_DIR = pjoin(dirname(abspath(__file__)), 'samples') BUILDSYS_PKGS = pjoin(SAMPLES_DIR, 'buildsys_pkgs') diff --git a/tests/test_meta.py b/buildtool_demo/tests/test_meta.py similarity index 97% rename from tests/test_meta.py rename to buildtool_demo/tests/test_meta.py index bd6a2e7..2b024e7 100644 --- a/tests/test_meta.py +++ b/buildtool_demo/tests/test_meta.py @@ -4,7 +4,7 @@ import pytest -from pep517 import meta +from .. import meta pep517_needs_python_3 = pytest.mark.xfail( diff --git a/pep517/__init__.py b/pep517/__init__.py index 7355b68..677afd6 100644 --- a/pep517/__init__.py +++ b/pep517/__init__.py @@ -2,3 +2,5 @@ """ __version__ = '0.8.2' + +from .wrappers import * # noqa: F401,F403 diff --git a/pep517/pyproject.py b/pep517/pyproject.py new file mode 100644 index 0000000..9015a5e --- /dev/null +++ b/pep517/pyproject.py @@ -0,0 +1,52 @@ +import os + +import toml + +from .compat import FileNotFoundError + +__all__ = [ + 'validate_system', + 'load_system', + 'compat_system', +] + + +def validate_system(system): + """ + Ensure build system has the requisite fields. + """ + required = {'requires', 'build-backend'} + if not (required <= set(system)): + message = "Missing required fields: {missing}".format( + missing=required-set(system), + ) + raise ValueError(message) + + +def load_system(source_dir): + """ + Load the build system from a source dir (pyproject.toml). + """ + pyproject = os.path.join(source_dir, 'pyproject.toml') + with open(pyproject) as f: + pyproject_data = toml.load(f) + return pyproject_data['build-system'] + + +def compat_system(source_dir): + """ + Given a source dir, attempt to get a build system backend + and requirements from pyproject.toml. Fallback to + setuptools but only if the file was not found or a build + system was not indicated. + """ + try: + system = load_system(source_dir) + except (FileNotFoundError, KeyError): + system = {} + system.setdefault( + 'build-backend', + 'setuptools.build_meta:__legacy__', + ) + system.setdefault('requires', ['setuptools', 'wheel']) + return system diff --git a/pep517/wrappers.py b/pep517/wrappers.py index 00a3d1a..85f574b 100644 --- a/pep517/wrappers.py +++ b/pep517/wrappers.py @@ -1,4 +1,3 @@ -import threading from contextlib import contextmanager import os from os.path import dirname, abspath, join as pjoin @@ -9,7 +8,6 @@ from . import compat - try: import importlib.resources as resources @@ -21,6 +19,17 @@ def _in_proc_script_path(): yield pjoin(dirname(abspath(__file__)), '_in_process.py') +__all__ = [ + 'Pep517HookCaller', + 'BackendUnavailable', + 'BackendInvalid', + 'HookMissing', + 'UnsupportedOperation', + 'default_subprocess_runner', + 'quiet_subprocess_runner', +] + + @contextmanager def tempdir(): td = mkdtemp() @@ -272,37 +281,3 @@ def _call_hook(self, hook_name, kwargs): if data.get('hook_missing'): raise HookMissing(hook_name) return data['return_val'] - - -class LoggerWrapper(threading.Thread): - """ - Read messages from a pipe and redirect them - to a logger (see python's logging module). - """ - - def __init__(self, logger, level): - threading.Thread.__init__(self) - self.daemon = True - - self.logger = logger - self.level = level - - # create the pipe and reader - self.fd_read, self.fd_write = os.pipe() - self.reader = os.fdopen(self.fd_read) - - self.start() - - def fileno(self): - return self.fd_write - - @staticmethod - def remove_newline(msg): - return msg[:-1] if msg.endswith(os.linesep) else msg - - def run(self): - for line in self.reader: - self._write(self.remove_newline(line)) - - def _write(self, message): - self.logger.log(self.level, message) diff --git a/pyproject.toml b/pyproject.toml index 65d764c..ce3e4d7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,8 +10,6 @@ home-page = "https://github.com/pypa/pep517" description-file = "README.rst" requires = [ "toml", - "importlib_metadata;python_version<'3.8'", - "zipp;python_version<'3.8'", ] classifiers = [ "License :: OSI Approved :: MIT License", diff --git a/tests/test_build.py b/tests/test_build.py deleted file mode 100644 index 2a7c2bc..0000000 --- a/tests/test_build.py +++ /dev/null @@ -1,27 +0,0 @@ -import pytest - -from pep517 import build - - -def system(*args): - return dict.fromkeys(args) - - -class TestValidateSystem: - def test_missing(self): - with pytest.raises(ValueError): - build.validate_system(system()) - with pytest.raises(ValueError): - build.validate_system(system('requires')) - with pytest.raises(ValueError): - build.validate_system(system('build-backend')) - with pytest.raises(ValueError): - build.validate_system(system('other')) - - def test_missing_and_extra(self): - with pytest.raises(ValueError): - build.validate_system(system('build-backend', 'other')) - - def test_satisfied(self): - build.validate_system(system('build-backend', 'requires')) - build.validate_system(system('build-backend', 'requires', 'other')) diff --git a/tests/test_hook_fallbacks.py b/tests/test_hook_fallbacks.py index c8d4f21..7410de6 100644 --- a/tests/test_hook_fallbacks.py +++ b/tests/test_hook_fallbacks.py @@ -4,7 +4,7 @@ from testpath import modified_env, assert_isfile from testpath.tempdir import TemporaryDirectory -from pep517.wrappers import HookMissing, Pep517HookCaller +from pep517 import HookMissing, Pep517HookCaller SAMPLES_DIR = pjoin(dirname(abspath(__file__)), 'samples') BUILDSYS_PKGS = pjoin(SAMPLES_DIR, 'buildsys_pkgs') diff --git a/tests/test_inplace_hooks.py b/tests/test_inplace_hooks.py index 2e6e886..191711c 100644 --- a/tests/test_inplace_hooks.py +++ b/tests/test_inplace_hooks.py @@ -3,7 +3,7 @@ from testpath import modified_env import pytest -from pep517.wrappers import Pep517HookCaller, BackendInvalid +from pep517 import Pep517HookCaller, BackendInvalid SAMPLES_DIR = pjoin(dirname(abspath(__file__)), 'samples') BUILDSYS_PKGS = pjoin(SAMPLES_DIR, 'buildsys_pkgs') diff --git a/tests/test_pyproject.py b/tests/test_pyproject.py new file mode 100644 index 0000000..aaca65d --- /dev/null +++ b/tests/test_pyproject.py @@ -0,0 +1,27 @@ +import pytest + +from pep517.pyproject import validate_system + + +def system(*args): + return dict.fromkeys(args) + + +class TestValidateSystem: + def test_missing(self): + with pytest.raises(ValueError): + validate_system(system()) + with pytest.raises(ValueError): + validate_system(system('requires')) + with pytest.raises(ValueError): + validate_system(system('build-backend')) + with pytest.raises(ValueError): + validate_system(system('other')) + + def test_missing_and_extra(self): + with pytest.raises(ValueError): + validate_system(system('build-backend', 'other')) + + def test_satisfied(self): + validate_system(system('build-backend', 'requires')) + validate_system(system('build-backend', 'requires', 'other')) From 92da3870397059264a68cbfd6bd746081aeb7276 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Mon, 13 Jul 2020 21:05:08 +0100 Subject: [PATCH 02/10] Move buildtool into examples folder --- {buildtool_demo => examples/buildtool}/__init__.py | 0 {buildtool_demo => examples/buildtool}/build.py | 0 {buildtool_demo => examples/buildtool}/check.py | 0 {buildtool_demo => examples/buildtool}/colorlog.py | 0 {buildtool_demo => examples/buildtool}/dirtools.py | 0 {buildtool_demo => examples/buildtool}/envbuild.py | 0 {buildtool_demo => examples/buildtool}/meta.py | 0 {buildtool_demo => examples/buildtool}/tests/__init__.py | 0 .../buildtool}/tests/samples/buildsys_pkgs/buildsys.py | 0 .../buildtool}/tests/samples/buildsys_pkgs/buildsys_minimal.py | 0 .../buildtool}/tests/samples/pkg1/pkg1-0.5.dist-info/LICENSE | 0 .../buildtool}/tests/samples/pkg1/pkg1-0.5.dist-info/METADATA | 0 .../buildtool}/tests/samples/pkg1/pkg1-0.5.dist-info/RECORD | 0 .../buildtool}/tests/samples/pkg1/pkg1-0.5.dist-info/WHEEL | 0 {buildtool_demo => examples/buildtool}/tests/samples/pkg1/pkg1.py | 0 .../buildtool}/tests/samples/pkg1/pyproject.toml | 0 {buildtool_demo => examples/buildtool}/tests/test_envbuild.py | 0 {buildtool_demo => examples/buildtool}/tests/test_meta.py | 0 18 files changed, 0 insertions(+), 0 deletions(-) rename {buildtool_demo => examples/buildtool}/__init__.py (100%) rename {buildtool_demo => examples/buildtool}/build.py (100%) rename {buildtool_demo => examples/buildtool}/check.py (100%) rename {buildtool_demo => examples/buildtool}/colorlog.py (100%) rename {buildtool_demo => examples/buildtool}/dirtools.py (100%) rename {buildtool_demo => examples/buildtool}/envbuild.py (100%) rename {buildtool_demo => examples/buildtool}/meta.py (100%) rename {buildtool_demo => examples/buildtool}/tests/__init__.py (100%) rename {buildtool_demo => examples/buildtool}/tests/samples/buildsys_pkgs/buildsys.py (100%) rename {buildtool_demo => examples/buildtool}/tests/samples/buildsys_pkgs/buildsys_minimal.py (100%) rename {buildtool_demo => examples/buildtool}/tests/samples/pkg1/pkg1-0.5.dist-info/LICENSE (100%) rename {buildtool_demo => examples/buildtool}/tests/samples/pkg1/pkg1-0.5.dist-info/METADATA (100%) rename {buildtool_demo => examples/buildtool}/tests/samples/pkg1/pkg1-0.5.dist-info/RECORD (100%) rename {buildtool_demo => examples/buildtool}/tests/samples/pkg1/pkg1-0.5.dist-info/WHEEL (100%) rename {buildtool_demo => examples/buildtool}/tests/samples/pkg1/pkg1.py (100%) rename {buildtool_demo => examples/buildtool}/tests/samples/pkg1/pyproject.toml (100%) rename {buildtool_demo => examples/buildtool}/tests/test_envbuild.py (100%) rename {buildtool_demo => examples/buildtool}/tests/test_meta.py (100%) diff --git a/buildtool_demo/__init__.py b/examples/buildtool/__init__.py similarity index 100% rename from buildtool_demo/__init__.py rename to examples/buildtool/__init__.py diff --git a/buildtool_demo/build.py b/examples/buildtool/build.py similarity index 100% rename from buildtool_demo/build.py rename to examples/buildtool/build.py diff --git a/buildtool_demo/check.py b/examples/buildtool/check.py similarity index 100% rename from buildtool_demo/check.py rename to examples/buildtool/check.py diff --git a/buildtool_demo/colorlog.py b/examples/buildtool/colorlog.py similarity index 100% rename from buildtool_demo/colorlog.py rename to examples/buildtool/colorlog.py diff --git a/buildtool_demo/dirtools.py b/examples/buildtool/dirtools.py similarity index 100% rename from buildtool_demo/dirtools.py rename to examples/buildtool/dirtools.py diff --git a/buildtool_demo/envbuild.py b/examples/buildtool/envbuild.py similarity index 100% rename from buildtool_demo/envbuild.py rename to examples/buildtool/envbuild.py diff --git a/buildtool_demo/meta.py b/examples/buildtool/meta.py similarity index 100% rename from buildtool_demo/meta.py rename to examples/buildtool/meta.py diff --git a/buildtool_demo/tests/__init__.py b/examples/buildtool/tests/__init__.py similarity index 100% rename from buildtool_demo/tests/__init__.py rename to examples/buildtool/tests/__init__.py diff --git a/buildtool_demo/tests/samples/buildsys_pkgs/buildsys.py b/examples/buildtool/tests/samples/buildsys_pkgs/buildsys.py similarity index 100% rename from buildtool_demo/tests/samples/buildsys_pkgs/buildsys.py rename to examples/buildtool/tests/samples/buildsys_pkgs/buildsys.py diff --git a/buildtool_demo/tests/samples/buildsys_pkgs/buildsys_minimal.py b/examples/buildtool/tests/samples/buildsys_pkgs/buildsys_minimal.py similarity index 100% rename from buildtool_demo/tests/samples/buildsys_pkgs/buildsys_minimal.py rename to examples/buildtool/tests/samples/buildsys_pkgs/buildsys_minimal.py diff --git a/buildtool_demo/tests/samples/pkg1/pkg1-0.5.dist-info/LICENSE b/examples/buildtool/tests/samples/pkg1/pkg1-0.5.dist-info/LICENSE similarity index 100% rename from buildtool_demo/tests/samples/pkg1/pkg1-0.5.dist-info/LICENSE rename to examples/buildtool/tests/samples/pkg1/pkg1-0.5.dist-info/LICENSE diff --git a/buildtool_demo/tests/samples/pkg1/pkg1-0.5.dist-info/METADATA b/examples/buildtool/tests/samples/pkg1/pkg1-0.5.dist-info/METADATA similarity index 100% rename from buildtool_demo/tests/samples/pkg1/pkg1-0.5.dist-info/METADATA rename to examples/buildtool/tests/samples/pkg1/pkg1-0.5.dist-info/METADATA diff --git a/buildtool_demo/tests/samples/pkg1/pkg1-0.5.dist-info/RECORD b/examples/buildtool/tests/samples/pkg1/pkg1-0.5.dist-info/RECORD similarity index 100% rename from buildtool_demo/tests/samples/pkg1/pkg1-0.5.dist-info/RECORD rename to examples/buildtool/tests/samples/pkg1/pkg1-0.5.dist-info/RECORD diff --git a/buildtool_demo/tests/samples/pkg1/pkg1-0.5.dist-info/WHEEL b/examples/buildtool/tests/samples/pkg1/pkg1-0.5.dist-info/WHEEL similarity index 100% rename from buildtool_demo/tests/samples/pkg1/pkg1-0.5.dist-info/WHEEL rename to examples/buildtool/tests/samples/pkg1/pkg1-0.5.dist-info/WHEEL diff --git a/buildtool_demo/tests/samples/pkg1/pkg1.py b/examples/buildtool/tests/samples/pkg1/pkg1.py similarity index 100% rename from buildtool_demo/tests/samples/pkg1/pkg1.py rename to examples/buildtool/tests/samples/pkg1/pkg1.py diff --git a/buildtool_demo/tests/samples/pkg1/pyproject.toml b/examples/buildtool/tests/samples/pkg1/pyproject.toml similarity index 100% rename from buildtool_demo/tests/samples/pkg1/pyproject.toml rename to examples/buildtool/tests/samples/pkg1/pyproject.toml diff --git a/buildtool_demo/tests/test_envbuild.py b/examples/buildtool/tests/test_envbuild.py similarity index 100% rename from buildtool_demo/tests/test_envbuild.py rename to examples/buildtool/tests/test_envbuild.py diff --git a/buildtool_demo/tests/test_meta.py b/examples/buildtool/tests/test_meta.py similarity index 100% rename from buildtool_demo/tests/test_meta.py rename to examples/buildtool/tests/test_meta.py From 6b8b31192c87f478736090fdec0709a0cbe49d45 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Mon, 13 Jul 2020 21:07:27 +0100 Subject: [PATCH 03/10] Fix import --- examples/buildtool/check.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/buildtool/check.py b/examples/buildtool/check.py index 9e0c068..14ff988 100644 --- a/examples/buildtool/check.py +++ b/examples/buildtool/check.py @@ -14,7 +14,7 @@ from .colorlog import enable_colourful_output from .envbuild import BuildEnvironment -from .wrappers import Pep517HookCaller +from pep517 import Pep517HookCaller log = logging.getLogger(__name__) From 87bb9d3f7a144099e71e3303e901ab0387ca192c Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Mon, 13 Jul 2020 21:13:21 +0100 Subject: [PATCH 04/10] Add README in examples folder --- examples/README.rst | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 examples/README.rst diff --git a/examples/README.rst b/examples/README.rst new file mode 100644 index 0000000..3b24a48 --- /dev/null +++ b/examples/README.rst @@ -0,0 +1,5 @@ +Examples of using the ``pep517`` library. + +* ``buildtool`` is about the simplest possible PEP 517 frontend, which can use + PEP 517 backends to build packages. It installs build dependencies into a + temporary but non-isolated environment using pip. From 7e2e1449b1fff7d55a4cb231015dc866eacb171a Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Mon, 13 Jul 2020 21:18:17 +0100 Subject: [PATCH 05/10] Tests need package installed now --- tox.ini | 1 - 1 file changed, 1 deletion(-) diff --git a/tox.ini b/tox.ini index 2502fcf..e264324 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,5 @@ [tox] envlist = py27, py34, py35, py36, py37, pypy, pypy3 -skipsdist = true [testenv] deps = -rdev-requirements.txt From 00072e8d79e9b444ebdeeba2b6f9957bb7167d2c Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Mon, 13 Jul 2020 21:18:36 +0100 Subject: [PATCH 06/10] Expand flit_core requirement to <4 --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index ce3e4d7..fe7f337 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["flit_core >=2,<3"] +requires = ["flit_core >=2,<4"] build-backend = "flit_core.buildapi" [tool.flit.metadata] From 021ed3555da863bcc822590598bde3287a16e41b Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Mon, 13 Jul 2020 21:20:15 +0100 Subject: [PATCH 07/10] Enable isolated_build for Tox to use PEP 517 --- tox.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/tox.ini b/tox.ini index e264324..4ffcb74 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,6 @@ [tox] envlist = py27, py34, py35, py36, py37, pypy, pypy3 +isolated_build = True [testenv] deps = -rdev-requirements.txt From 94c4a87987931704c7dea1fe638ec3d32da3f617 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Mon, 13 Jul 2020 21:25:03 +0100 Subject: [PATCH 08/10] Try upgrading virtualenv on Travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 712a531..3ce9c1e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,6 +31,7 @@ jobs: cache: pip install: +- pip install -U virtualenv - pip install tox tox-venv script: tox From 512ddb46d0826de13966316082d12cb179c238ad Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Mon, 13 Jul 2020 21:27:41 +0100 Subject: [PATCH 09/10] Or maybe upgrade pip --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3ce9c1e..44b6b73 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,7 +31,7 @@ jobs: cache: pip install: -- pip install -U virtualenv +- pip install -U pip - pip install tox tox-venv script: tox From e70e03e734442817cb7ee41fc8fbdec574a81721 Mon Sep 17 00:00:00 2001 From: Thomas Kluyver Date: Mon, 13 Jul 2020 21:30:57 +0100 Subject: [PATCH 10/10] Try using virtualenv for tox environments --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 44b6b73..b91c18a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -31,7 +31,7 @@ jobs: cache: pip install: -- pip install -U pip -- pip install tox tox-venv +- pip install -U virtualenv +- pip install tox script: tox