• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2021 The Pigweed Authors
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4# use this file except in compliance with the License. You may obtain a copy of
5# the License at
6#
7#     https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations under
13# the License.
14"""Collect Python wheels from a build into a central directory."""
15
16import argparse
17import logging
18from pathlib import Path
19import shutil
20import sys
21
22_LOG = logging.getLogger(__name__)
23
24
25def _parse_args():
26    parser = argparse.ArgumentParser(description=__doc__)
27    parser.add_argument(
28        '--prefix',
29        type=Path,
30        help='Root search path to use in conjunction with --wheels_file')
31    parser.add_argument(
32        '--suffix_file',
33        type=argparse.FileType('r'),
34        help=('File that lists subdirs relative to --prefix, one per line,'
35              'to search for .whl files to copy into --out_dir'))
36    parser.add_argument(
37        '--out_dir',
38        type=Path,
39        help='Path where all the built and collected .whl files should be put')
40
41    return parser.parse_args()
42
43
44def copy_wheels(prefix, suffix_file, out_dir):
45    if not out_dir.exists():
46        out_dir.mkdir()
47
48    for suffix in suffix_file.readlines():
49        path = prefix / suffix.strip()
50        _LOG.debug('Searching for wheels in %s', path)
51        if path == out_dir:
52            continue
53        for wheel in path.glob('**/*.whl'):
54            _LOG.debug('Copying %s to %s', wheel, out_dir)
55            shutil.copy(wheel, out_dir)
56
57
58def main():
59    copy_wheels(**vars(_parse_args()))
60
61
62if __name__ == '__main__':
63    logging.basicConfig()
64    main()
65    sys.exit(0)
66