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"""Runnable module that sets up virtualenv for Pigweed.""" 15 16import argparse 17import os 18import sys 19 20# pylint: disable=import-error 21try: 22 from pw_env_setup import virtualenv_setup 23except ImportError: 24 import install as virtualenv_setup # type: ignore 25# pylint: enable=import-error 26 27 28def _main(): 29 parser = argparse.ArgumentParser( 30 prog="python -m pw_env_setup.virtualenv_setup", description=__doc__ 31 ) 32 33 project_root = os.environ.get('PW_PROJECT_ROOT', None) 34 35 parser.add_argument( 36 '--project-root', 37 default=project_root, 38 required=not project_root, 39 help='Path to overall project root.', 40 ) 41 parser.add_argument( 42 '--venv_path', required=True, help='Path at which to create the venv' 43 ) 44 parser.add_argument( 45 '-r', 46 '--requirements', 47 default=[], 48 action='append', 49 help='requirements.txt files to install', 50 ) 51 parser.add_argument( 52 '--gn-target', 53 dest='gn_targets', 54 default=[], 55 action='append', 56 type=virtualenv_setup.GnTarget, 57 help='GN targets that install packages', 58 ) 59 parser.add_argument( 60 '--quick-setup', 61 dest='full_envsetup', 62 action='store_false', 63 default='PW_ENVSETUP_FULL' in os.environ, 64 help=( 65 'Do full setup or only minimal checks to see if ' 66 'full setup is required.' 67 ), 68 ) 69 parser.add_argument( 70 '--python', 71 default=sys.executable, 72 help='Python to use when creating virtualenv.', 73 ) 74 75 virtualenv_setup.install(**vars(parser.parse_args())) 76 77 return 0 78 79 80if __name__ == '__main__': 81 sys.exit(_main()) 82