private BuildScriptSnippet GetBuildScriptSnippetForConda( BuildScriptGeneratorContext context, PythonPlatformDetectorResult detectorResult) { var scriptProperties = new JupyterNotebookBashBuildSnippetProperties(); scriptProperties.HasRequirementsTxtFile = detectorResult.HasRequirementsTxtFile; if (detectorResult.HasCondaEnvironmentYmlFile) { scriptProperties.EnvironmentYmlFile = CondaConstants.CondaEnvironmentYmlFileName; } else { string pythonVersion; string templateName; var version = new SemVer.Version(detectorResult.PlatformVersion); if (version.Major.Equals(2)) { templateName = CondaConstants.DefaultPython2CondaEnvironmentYmlFileTemplateName; // Conda seems to have a problem with post 2.7.15 version, // so we by default restrict it to this version pythonVersion = CondaConstants.DefaultPython2Version; } else { templateName = CondaConstants.DefaultCondaEnvironmentYmlFileTemplateName; pythonVersion = detectorResult.PlatformVersion; } scriptProperties.EnvironmentTemplateFileName = templateName; scriptProperties.EnvironmentTemplatePythonVersion = pythonVersion; } var script = TemplateHelper.Render( TemplateHelper.TemplateResource.PythonJupyterNotebookSnippet, scriptProperties, _logger); return(new BuildScriptSnippet { BashBuildScriptSnippet = script, }); }
private BuildScriptSnippet GetBuildScriptSnippetForConda( BuildScriptGeneratorContext context, PythonPlatformDetectorResult detectorResult) { var scriptProperties = new JupyterNotebookBashBuildSnippetProperties(); scriptProperties.HasRequirementsTxtFile = detectorResult.HasRequirementsTxtFile; _logger.LogInformation($"conda context buildcommandsfilename: {context.BuildCommandsFileName}"); _logger.LogInformation($"conda common option buildcommandsfilename: {_commonOptions.BuildCommandsFileName}"); _logger.LogInformation($"conda common option manifest dir: {_commonOptions.ManifestDir}"); var condaBuildCommandsFile = string.IsNullOrEmpty(_commonOptions.BuildCommandsFileName) ? FilePaths.BuildCommandsFileName : _commonOptions.BuildCommandsFileName; condaBuildCommandsFile = string.IsNullOrEmpty(_commonOptions.ManifestDir) ? Path.Combine(context.SourceRepo.RootPath, condaBuildCommandsFile) : Path.Combine(this._commonOptions.ManifestDir, condaBuildCommandsFile); _logger.LogInformation($"conda buildcommandsfilename with path: {condaBuildCommandsFile}"); var manifestFileProperties = new Dictionary <string, string>(); // Write the platform name and version to the manifest file manifestFileProperties[ManifestFilePropertyKeys.PythonVersion] = detectorResult.PlatformVersion; manifestFileProperties[nameof(condaBuildCommandsFile)] = condaBuildCommandsFile; if (detectorResult.HasCondaEnvironmentYmlFile) { scriptProperties.EnvironmentYmlFile = CondaConstants.CondaEnvironmentYmlFileName; } else { string pythonVersion; string templateName; var version = new SemVer.Version(detectorResult.PlatformVersion); if (version.Major.Equals(2)) { templateName = CondaConstants.DefaultPython2CondaEnvironmentYmlFileTemplateName; // Conda seems to have a problem with post 2.7.15 version, // so we by default restrict it to this version pythonVersion = CondaConstants.DefaultPython2Version; } else { templateName = CondaConstants.DefaultCondaEnvironmentYmlFileTemplateName; pythonVersion = detectorResult.PlatformVersion; } scriptProperties.EnvironmentTemplateFileName = templateName; scriptProperties.EnvironmentTemplatePythonVersion = pythonVersion; scriptProperties.NoteBookBuildCommandsFileName = condaBuildCommandsFile; } _logger.LogInformation($"script properties of conda buildcommandfilename: {scriptProperties.NoteBookBuildCommandsFileName}"); _logger.LogInformation($"script properties of conda templatename: {scriptProperties.EnvironmentTemplateFileName}"); var script = TemplateHelper.Render( TemplateHelper.TemplateResource.PythonJupyterNotebookSnippet, scriptProperties, _logger); return(new BuildScriptSnippet { BashBuildScriptSnippet = script, BuildProperties = manifestFileProperties, }); }