/// <summary> /// Recursively resolves the dependencies of a given package. /// </summary> /// <param name="packageName">Name of the package.</param> /// <param name="venv">Representation of current virtual environment.</param> /// <param name="dependencies">The dependencies.</param> private void ResolveDependencies(string packageName, PythonVirtualEnv venv, ICollection <LambdaDependency> dependencies) { if (IgnoreDependencies.Contains(packageName)) { this.logger.LogVerbose($"Package '{packageName}' will not be included because it exists by default in the AWS execution environment."); return; } var module = venv[packageName]; if (module == null) { this.logger.LogWarning($"Cannot find module '{packageName}' in your virtual environment"); return; } dependencies.Add(new LambdaDependency { Location = venv.VirtualEnvDir, Libraries = module.Paths.ToArray() }); foreach (var pkg in module.Dependencies) { this.ResolveDependencies(pkg, venv, dependencies); } }
/// <summary> /// Loads dependencies from requirements.txt file. /// </summary> /// <param name="pathToRequirements">The path to requirements.txt.</param> /// <returns>Deserialized Dependencies</returns> internal List <LambdaDependency> LoadDependenciesFromRequirements(string pathToRequirements) { var dependencies = new List <LambdaDependency>(); if (string.IsNullOrEmpty(pathToRequirements)) { return(dependencies); } var venv = new PythonVirtualEnv(this.platform).Load(this.RuntimeInfo); foreach (var match in RequirementsRegex.Matches(File.ReadAllText(pathToRequirements)).Cast <Match>()) { this.ResolveDependencies(match.Groups["dependency"].Value.Trim(), venv, dependencies); } return(dependencies.Distinct().ToList()); }