def __init__(self, descriptor): super().__init__(descriptor) # Check to see whether this URL should be patched. url_creds_var = descriptor.get('url_creds_var', None) if url_creds_var is not None: env = ShellEnvironment.GetEnvironment() url_creds = env.get_shell_var(url_creds_var) if url_creds is not None: # Break things up. source_parts = urlsplit(self.source) # Modify the URL host with the creds. new_parts = (source_parts.scheme, url_creds + '@' + source_parts.netloc, source_parts.path, source_parts.query, source_parts.fragment) # Put things back together. self.source = urlunsplit(new_parts) self.repo_url = self.source self.commit = self.version self._local_repo_root_path = os.path.join(os.path.abspath(self.contents_dir), self.name) self.logger = logging.getLogger("git-dependency") # valid_attributes = ["Path", "Url", "Branch", "Commit", "ReferencePath", "Full"] self._repo_resolver_dep_obj = {"Path": self.name, "Url": self.repo_url, "Commit": self.commit}
def test_url_should_not_be_modified_without_descriptor_field(self): my_test_descriptor = copy.copy(TestGitDependencyUrlPatching.TEST_DESCRIPTOR) env = ShellEnvironment.GetEnvironment() # Add the var to the environment. env.set_shell_var('test_creds_var', 'my_stuff') # Initialize the GitDependency object. gdep = GitDependency(my_test_descriptor) # Assert that the URL is identical. self.assertEqual(gdep.source, my_test_descriptor['source'])
def test_url_should_be_modified_if_creds_are_indicated_and_supplied(self): my_test_descriptor = copy.copy(TestGitDependencyUrlPatching.TEST_DESCRIPTOR) # Add the indicator for patching. my_test_descriptor['url_creds_var'] = 'test_creds_var' env = ShellEnvironment.GetEnvironment() # Add the var to the environment. env.set_shell_var('test_creds_var', 'my_stuff') # Initialize the GitDependency object. gdep = GitDependency(my_test_descriptor) # Assert that the URL is identical. self.assertEqual(gdep.source, "https://[email protected]/octocat/Hello-World.git")
def BootstrapEnvironment(workspace, scopes=()): global ENVIRONMENT_BOOTSTRAP_COMPLETE, ENV_STATE if not ENVIRONMENT_BOOTSTRAP_COMPLETE: # # ENVIRONMENT BOOTSTRAP STAGE 1 # Locate and load all environment description files. # build_env = SelfDescribingEnvironment( workspace, scopes).load_workspace() # # ENVIRONMENT BOOTSTRAP STAGE 2 # Parse all of the PATH-related descriptor files to make sure that # any required tools or Python modules are now available. # shell_env = ShellEnvironment.GetEnvironment() build_env.update_simple_paths(shell_env) # # ENVIRONMENT BOOTSTRAP STAGE 3 # Now that the preliminary paths have been loaded, # we can load the modules that had greater dependencies. # build_env.update_extdep_paths(shell_env) # Bind our current execution environment into the shell vars. shell_env.set_shell_var("PYTHON_HOME", os.path.dirname(sys.executable)) # MU_DEPRECATED - Support legacy variable for older releases. shell_env.set_shell_var("PYTHON3", sys.executable) # PYTHON_COMMAND is required to be set for Linux shell_env.set_shell_var("PYTHON_COMMAND", sys.executable) # Debug the environment that was produced. shell_env.log_environment() ENVIRONMENT_BOOTSTRAP_COMPLETE = True ENV_STATE = (build_env, shell_env) # Return the environment as it's configured. return ENV_STATE
def setUpClass(cls): env = ShellEnvironment.GetEnvironment() cls.env_checkpoint = env.checkpoint()
def tearDown(self): env = ShellEnvironment.GetEnvironment() env.restore_checkpoint(TestGitDependencyUrlPatching.env_checkpoint)