| 
									
										
										
										
											2013-06-02 13:54:46 -07:00
										 |  |  | #!/usr/bin/env python | 
					
						
							| 
									
										
										
										
											2014-01-08 10:21:02 +01:00
										 |  |  | ############################################################################## | 
					
						
							| 
									
										
										
										
											2017-09-07 05:44:16 +02:00
										 |  |  | # Copyright (c) 2013-2017, Lawrence Livermore National Security, LLC. | 
					
						
							| 
									
										
										
										
											2014-01-08 10:21:02 +01:00
										 |  |  | # Produced at the Lawrence Livermore National Laboratory. | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # This file is part of Spack. | 
					
						
							| 
									
										
										
										
											2016-05-11 21:22:25 -07:00
										 |  |  | # Created by Todd Gamblin, tgamblin@llnl.gov, All rights reserved. | 
					
						
							| 
									
										
										
										
											2014-01-08 10:21:02 +01:00
										 |  |  | # LLNL-CODE-647188 | 
					
						
							|  |  |  | # | 
					
						
							| 
									
										
										
										
											2017-11-04 17:08:04 -07:00
										 |  |  | # For details, see https://github.com/spack/spack | 
					
						
							| 
									
										
										
										
											2017-06-24 22:22:55 -07:00
										 |  |  | # Please also see the NOTICE and LICENSE files for our notice and the LGPL. | 
					
						
							| 
									
										
										
										
											2014-01-08 10:21:02 +01:00
										 |  |  | # | 
					
						
							|  |  |  | # This program is free software; you can redistribute it and/or modify | 
					
						
							| 
									
										
										
										
											2016-05-11 21:22:25 -07:00
										 |  |  | # it under the terms of the GNU Lesser General Public License (as | 
					
						
							|  |  |  | # published by the Free Software Foundation) version 2.1, February 1999. | 
					
						
							| 
									
										
										
										
											2014-01-08 10:21:02 +01:00
										 |  |  | # | 
					
						
							|  |  |  | # This program is distributed in the hope that it will be useful, but | 
					
						
							|  |  |  | # WITHOUT ANY WARRANTY; without even the IMPLIED WARRANTY OF | 
					
						
							|  |  |  | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the terms and | 
					
						
							| 
									
										
										
										
											2016-05-11 21:22:25 -07:00
										 |  |  | # conditions of the GNU Lesser General Public License for more details. | 
					
						
							| 
									
										
										
										
											2014-01-08 10:21:02 +01:00
										 |  |  | # | 
					
						
							| 
									
										
										
										
											2016-05-11 21:22:25 -07:00
										 |  |  | # You should have received a copy of the GNU Lesser General Public | 
					
						
							|  |  |  | # License along with this program; if not, write to the Free Software | 
					
						
							|  |  |  | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 
					
						
							| 
									
										
										
										
											2014-01-08 10:21:02 +01:00
										 |  |  | ############################################################################## | 
					
						
							| 
									
										
										
										
											2017-03-07 14:25:48 -08:00
										 |  |  | from __future__ import print_function | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-08 13:18:29 -07:00
										 |  |  | import os | 
					
						
							| 
									
										
										
										
											2013-06-02 13:54:46 -07:00
										 |  |  | import sys | 
					
						
							| 
									
										
										
										
											2017-05-08 13:18:29 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-07 09:31:15 -08:00
										 |  |  | if sys.version_info[:2] < (2, 6): | 
					
						
							| 
									
										
										
										
											2014-12-19 11:09:37 -08:00
										 |  |  |     v_info = sys.version_info[:3] | 
					
						
							| 
									
										
										
										
											2017-03-07 09:31:15 -08:00
										 |  |  |     sys.exit("Spack requires Python 2.6 or higher." | 
					
						
							| 
									
										
										
										
											2016-08-09 13:23:53 -07:00
										 |  |  |              "This is Python %d.%d.%d." % v_info) | 
					
						
							| 
									
										
										
										
											2013-02-13 17:50:44 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | # Find spack's location and its prefix. | 
					
						
							| 
									
										
										
										
											2017-05-08 13:18:29 -07:00
										 |  |  | spack_file = os.path.realpath(os.path.expanduser(__file__)) | 
					
						
							|  |  |  | spack_prefix = os.path.dirname(os.path.dirname(spack_file)) | 
					
						
							| 
									
										
										
										
											2013-02-13 17:50:44 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | # Allow spack libs to be imported in our scripts | 
					
						
							| 
									
										
										
										
											2017-05-08 13:18:29 -07:00
										 |  |  | spack_lib_path = os.path.join(spack_prefix, "lib", "spack") | 
					
						
							|  |  |  | sys.path.insert(0, spack_lib_path) | 
					
						
							| 
									
										
										
										
											2016-10-12 18:25:18 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | # Add external libs | 
					
						
							| 
									
										
										
										
											2017-05-08 13:18:29 -07:00
										 |  |  | spack_external_libs = os.path.join(spack_lib_path, "external") | 
					
						
							| 
									
										
										
										
											2018-01-16 07:00:39 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | if sys.version_info[:2] == (2, 6): | 
					
						
							|  |  |  |     sys.path.insert(0, os.path.join(spack_external_libs, 'py26')) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-08 13:18:29 -07:00
										 |  |  | sys.path.insert(0, spack_external_libs) | 
					
						
							| 
									
										
										
										
											2013-02-13 17:50:44 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-07 09:32:43 -08:00
										 |  |  | # Handle vendoring of YAML specially, as it has two versions. | 
					
						
							|  |  |  | if sys.version_info[0] == 2: | 
					
						
							| 
									
										
										
										
											2017-05-08 13:18:29 -07:00
										 |  |  |     spack_yaml_libs = os.path.join(spack_external_libs, "yaml/lib") | 
					
						
							| 
									
										
										
										
											2017-03-07 09:32:43 -08:00
										 |  |  | else: | 
					
						
							| 
									
										
										
										
											2017-05-08 13:18:29 -07:00
										 |  |  |     spack_yaml_libs = os.path.join(spack_external_libs, "yaml/lib3") | 
					
						
							|  |  |  | sys.path.insert(0, spack_yaml_libs) | 
					
						
							| 
									
										
										
										
											2017-03-07 09:32:43 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-23 17:39:59 -08:00
										 |  |  | # Quick and dirty check to clean orphaned .pyc files left over from | 
					
						
							|  |  |  | # previous revisions.  These files were present in earlier versions of | 
					
						
							|  |  |  | # Spack, were removed, but shadow system modules that Spack still | 
					
						
							|  |  |  | # imports.  If we leave them, Spack will fail in mysterious ways. | 
					
						
							|  |  |  | # TODO: more elegant solution for orphaned pyc files. | 
					
						
							| 
									
										
										
										
											2016-08-30 10:47:38 -05:00
										 |  |  | orphaned_pyc_files = [ | 
					
						
							| 
									
										
										
										
											2017-05-08 13:18:29 -07:00
										 |  |  |     os.path.join(spack_external_libs, 'functools.pyc'), | 
					
						
							|  |  |  |     os.path.join(spack_external_libs, 'ordereddict.pyc'), | 
					
						
							|  |  |  |     os.path.join(spack_lib_path, 'spack', 'platforms', 'cray_xc.pyc'), | 
					
						
							|  |  |  |     os.path.join(spack_lib_path, 'spack', 'cmd', 'package-list.pyc'), | 
					
						
							|  |  |  |     os.path.join(spack_lib_path, 'spack', 'cmd', 'test-install.pyc'), | 
					
						
							|  |  |  |     os.path.join(spack_lib_path, 'spack', 'cmd', 'url-parse.pyc'), | 
					
						
							|  |  |  |     os.path.join(spack_lib_path, 'spack', 'test', 'yaml.pyc') | 
					
						
							| 
									
										
										
										
											2016-08-30 10:47:38 -05:00
										 |  |  | ] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-23 17:39:59 -08:00
										 |  |  | for pyc_file in orphaned_pyc_files: | 
					
						
							|  |  |  |     if not os.path.exists(pyc_file): | 
					
						
							|  |  |  |         continue | 
					
						
							|  |  |  |     try: | 
					
						
							|  |  |  |         os.remove(pyc_file) | 
					
						
							|  |  |  |     except OSError as e: | 
					
						
							| 
									
										
										
										
											2017-03-07 14:25:48 -08:00
										 |  |  |         print("WARNING: Spack may fail mysteriously. " | 
					
						
							|  |  |  |               "Couldn't remove orphaned .pyc file: %s" % pyc_file) | 
					
						
							| 
									
										
										
										
											2015-11-23 17:39:59 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-08 13:18:29 -07:00
										 |  |  | # Once we've set up the system path, run the spack main method | 
					
						
							|  |  |  | import spack.main  # noqa | 
					
						
							|  |  |  | sys.exit(spack.main.main()) |