Skip to content

Commit ae41d4e

Browse files
authored
Merge pull request #96 from pypa/revert-83-separate-highlevel
Revert "Pull out high-level interfaces as an extended example"
2 parents 00be440 + c03a9a9 commit ae41d4e

30 files changed

+157
-299
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ jobs:
3131
cache: pip
3232

3333
install:
34-
- pip install -U virtualenv
35-
- pip install tox
34+
- pip install tox tox-venv
3635

3736
script: tox

README.rst

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,38 @@ provides:
88
the current process.
99
- Fallbacks for the optional hooks, so that frontends can call the hooks without
1010
checking which are defined.
11-
- Functions to load the build system table from ``pyproject.toml``, with
12-
optional fallback to setuptools.
11+
- Higher-level functions which install the build dependencies into a
12+
temporary environment and build a wheel/sdist using them.
1313

1414
Run the tests with ``pytest`` or `tox <https://pypi.org/project/tox>`_.
1515

16-
Usage:
16+
High level usage, with build requirements handled:
1717

1818
.. code-block:: python
1919
2020
import os
21-
from pep517 import Pep517HookCaller
22-
from pep517.pyproject import load_system
21+
from pep517.envbuild import build_wheel, build_sdist
2322
2423
src = 'path/to/source' # Folder containing 'pyproject.toml'
25-
build_sys = load_system(src)
24+
destination = 'also/a/folder'
25+
whl_filename = build_wheel(src, destination)
26+
assert os.path.isfile(os.path.join(destination, whl_filename))
27+
28+
targz_filename = build_sdist(src, destination)
29+
assert os.path.isfile(os.path.join(destination, targz_filename))
30+
31+
Lower level usage—you are responsible for ensuring build requirements are
32+
available:
33+
34+
.. code-block:: python
35+
36+
import os
37+
import toml
38+
from pep517.wrappers import Pep517HookCaller
39+
40+
src = 'path/to/source' # Folder containing 'pyproject.toml'
41+
with open(os.path.join(src, 'pyproject.toml')) as f:
42+
build_sys = toml.load(f)['build-system']
2643
2744
print(build_sys['requires']) # List of static requirements
2845
@@ -40,9 +57,18 @@ Usage:
4057
whl_filename = hooks.build_wheel(destination, config_options)
4158
assert os.path.isfile(os.path.join(destination, whl_filename))
4259
43-
The caller is responsible for installing build dependencies.
44-
The static requirements should be installed before trying to call any hooks.
60+
To test the build backend for a project, run in a system shell:
61+
62+
.. code-block:: shell
63+
64+
python3 -m pep517.check path/to/source # source dir containing pyproject.toml
65+
66+
To build a backend into source and/or binary distributions, run in a shell:
67+
68+
.. code-block:: shell
69+
70+
python -m pep517.build path/to/source # source dir containing pyproject.toml
4571
46-
The ``buildtool_demo`` package in this repository gives a more complete
47-
example of how to use the hooks. This is an example, and doesn't get installed
48-
with the ``pep517`` package.
72+
This 'build' module should be considered experimental while the PyPA `decides
73+
on the best place for this functionality
74+
<https://github.com/pypa/packaging-problems/issues/219>`_.

examples/README.rst

Lines changed: 0 additions & 5 deletions
This file was deleted.

examples/buildtool/__init__.py

Whitespace-only changes.

examples/buildtool/tests/__init__.py

Whitespace-only changes.

examples/buildtool/tests/samples/buildsys_pkgs/buildsys.py

Lines changed: 0 additions & 62 deletions
This file was deleted.

examples/buildtool/tests/samples/buildsys_pkgs/buildsys_minimal.py

Lines changed: 0 additions & 34 deletions
This file was deleted.

examples/buildtool/tests/samples/pkg1/pkg1-0.5.dist-info/LICENSE

Lines changed: 0 additions & 21 deletions
This file was deleted.

examples/buildtool/tests/samples/pkg1/pkg1-0.5.dist-info/METADATA

Lines changed: 0 additions & 9 deletions
This file was deleted.

examples/buildtool/tests/samples/pkg1/pkg1-0.5.dist-info/RECORD

Lines changed: 0 additions & 5 deletions
This file was deleted.

examples/buildtool/tests/samples/pkg1/pkg1-0.5.dist-info/WHEEL

Lines changed: 0 additions & 5 deletions
This file was deleted.

examples/buildtool/tests/samples/pkg1/pkg1.py

Lines changed: 0 additions & 3 deletions
This file was deleted.

examples/buildtool/tests/samples/pkg1/pyproject.toml

Lines changed: 0 additions & 3 deletions
This file was deleted.

