-
Notifications
You must be signed in to change notification settings - Fork 54
New command pep517.meta #48
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
Merged
Merged
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
28ceec4
Drafted an implementation of a 'build-meta' command for pep517 projec…
jaraco 8793a46
Allow 'build_meta' to be importable
jaraco 1d79831
Add build_meta_as_zip function. Fixes #26.
jaraco 9a3654b
Allow build system to be supplied to the build_meta command.
jaraco 8c52ae2
Add a function for supplying a fallback, setuptools-based build system.
jaraco cc2d966
Move two dirtools to a module
jaraco 6eea6ea
Move 'build' support to build module
jaraco b35a8dd
Add docstrings
jaraco 9366451
The spec is 'build-system.build-backend', not 'build-system.backend'.
jaraco 13e05d2
Add 'load' method for loading the metadata as an importlib.metadata.D…
jaraco 9bcdf84
Invoke expanduser on the root so the caller doesn't have to.
jaraco 8033aae
Add a docstring to tempdir
jaraco fcbb6e2
Use the classic syntax for __main__ detection
jaraco 7e60f44
Rename 'build_meta' to simply 'meta'
jaraco 45c2c37
Move dir_to_zipfile to dirtools
jaraco f62f785
Remove 'build-meta'. Instead, users should use pep517.meta for that c…
jaraco 0c24fd7
Add a basic test for the metadata functionality.
jaraco bf600de
Remove excess newline
jaraco 76c2682
Mark test as xfail on Python 2.7 due to pep517 being a flit package.
jaraco 6d06c6a
Add another test demonstrating support for classic packages.
jaraco e3138f4
Add test for expecation that output shouldn't be so noisy
jaraco d27a2ec
Suppress output when building metadata. This required suppressing out…
jaraco 11ade28
Skip an additional test on Python 2
jaraco e4ff5bd
Instead of suppressing output for pip_install, direct it to the loggi…
jaraco bdad30a
Inline the 'missing' name to avoid locals invocation.
jaraco 0da9696
More precisely trap errors in compat_system, only catching two expect…
jaraco bcf3def
Add tests for validate_system.
jaraco 1f90e57
Correct behavior of validate_system. Thanks takluyver
jaraco 7d568e5
Rewrite docstring to describe more precisely what's happening.
jaraco 205d128
Rely on __legacy__ for fallback behavior.
jaraco File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ mock | |
testpath | ||
pytoml | ||
setuptools>=30 | ||
importlib_metadata | ||
zipp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import os | ||
import io | ||
import contextlib | ||
import tempfile | ||
import shutil | ||
import errno | ||
import zipfile | ||
|
||
|
||
@contextlib.contextmanager | ||
def tempdir(): | ||
jaraco marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"""Create a temporary directory in a context manager.""" | ||
td = tempfile.mkdtemp() | ||
try: | ||
yield td | ||
finally: | ||
shutil.rmtree(td) | ||
|
||
|
||
def mkdir_p(*args, **kwargs): | ||
"""Like `mkdir`, but does not raise an exception if the | ||
directory already exists. | ||
""" | ||
try: | ||
return os.mkdir(*args, **kwargs) | ||
except OSError as exc: | ||
if exc.errno != errno.EEXIST: | ||
raise | ||
|
||
|
||
def dir_to_zipfile(root): | ||
"""Construct an in-memory zip file for a directory.""" | ||
buffer = io.BytesIO() | ||
zip_file = zipfile.ZipFile(buffer, 'w') | ||
for root, dirs, files in os.walk(root): | ||
for path in dirs: | ||
fs_path = os.path.join(root, path) | ||
rel_path = os.path.relpath(fs_path, root) | ||
zip_file.writestr(rel_path + '/', '') | ||
for path in files: | ||
fs_path = os.path.join(root, path) | ||
rel_path = os.path.relpath(fs_path, root) | ||
zip_file.write(fs_path, rel_path) | ||
return zip_file |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
"""Build metadata for a project using PEP 517 hooks. | ||
""" | ||
import argparse | ||
import logging | ||
import os | ||
import shutil | ||
import functools | ||
|
||
try: | ||
import importlib.metadata as imp_meta | ||
except ImportError: | ||
import importlib_metadata as imp_meta | ||
|
||
try: | ||
from zipfile import Path | ||
except ImportError: | ||
from zipp import Path | ||
|
||
from .envbuild import BuildEnvironment | ||
from .wrappers import Pep517HookCaller, quiet_subprocess_runner | ||
from .dirtools import tempdir, mkdir_p, dir_to_zipfile | ||
from .build import validate_system, load_system, compat_system | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
def _prep_meta(hooks, env, dest): | ||
reqs = hooks.get_requires_for_build_wheel({}) | ||
log.info('Got build requires: %s', reqs) | ||
|
||
env.pip_install(reqs) | ||
log.info('Installed dynamic build dependencies') | ||
|
||
with tempdir() as td: | ||
log.info('Trying to build metadata in %s', td) | ||
filename = hooks.prepare_metadata_for_build_wheel(td, {}) | ||
source = os.path.join(td, filename) | ||
shutil.move(source, os.path.join(dest, os.path.basename(filename))) | ||
|
||
|
||
def build(source_dir='.', dest=None, system=None): | ||
system = system or load_system(source_dir) | ||
dest = os.path.join(source_dir, dest or 'dist') | ||
mkdir_p(dest) | ||
validate_system(system) | ||
hooks = Pep517HookCaller(source_dir, system['build-backend']) | ||
|
||
with hooks.subprocess_runner(quiet_subprocess_runner): | ||
with BuildEnvironment() as env: | ||
env.pip_install(system['requires']) | ||
_prep_meta(hooks, env, dest) | ||
|
||
|
||
def build_as_zip(builder=build): | ||
with tempdir() as out_dir: | ||
builder(dest=out_dir) | ||
return dir_to_zipfile(out_dir) | ||
|
||
|
||
def load(root): | ||
""" | ||
Given a source directory (root) of a package, | ||
return an importlib.metadata.Distribution object | ||
with metadata build from that package. | ||
""" | ||
root = os.path.expanduser(root) | ||
system = compat_system(root) | ||
builder = functools.partial(build, source_dir=root, system=system) | ||
path = Path(build_as_zip(builder)) | ||
return imp_meta.PathDistribution(path) | ||
|
||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
'source_dir', | ||
help="A directory containing pyproject.toml", | ||
) | ||
parser.add_argument( | ||
'--out-dir', '-o', | ||
help="Destination in which to save the builds relative to source dir", | ||
) | ||
|
||
|
||
def main(): | ||
args = parser.parse_args() | ||
build(args.source_dir, args.out_dir) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
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')) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.