Skip to content

Commit

Permalink
fix PATH error flagged by ruff
Browse files Browse the repository at this point in the history
  • Loading branch information
Remi-Gau committed Nov 10, 2024
1 parent 033a1a1 commit 8c19518
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 14 deletions.
10 changes: 7 additions & 3 deletions eye2bids/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ def write(
) -> None:
"""Write to json."""
content = {key: value for key, value in self.items() if self[key] is not None}
with open(output_dir / self.output_filename(recording=recording), "w") as outfile:
with (output_dir / self.output_filename(recording=recording)).open(
"w"
) as outfile:
json.dump(content, outfile, indent=4)


Expand Down Expand Up @@ -110,7 +112,7 @@ def write(
self[key] = value

content = {key: value for key, value in self.items() if self[key] is not None}
with open(output_dir / self.output_filename(), "w") as outfile:
with (output_dir / self.output_filename()).open("w") as outfile:
json.dump(content, outfile, indent=4)


Expand Down Expand Up @@ -196,5 +198,7 @@ def write(
self[key] = value

content = {key: value for key, value in self.items() if self[key] is not None}
with open(output_dir / self.output_filename(recording=recording), "w") as outfile:
with (output_dir / self.output_filename(recording=recording)).open(
"w"
) as outfile:
json.dump(content, outfile, indent=4)
6 changes: 3 additions & 3 deletions eye2bids/edf2bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def _extract_StopTime(events: list[str]) -> int:


def _load_asc_file(events_asc_file: str | Path) -> list[str]:
with open(events_asc_file) as f:
with Path(events_asc_file).open() as f:
return f.readlines()


Expand Down Expand Up @@ -424,7 +424,7 @@ def generate_physio_json(
if metadata_file is None:
metadata = {}
else:
with open(metadata_file) as f:
with Path(metadata_file).open() as f:
metadata = yaml.load(f, Loader=SafeLoader)

events = _load_asc_file(events_asc_file)
Expand Down Expand Up @@ -543,7 +543,7 @@ def edf2bids(
if metadata_file is None:
metadata = {}
else:
with open(metadata_file) as f:
with metadata_file.open() as f:
metadata = yaml.load(f, Loader=SafeLoader)

events_json = BaseEventsJson(metadata)
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ skip-magic-trailing-comma = false
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
fixable = ["ALL"]
ignore = [
"PTH123",
"PD901",
"N802",
"D205",
Expand Down
12 changes: 6 additions & 6 deletions tests/test_edf2bids.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def _check_output_content(output_dir, input_file, eye=1):
).with_suffix(".json")

df = pd.read_csv(tsv_file, sep="\t", header=None)
with open(json_file) as f:
with json_file.open() as f:
metadata = json.load(f)
assert len(df.columns) == len(metadata["Columns"])

Expand Down Expand Up @@ -141,12 +141,12 @@ def test_edf_end_to_end(eyelink_test_data_dir):
_check_output_exists(output_dir, input_file)

expected_events_sidecar = output_dir / f"{input_file.stem}_events.json"
with open(expected_events_sidecar) as f:
with expected_events_sidecar.open() as f:
events = json.load(f)
assert events["StimulusPresentation"]["ScreenResolution"] == [1919, 1079]

expected_data_sidecar = output_dir / f"{input_file.stem}_recording-eye1_physio.json"
with open(expected_data_sidecar) as f:
with expected_data_sidecar.open() as f:
eyetrack = json.load(f)
assert eyetrack["SamplingFrequency"] == 500
assert eyetrack["RecordedEye"] == "Right"
Expand Down Expand Up @@ -189,14 +189,14 @@ def test_edf_end_to_end_2eyes(eyelink_test_data_dir):
_check_output_content(output_dir, input_file)

expected_events_sidecar_eye1 = output_dir / f"{input_file.stem}_events.json"
with open(expected_events_sidecar_eye1) as f:
with expected_events_sidecar_eye1.open() as f:
events = json.load(f)
assert events["StimulusPresentation"]["ScreenResolution"] == [1919, 1079]

expected_data_sidecar_eye1 = (
output_dir / f"{input_file.stem}_recording-eye1_physio.json"
)
with open(expected_data_sidecar_eye1) as f:
with expected_data_sidecar_eye1.open() as f:
eyetrack = json.load(f)
assert eyetrack["SamplingFrequency"] == 1000
assert eyetrack["AverageCalibrationError"] == [[0.29]]
Expand All @@ -208,7 +208,7 @@ def test_edf_end_to_end_2eyes(eyelink_test_data_dir):
expected_data_sidecar_eye2 = (
output_dir / f"{input_file.stem}_recording-eye2_physio.json"
)
with open(expected_data_sidecar_eye2) as f:
with expected_data_sidecar_eye2.open() as f:
eyetrack = json.load(f)
assert eyetrack["AverageCalibrationError"] == [[0.35]]
assert eyetrack["RecordedEye"] == "Right"
Expand Down
2 changes: 1 addition & 1 deletion tools/download_test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

# Download the zip file
r = requests.get(download_url, stream=True)
with open(output_file, "wb") as f:
with output_file.open("wb") as f:
for chunk in r.iter_content(chunk_size=1024):
if chunk:
f.write(chunk)
Expand Down

0 comments on commit 8c19518

Please sign in to comment.