Mercurial > repos > guerler > hhblits
comparison lib/python3.8/site-packages/pip/_vendor/pep517/meta.py @ 0:9e54283cc701 draft
"planemo upload commit d12c32a45bcd441307e632fca6d9af7d60289d44"
author | guerler |
---|---|
date | Mon, 27 Jul 2020 03:47:31 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:9e54283cc701 |
---|---|
1 """Build metadata for a project using PEP 517 hooks. | |
2 """ | |
3 import argparse | |
4 import logging | |
5 import os | |
6 import shutil | |
7 import functools | |
8 | |
9 try: | |
10 import importlib.metadata as imp_meta | |
11 except ImportError: | |
12 import importlib_metadata as imp_meta | |
13 | |
14 try: | |
15 from zipfile import Path | |
16 except ImportError: | |
17 from zipp import Path | |
18 | |
19 from .envbuild import BuildEnvironment | |
20 from .wrappers import Pep517HookCaller, quiet_subprocess_runner | |
21 from .dirtools import tempdir, mkdir_p, dir_to_zipfile | |
22 from .build import validate_system, load_system, compat_system | |
23 | |
24 log = logging.getLogger(__name__) | |
25 | |
26 | |
27 def _prep_meta(hooks, env, dest): | |
28 reqs = hooks.get_requires_for_build_wheel({}) | |
29 log.info('Got build requires: %s', reqs) | |
30 | |
31 env.pip_install(reqs) | |
32 log.info('Installed dynamic build dependencies') | |
33 | |
34 with tempdir() as td: | |
35 log.info('Trying to build metadata in %s', td) | |
36 filename = hooks.prepare_metadata_for_build_wheel(td, {}) | |
37 source = os.path.join(td, filename) | |
38 shutil.move(source, os.path.join(dest, os.path.basename(filename))) | |
39 | |
40 | |
41 def build(source_dir='.', dest=None, system=None): | |
42 system = system or load_system(source_dir) | |
43 dest = os.path.join(source_dir, dest or 'dist') | |
44 mkdir_p(dest) | |
45 validate_system(system) | |
46 hooks = Pep517HookCaller( | |
47 source_dir, system['build-backend'], system.get('backend-path') | |
48 ) | |
49 | |
50 with hooks.subprocess_runner(quiet_subprocess_runner): | |
51 with BuildEnvironment() as env: | |
52 env.pip_install(system['requires']) | |
53 _prep_meta(hooks, env, dest) | |
54 | |
55 | |
56 def build_as_zip(builder=build): | |
57 with tempdir() as out_dir: | |
58 builder(dest=out_dir) | |
59 return dir_to_zipfile(out_dir) | |
60 | |
61 | |
62 def load(root): | |
63 """ | |
64 Given a source directory (root) of a package, | |
65 return an importlib.metadata.Distribution object | |
66 with metadata build from that package. | |
67 """ | |
68 root = os.path.expanduser(root) | |
69 system = compat_system(root) | |
70 builder = functools.partial(build, source_dir=root, system=system) | |
71 path = Path(build_as_zip(builder)) | |
72 return imp_meta.PathDistribution(path) | |
73 | |
74 | |
75 parser = argparse.ArgumentParser() | |
76 parser.add_argument( | |
77 'source_dir', | |
78 help="A directory containing pyproject.toml", | |
79 ) | |
80 parser.add_argument( | |
81 '--out-dir', '-o', | |
82 help="Destination in which to save the builds relative to source dir", | |
83 ) | |
84 | |
85 | |
86 def main(): | |
87 args = parser.parse_args() | |
88 build(args.source_dir, args.out_dir) | |
89 | |
90 | |
91 if __name__ == '__main__': | |
92 main() |