1# Copyright 2020 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"""Wrapper for the CLI commands for Python .whl building.""" 15 16import argparse 17import logging 18import os 19import subprocess 20import sys 21 22_LOG = logging.getLogger(__name__) 23 24 25def _parse_args(): 26 parser = argparse.ArgumentParser(description=__doc__) 27 parser.add_argument( 28 'setup_files', 29 nargs='+', 30 help='Path to a setup.py file to invoke to build wheels.', 31 ) 32 parser.add_argument( 33 '--out_dir', help='Path where the build artifacts should be put.' 34 ) 35 36 return parser.parse_args() 37 38 39def build_wheels(setup_files, out_dir): 40 """Build Python wheels by calling 'python setup.py bdist_wheel'.""" 41 dist_dir = os.path.abspath(out_dir) 42 43 for filename in setup_files: 44 if not (filename.endswith('setup.py') and os.path.isfile(filename)): 45 raise RuntimeError(f'Unable to find setup.py file at {filename}.') 46 47 working_dir = os.path.dirname(filename) 48 49 cmd = [ 50 sys.executable, 51 'setup.py', 52 'bdist_wheel', 53 '--dist-dir', 54 dist_dir, 55 ] 56 _LOG.debug('Running command:\n %s', ' '.join(cmd)) 57 subprocess.check_call(cmd, cwd=working_dir) 58 59 60def main(): 61 build_wheels(**vars(_parse_args())) 62 63 64if __name__ == '__main__': 65 logging.basicConfig() 66 main() 67 sys.exit(0) 68