Skip to content

Commit 178b418

Browse files
committed
FIX: Fix regression with path.get_filename for .SAFE and .SEN3 directories
1 parent 2d0e124 commit 178b418

3 files changed

Lines changed: 42 additions & 9 deletions

File tree

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Release History
22

3+
## 1.54.1 (2026-06-02)
4+
5+
- FIX: Fix regression with `path.get_filename` for .SAFE and .SEN3 directories
6+
37
## 1.54.0 (2026-06-01)
48

59
- **ENH: Filter directory extensions (if wanted) in `path.get_ext` with `curate_dir_extensions` keyword**

ci/test_path.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,19 +159,37 @@ def test_get_file_name():
159159
ci.assert_val(file_name, "test_path", "__file__ + /")
160160

161161
# random
162-
file = r"/test/vector.gpkg"
162+
file = "/test/vector.gpkg"
163163
ci.assert_val("vector", path.get_filename(file), "gpkg name")
164164
ci.assert_val(".gpkg", path.get_ext(file, start_with_point=True), "gpkg extension")
165165

166-
# SAFE
167-
fn = r"/test/S2A_MSIL1C_20200824T110631_N0209_R137_T30TTK_20200824T150432.SAFE"
166+
# SAFE (existing)
167+
fn = (
168+
files_path()
169+
/ "S2A_MSIL1C_20200824T110631_N0209_R137_T30TTK_20200824T150432.SAFE"
170+
)
171+
ci.assert_val(
172+
path.get_filename(fn),
173+
"S2A_MSIL1C_20200824T110631_N0209_R137_T30TTK_20200824T150432",
174+
"SAFE filename (existing)",
175+
)
176+
ci.assert_val(
177+
path.get_ext(fn, start_with_point=True),
178+
".SAFE",
179+
"SAFE dir extension (existing)",
180+
)
181+
182+
# SAFE (non-existing)
183+
fn = "/test/S2A_MSIL1C_20200824T110631_N0209_R137_T30TTK_20200824T150432.SAFE"
168184
ci.assert_val(
169185
path.get_filename(fn),
170186
"S2A_MSIL1C_20200824T110631_N0209_R137_T30TTK_20200824T150432",
171-
"SAFE filename",
187+
"SAFE filename (non-existing)",
172188
)
173189
ci.assert_val(
174-
path.get_ext(fn, start_with_point=True), ".SAFE", "SAFE dir extension"
190+
path.get_ext(fn, start_with_point=True),
191+
".SAFE",
192+
"SAFE dir extension (non-existing)",
175193
)
176194

177195
# tar gz

sertit/path.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131

3232
LOGGER = logging.getLogger(SU_NAME)
3333

34+
REMOVED_DIR_EXTS = [".SAFE", ".SEN3", ".data"]
35+
3436

3537
def get_root_path() -> AnyPathType:
3638
"""
@@ -376,8 +378,18 @@ def get_filename(file_path: AnyPathStrType, other_exts: list | str = None) -> st
376378
if any([str(file_path).endswith(ext) for ext in multi_exts]):
377379
filename = file_path.name.split(".")[0]
378380
else:
379-
# Manage correctly the cases like HLS.L30.T42RVR.2022240T055634.v2.0 folders or HLS.L30.T42RVR.2022240T055634.v2.0.B01.tif files...
380-
filename = file_path.name if file_path.is_dir() else file_path.stem
381+
if file_path.is_dir():
382+
# Manage correctly the cases like HLS.L30.T42RVR.2022240T055634.v2.0 folders (keep the last .0)
383+
filename = file_path.name
384+
385+
# Remove SAFE, SEN, etc in case of existing dir
386+
for ext in REMOVED_DIR_EXTS:
387+
if ext in filename:
388+
filename = filename.replace(ext, "")
389+
390+
else:
391+
# Manage correctly the cases like HLS.L30.T42RVR.2022240T055634.v2.0.B01.tif files...
392+
filename = file_path.stem
381393

382394
# get_archived_rio_path returns zip+file://{zip_path}!{file_name}
383395
if ".zip!" in filename:
@@ -449,8 +461,7 @@ def get_ext(
449461
# Curate directory extensions.
450462
# WARNING: using is_dir() makes it work only if the directory is existing.
451463
if file_path.is_dir() and curate_dir_extensions:
452-
curated_dir_exts = [".SAFE", ".SEN3", ".data"]
453-
ext = ending_ext if ending_ext in curated_dir_exts else ""
464+
ext = ending_ext if ending_ext in REMOVED_DIR_EXTS else ""
454465

455466
# Legacy reasons
456467
if not start_with_point:

0 commit comments

Comments
 (0)