def start(self): # validate parameters, ensure values are present self._validate_parameters() # create staging dir self.staging_dir = spec_utils.create_staging_directory() # copy files from installed area to staging dir self.source_dir = os.path.abspath( os.path.join(os.path.dirname(__file__), 'kernelspecs', self.template_dir)) dir_util.copy_tree(src=self.source_dir, dst=self.staging_dir) spec_utils.copy_kernelspec_files(self.staging_dir, launcher_type=self.language, resource_type=self.language) # install to destination self.log.info( "Installing Yarn Kernel Provider kernel specification for '{}'". format(self.display_name)) install_dir = self.kernel_spec_manager.install_kernel_spec( self.staging_dir, kernel_name=self.kernel_name, user=self.user, prefix=self.prefix) # apply template values at destination (since one of the values is the destination directory) self._finalize_kernel_json(install_dir)
def test_copy_r_launcher(tmpdir): kernel_name = 'r_kernel' staging_dir = spec_utils.create_staging_directory(parent_dir=tmpdir.dirname) spec_dir = path.join(staging_dir, kernel_name) spec_utils.copy_kernelspec_files(spec_dir, launcher_type='r') assert path.isdir(spec_dir) resource_file = path.join(spec_dir, 'kernel.js') assert path.isfile(resource_file) resource_file = path.join(spec_dir, 'logo-64x64.png') assert path.isfile(resource_file) scripts_dir = path.join(spec_dir, 'scripts') assert path.isdir(scripts_dir) launcher_file = path.join(spec_dir, 'scripts', 'launch_IRkernel.R') assert path.isfile(launcher_file) gateway_file = path.join(spec_dir, 'scripts', 'gateway_listener.py') assert path.isfile(gateway_file) spec_utils.delete_staging_directory(staging_dir) assert not path.exists(gateway_file) assert not path.exists(launcher_file) assert not path.exists(scripts_dir) assert not path.exists(resource_file) assert not path.exists(spec_dir)
def test_copy_scala_launcher(tmpdir): kernel_name = 'scala_kernel' staging_dir = spec_utils.create_staging_directory(parent_dir=tmpdir.dirname) spec_dir = path.join(staging_dir, kernel_name) spec_utils.copy_kernelspec_files(spec_dir, launcher_type='scala') assert path.isdir(spec_dir) lib_dir = path.join(spec_dir, 'lib') assert path.isdir(lib_dir) launcher_file = path.join(spec_dir, 'lib', 'toree-launcher_*') matches = glob.glob(launcher_file) assert len(matches) == 1 launcher_file = matches[0] assert path.isfile(launcher_file) toree_jar = path.join(spec_dir, 'lib', 'toree-assembly-*') matches = glob.glob(toree_jar) assert len(matches) == 1 toree_jar = matches[0] assert path.isfile(toree_jar) spec_utils.delete_staging_directory(staging_dir) assert not path.exists(toree_jar) assert not path.exists(launcher_file) assert not path.exists(lib_dir) assert not path.exists(spec_dir)
def test_invalid_parameters(create_temp_dir): kernel_name = 'invalid' staging_dir = spec_utils.create_staging_directory(parent_dir=temp_dir) spec_dir = path.join(staging_dir, kernel_name) # use a bogus launch-type... with pytest.raises(ValueError) as ve: assert spec_utils.copy_kernelspec_files(spec_dir, launcher_type='bogus-type') assert str(ve.value).startswith("Invalid launcher_type 'bogus-type'") # and a bogus resource-type... with pytest.raises(ValueError) as ve: assert spec_utils.copy_kernelspec_files(spec_dir, launcher_type='python', resource_type='bogus-type') assert str(ve.value).startswith("Invalid resource_type 'bogus-type'") # and no launcher or resource types specified... with pytest.raises(ValueError) as ve: assert spec_utils.copy_kernelspec_files(spec_dir) assert str(ve.value).startswith( "Invalid parameters. At least one of 'launcher_type' or 'resource_type' must" ) spec_utils.delete_staging_directory(staging_dir) assert not path.exists(staging_dir)
def test_copy_python_launcher(tmpdir): kernel_name = 'python_kernel' staging_dir = spec_utils.create_staging_directory(parent_dir=tmpdir.dirname) spec_dir = path.join(staging_dir, kernel_name) spec_utils.copy_kernelspec_files(spec_dir, launcher_type='python') assert path.isdir(spec_dir) scripts_dir = path.join(spec_dir, 'scripts') assert path.isdir(scripts_dir) launcher_file = path.join(spec_dir, 'scripts', 'launch_ipykernel.py') assert path.isfile(launcher_file) spec_utils.delete_staging_directory(staging_dir) assert not path.exists(launcher_file) assert not path.exists(scripts_dir) assert not path.exists(spec_dir)
def test_copy_only_resource(tmpdir): kernel_name = 'resource-only' staging_dir = spec_utils.create_staging_directory(parent_dir=tmpdir.dirname) spec_dir = path.join(staging_dir, kernel_name) spec_utils.copy_kernelspec_files(spec_dir, launcher_type=None, resource_type='r') assert path.isdir(spec_dir) resource_file = path.join(spec_dir, 'kernel.js') assert path.isfile(resource_file) resource_file = path.join(spec_dir, 'logo-64x64.png') assert path.isfile(resource_file) scripts_dir = path.join(spec_dir, 'scripts') assert not path.exists(scripts_dir) spec_utils.delete_staging_directory(staging_dir) assert not path.exists(resource_file) assert not path.exists(spec_dir)