Skip to content

Commit b9fc128

Browse files
committed
resolve paths
1 parent 6b9bff5 commit b9fc128

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

petab/v2/petab1to2.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import shutil
33
from itertools import chain
44
from pathlib import Path
5+
from urllib.parse import urlparse
56

67
from 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 dest.samefile(src):
152+
return
153+
except FileNotFoundError:
154+
shutil.copy(str(src), str(dest))

petab/v2/problem.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -896,10 +896,11 @@ def add_measurement(
896896
record[PREEQUILIBRATION_CONDITION_ID] = [preeq_cond_id]
897897

898898
tmp_df = pd.DataFrame(record)
899-
if self.measurement_df is None:
900-
self.measurement_df = tmp_df
901-
else:
902-
self.measurement_df = pd.concat([self.measurement_df, tmp_df])
899+
self.measurement_df = (
900+
pd.concat([self.measurement_df, tmp_df])
901+
if self.measurement_df is not None
902+
else tmp_df
903+
)
903904

904905
def add_mapping(self, petab_id: str, model_id: str):
905906
"""Add a mapping table entry to the problem.

0 commit comments

Comments
 (0)