def remove_libtool_archives(self): """Remove all .la files in prefix sub-folders if the package sets ``install_libtool_archives`` to be False. """ # If .la files are to be installed there's nothing to do if self.install_libtool_archives: return # Remove the files and create a log of what was removed libtool_files = fs.find(str(self.prefix), '*.la', recursive=True) with fs.safe_remove(*libtool_files): fs.mkdirp(os.path.dirname(self._removed_la_files_log)) with open(self._removed_la_files_log, mode='w') as f: f.write('\n'.join(libtool_files))
def test_content_of_files_with_same_name(tmpdir): # Create two subdirectories containing a file with the same name, # differentiate the files by their content file1 = tmpdir.ensure('myenv1/spack.lock') file2 = tmpdir.ensure('myenv2/spack.lock') file1.write('file1'), file2.write('file2') # Use 'safe_remove' to remove the two files with pytest.raises(RuntimeError): with fs.safe_remove(str(file1), str(file2)): raise RuntimeError('Mock a failure') # Check both files have been restored correctly # and have not been mixed assert file1.read().strip() == 'file1' assert file2.read().strip() == 'file2'