public void GeneratedScript_DoesNotUseVenv() { // Arrange var scriptGenerator = CreatePlatform(); var repo = new MemorySourceRepo(); repo.AddFile("", PythonConstants.RequirementsFileName); repo.AddFile("print(1)", "bla.py"); var context = new BuildScriptGeneratorContext { SourceRepo = repo }; var detectorResult = new PythonPlatformDetectorResult { Platform = PythonConstants.PlatformName, PlatformVersion = "3.7.5", }; // Act var snippet = scriptGenerator.GenerateBashBuildScriptSnippet(context, detectorResult); // Assert Assert.NotNull(snippet); Assert.Contains("Python Virtual Environment", snippet.BashBuildScriptSnippet); Assert.True(scriptGenerator.IsCleanRepo(repo)); }
private bool IsCondaEnvironment(PythonPlatformDetectorResult pythonPlatformDetectorResult) { if (pythonPlatformDetectorResult.HasCondaEnvironmentYmlFile && IsCondaInstalledInImage()) { return(true); } return(false); }
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, }); }
public void GeneratedSnippet_HaveInstallScript_IfCustomRequirementsTxtPathSpecified() { // Arrange var pythonScriptGeneratorOptions = new PythonScriptGeneratorOptions() { CustomRequirementsTxtPath = "foo/requirements.txt" }; var commonOptions = new BuildScriptGeneratorOptions() { EnableDynamicInstall = true, CustomRequirementsTxtPath = "foo/requirements.txt" }; var installerScriptSnippet = "##INSTALLER_SCRIPT##"; var versionProvider = new TestPythonVersionProvider(new[] { "3.7.5", "3.8.0" }, defaultVersion: "3.7.5"); var platformInstaller = new TestPythonPlatformInstaller( isVersionAlreadyInstalled: false, installerScript: installerScriptSnippet, Options.Create(commonOptions), NullLoggerFactory.Instance); var platform = CreatePlatform( versionProvider, platformInstaller, commonOptions, pythonScriptGeneratorOptions); var repo = new MemorySourceRepo(); repo.AddFile("", "foo/requirements.txt"); repo.AddFile("print(1)", "bla.py"); var context = new BuildScriptGeneratorContext { SourceRepo = repo }; var detectorResult = new PythonPlatformDetectorResult { Platform = PythonConstants.PlatformName, PlatformVersion = "3.7.5", HasRequirementsTxtFile = true, }; // Act var snippet = platform.GetInstallerScriptSnippet(context, detectorResult); // Assert Assert.NotNull(snippet); }
private static PlatformDetectorResult GetPlatformDetectorResult(string name, string version) { var result = new PlatformDetectorResult(); switch (name) { case DotNetCoreConstants.PlatformName: result = new DotNetCorePlatformDetectorResult(); break; case NodeConstants.PlatformName: result = new NodePlatformDetectorResult(); break; case PythonConstants.PlatformName: result = new PythonPlatformDetectorResult(); break; case HugoConstants.PlatformName: result = new PlatformDetectorResult(); break; case PhpConstants.PlatformName: result = new PhpPlatformDetectorResult(); break; case JavaConstants.PlatformName: result = new JavaPlatformDetectorResult(); break; case RubyConstants.PlatformName: result = new RubyPlatformDetectorResult(); break; } result.Platform = name; result.PlatformVersion = version; return(result); }
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, }); }