22import shutil
33from itertools import chain
44from pathlib import Path
5+ from urllib .parse import urlparse
56
67from pandas .io .common import get_handle , is_url
78
@@ -76,7 +77,7 @@ def petab1to2(yaml_config: Path | str, output_dir: Path | str = None):
7677 # condition tables, observable tables, SBML files, parameter table:
7778 # no changes - just copy
7879 file = yaml_config [C .PARAMETER_FILE ]
79- _copy_file (get_src_path (file ), get_dest_path (file ))
80+ _copy_file (get_src_path (file ), Path ( get_dest_path (file ) ))
8081
8182 for problem_config in yaml_config [C .PROBLEMS ]:
8283 for file in chain (
@@ -89,7 +90,7 @@ def petab1to2(yaml_config: Path | str, output_dir: Path | str = None):
8990 problem_config .get (C .MEASUREMENT_FILES , []),
9091 problem_config .get (C .VISUALIZATION_FILES , []),
9192 ):
92- _copy_file (get_src_path (file ), get_dest_path (file ))
93+ _copy_file (get_src_path (file ), Path ( get_dest_path (file ) ))
9394
9495 # TODO: Measurements: preequilibration to experiments/timecourses once
9596 # finalized
@@ -131,18 +132,23 @@ def _update_yaml(yaml_config: dict) -> dict:
131132 return yaml_config
132133
133134
134- def _copy_file (src : Path | str , dest : Path | str ):
135+ def _copy_file (src : Path | str , dest : Path ):
135136 """Copy file."""
136- src = str (src )
137- dest = str (dest )
138-
139- if src == dest :
140- return
137+ # src might be a URL - convert to Path if local
138+ src_url = urlparse (src )
139+ if not src_url .scheme :
140+ src = Path (src )
141+ elif src_url .scheme == "file" and not src_url .netloc :
142+ src = Path (src .removeprefix ("file:/" ))
141143
142144 if is_url (src ):
143145 with get_handle (src , mode = "r" ) as src_handle :
144146 with open (dest , "w" ) as dest_handle :
145147 dest_handle .write (src_handle .handle .read ())
146148 return
147149
148- shutil .copy (str (src ), str (dest ))
150+ try :
151+ if src .samefile (dest ):
152+ return
153+ except FileNotFoundError :
154+ shutil .copy (str (src ), str (dest ))
0 commit comments