pep517/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,3 @@
22
"""
33

44
__version__ = '0.8.2'
5-
6-
from .wrappers import * # noqa: F401,F403

examples/buildtool/build.py renamed to pep517/build.py

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,58 @@
33
import argparse
44
import logging
55
import os
6+
import toml
67
import shutil
78

89
from .envbuild import BuildEnvironment
9-
from pep517 import Pep517HookCaller
10-
from pep517.pyproject import load_system, validate_system
10+
from .wrappers import Pep517HookCaller
1111
from .dirtools import tempdir, mkdir_p
12+
from .compat import FileNotFoundError
1213

1314
log = logging.getLogger(__name__)
1415

1516

17+
def validate_system(system):
18+
"""
19+
Ensure build system has the requisite fields.
20+
"""
21+
required = {'requires', 'build-backend'}
22+
if not (required <= set(system)):
23+
message = "Missing required fields: {missing}".format(
24+
missing=required-set(system),
25+
)
26+
raise ValueError(message)
27+
28+
29+
def load_system(source_dir):
30+
"""
31+
Load the build system from a source dir (pyproject.toml).
32+
"""
33+
pyproject = os.path.join(source_dir, 'pyproject.toml')
34+
with open(pyproject) as f:
35+
pyproject_data = toml.load(f)
36+
return pyproject_data['build-system']
37+
38+
39+
def compat_system(source_dir):
40+
"""
41+
Given a source dir, attempt to get a build system backend
42+
and requirements from pyproject.toml. Fallback to
43+
setuptools but only if the file was not found or a build
44+
system was not indicated.
45+
"""
46+
try:
47+
system = load_system(source_dir)
48+
except (FileNotFoundError, KeyError):
49+
system = {}
50+
system.setdefault(
51+
'build-backend',
52+
'setuptools.build_meta:__legacy__',
53+
)
54+
system.setdefault('requires', ['setuptools', 'wheel'])
55+
return system
56+
57+
1658
def _do_build(hooks, env, dist, dest):
1759
get_requires_name = 'get_requires_for_build_{dist}'.format(**locals())
1860
get_requires = getattr(hooks, get_requires_name)

examples/buildtool/check.py renamed to pep517/check.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from .colorlog import enable_colourful_output
1616
from .envbuild import BuildEnvironment
17-
from pep517 import Pep517HookCaller
17+
from .wrappers import Pep517HookCaller
1818

1919
log = logging.getLogger(__name__)
2020

File renamed without changes.
File renamed without changes.

examples/buildtool/envbuild.py renamed to pep517/envbuild.py

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@
99
import sys
1010
from sysconfig import get_paths
1111
from tempfile import mkdtemp
12-
import threading
1312

14-
from pep517 import Pep517HookCaller
13+
from .wrappers import Pep517HookCaller, LoggerWrapper
1514

1615
log = logging.getLogger(__name__)
1716

@@ -27,40 +26,6 @@ def _load_pyproject(source_dir):
2726
)
2827

2928

30-
class LoggerWrapper(threading.Thread):
31-
"""
32-
Read messages from a pipe and redirect them
33-
to a logger (see python's logging module).
34-
"""
35-
36-
def __init__(self, logger, level):
37-
threading.Thread.__init__(self)
38-
self.daemon = True
39-
40-
self.logger = logger
41-
self.level = level
42-
43-
# create the pipe and reader
44-
self.fd_read, self.fd_write = os.pipe()
45-
self.reader = os.fdopen(self.fd_read)
46-
47-
self.start()
48-
49-
def fileno(self):
50-
return self.fd_write
51-
52-
@staticmethod
53-
def remove_newline(msg):
54-
return msg[:-1] if msg.endswith(os.linesep) else msg
55-
56-
def run(self):
57-
for line in self.reader:
58-
self._write(self.remove_newline(line))
59-
60-
def _write(self, message):
61-
self.logger.log(self.level, message)
62-
63-
6429
class BuildEnvironment(object):
6530
"""Context manager to install build deps in a simple temporary environment
6631

examples/buildtool/meta.py renamed to pep517/meta.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717
from zipp import Path
1818

1919
from .envbuild import BuildEnvironment
20-
from pep517 import Pep517HookCaller, quiet_subprocess_runner
21-
from pep517.pyproject import validate_system, load_system, compat_system
20+
from .wrappers import Pep517HookCaller, quiet_subprocess_runner
2221
from .dirtools import tempdir, mkdir_p, dir_to_zipfile
22+
from .build import validate_system, load_system, compat_system
2323

2424
log = logging.getLogger(__name__)
2525

0 commit comments

Comments
 (0)