| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2015 The Chromium Authors. All rights reserved. | 2 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """Implements a standard mechanism for Chrome Infra Python environment setup. | 6 """Implements a standard mechanism for Chrome Infra Python environment setup. |
| 7 | 7 |
| 8 This library provides a central location to define Chrome Infra environment | 8 This library provides a central location to define Chrome Infra environment |
| 9 setup. It also provides several faculties to install this environment. | 9 setup. It also provides several faculties to install this environment. |
| 10 | 10 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 def path_if(*args): | 58 def path_if(*args): |
| 59 if not all(args): | 59 if not all(args): |
| 60 return None | 60 return None |
| 61 path = os.path.abspath(os.path.join(*args)) | 61 path = os.path.abspath(os.path.join(*args)) |
| 62 return (path) if os.path.exists(path) else (None) | 62 return (path) if os.path.exists(path) else (None) |
| 63 | 63 |
| 64 # The path to the <build> directory in which this script resides. | 64 # The path to the <build> directory in which this script resides. |
| 65 Build = path_if(os.path.dirname(__file__), os.pardir, os.pardir) | 65 Build = path_if(os.path.dirname(__file__), os.pardir, os.pardir) |
| 66 # The path to the <build_internal> directory. | 66 # The path to the <build_internal> directory. |
| 67 BuildInternal = path_if(Build, os.pardir, 'build_internal') | 67 BuildInternal = path_if(Build, os.pardir, 'build_internal') |
| 68 Infra = path_if(Build, os.pardir, 'infra') |
| 68 | 69 |
| 69 | 70 |
| 70 def SetPythonPathEnv(value): | 71 def SetPythonPathEnv(value): |
| 71 """Sets the system's PYTHONPATH environemnt variable. | 72 """Sets the system's PYTHONPATH environemnt variable. |
| 72 | 73 |
| 73 Args: | 74 Args: |
| 74 value (str): The value to use. If this is empty/None, the system's | 75 value (str): The value to use. If this is empty/None, the system's |
| 75 PYTHONPATH will be cleared. | 76 PYTHONPATH will be cleared. |
| 76 """ | 77 """ |
| 77 # Since we can't assign None to the environment "dictionary", we have to | 78 # Since we can't assign None to the environment "dictionary", we have to |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 - The system python path. | 365 - The system python path. |
| 365 | 366 |
| 366 Args: | 367 Args: |
| 367 hermetic (bool): True, prune any non-system path from the system path. | 368 hermetic (bool): True, prune any non-system path from the system path. |
| 368 master_dir (str): If not None, include a master path component. | 369 master_dir (str): If not None, include a master path component. |
| 369 """ | 370 """ |
| 370 path = PythonPath() | 371 path = PythonPath() |
| 371 if master_dir: | 372 if master_dir: |
| 372 path += GetMasterPythonPath(master_dir) | 373 path += GetMasterPythonPath(master_dir) |
| 373 path += GetBuildPythonPath() | 374 path += GetBuildPythonPath() |
| 375 path += Infra |
| 374 path += GetSysPythonPath(hermetic=hermetic) | 376 path += GetSysPythonPath(hermetic=hermetic) |
| 375 return path | 377 return path |
| 376 | 378 |
| 377 | 379 |
| 378 def _InfraPathFromArgs(args): | 380 def _InfraPathFromArgs(args): |
| 379 """Returns (PythonPath): A PythonPath populated from command-line arguments. | 381 """Returns (PythonPath): A PythonPath populated from command-line arguments. |
| 380 | 382 |
| 381 Args: | 383 Args: |
| 382 args (argparse.Namespace): The command-line arguments constructed by 'main'. | 384 args (argparse.Namespace): The command-line arguments constructed by 'main'. |
| 383 """ | 385 """ |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 # Parse | 439 # Parse |
| 438 args = parser.parse_args() | 440 args = parser.parse_args() |
| 439 | 441 |
| 440 # Execute our subcommand function, which will return the exit code. | 442 # Execute our subcommand function, which will return the exit code. |
| 441 path = _InfraPathFromArgs(args) | 443 path = _InfraPathFromArgs(args) |
| 442 return args.func(args, path) | 444 return args.func(args, path) |
| 443 | 445 |
| 444 | 446 |
| 445 if __name__ == '__main__': | 447 if __name__ == '__main__': |
| 446 sys.exit(main()) | 448 sys.exit(main()) |
| OLD | NEW |