Skip to content

Commit

Permalink
Path sanitization hotfix (#107)
Browse files Browse the repository at this point in the history
* Hotfix

* Update dep versions

* Fix and try to optimize some tests
  • Loading branch information
talmo authored Aug 2, 2024
1 parent 5b79a22 commit e002927
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 17 deletions.
10 changes: 5 additions & 5 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ channels:

dependencies:
- python
- ffmpeg<6.1.0
- ffmpeg
- imageio
- imageio-ffmpeg
- imageio-ffmpeg >=0.5.0
- av
- attrs
- pandas
- simplejson
- h5py>=3.8.0
- h5py >=3.8.0
- hdmf
- numpy
- opencv<4.9.0
- numpy <2.0.0
- opencv
- pynwb
- ndx-pose
- pytest
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dependencies = [
"pandas",
"simplejson",
"imageio",
"imageio-ffmpeg",
"imageio-ffmpeg>=0.5.0",
"av"]
dynamic = ["version", "readme"]

Expand Down
24 changes: 14 additions & 10 deletions sleap_io/io/slp.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,20 @@ def make_video(
is_embedded = True

# Basic path resolution.
video_path = Path(video_path)
if not video_path.exists():
# Check for the same filename in the same directory as the labels file.
video_path_ = Path(labels_path).parent / video_path.name
if video_path_.exists():
video_path = video_path_
else:
# TODO (TP): Expand capabilities of path resolution to support more
# complex path finding strategies.
pass
video_path = Path(Path(video_path).as_posix().replace("\\", "/"))

try:
if not video_path.exists():
# Check for the same filename in the same directory as the labels file.
video_path_ = Path(labels_path).parent / video_path.name
if video_path_.exists():
video_path = video_path_
else:
# TODO (TP): Expand capabilities of path resolution to support more
# complex path finding strategies.
pass
except OSError:
pass

# Convert video path to string.
video_path = video_path.as_posix()
Expand Down
2 changes: 1 addition & 1 deletion sleap_io/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

# Define package version.
# This is read dynamically by setuptools in pyproject.toml to determine the release version.
__version__ = "0.1.6"
__version__ = "0.1.7"
3 changes: 3 additions & 0 deletions tests/io/test_nwb.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ def test_default_metadata_overwriting(nwbfile, slp_predictions_with_provenance):

def test_complex_case_append(nwbfile, centered_pair):
labels = load_slp(centered_pair)
labels.clean(tracks=True)
nwbfile = append_nwb_data(labels, nwbfile)

# Test matching number of processing modules
Expand Down Expand Up @@ -169,6 +170,7 @@ def test_complex_case_append(nwbfile, centered_pair):

def test_complex_case_append_with_timestamps_metadata(nwbfile, centered_pair):
labels = load_slp(centered_pair)
labels.clean(tracks=True)

number_of_frames = 1100 # extracted using ffmpeg probe
video_sample_rate = 15.0 # 15 Hz extracted using ffmpeg probe for the video stream
Expand Down Expand Up @@ -238,6 +240,7 @@ def test_typical_case_write(slp_typical, tmp_path):

def test_get_timestamps(nwbfile, centered_pair):
labels = load_slp(centered_pair)
labels.clean(tracks=True)
nwbfile = append_nwb_data(labels, nwbfile)
processing = nwbfile.processing["SLEAP_VIDEO_000_centered_pair_low_quality"]
assert True
Expand Down

0 comments on commit e002927

Please sign in to comment.