Hallo
As @Villeroy said before, Libreoffice »see« only code proper wrapped into function-definitions:
from pathlib import Path
def test(*_):
doc_folder = Path.home() / "Documents"
source_path = doc_folder / "current_sheet.ods"
target_path = doc_folder / "Tool_Test.ods"
source_uri = source_path.as_uri()
target_uri = target_path.as_uri()
desktop = XSCRIPTCONTEXT.getDesktop()
source_doc = desktop.loadComponentFromURL(source_uri, "_blank", 0, (),)
target_doc = desktop.loadComponentFromURL(target_uri, "_blank", 0, (),)
source_sheet = source_doc.Sheets[0]
target_sheet = target_doc.Sheets[0]
target_sheet["A1"].Value = source_sheet["A1"].Value
for row_index in range(1, 9):
target_sheet[row_index, 1].Value = source_sheet[row_index, 1].Value