Skip to content

Commit

Permalink
Merge pull request #22 from NHFLO/actions
Browse files Browse the repository at this point in the history
move get_latest_data_paths
  • Loading branch information
bdestombe authored Dec 4, 2024
2 parents 9c5e573 + ee6a658 commit 254a521
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 22 deletions.
22 changes: 22 additions & 0 deletions src/nhflodata/get_paths.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"""Functions to get paths to data sets."""
from __future__ import annotations

import logging
import os
import re
from pathlib import Path

import yaml
from yaml.loader import SafeLoader
Expand Down Expand Up @@ -110,6 +112,26 @@ def get_data_dir():
return os.path.join(os.path.dirname(__file__), "data")


def get_latest_data_paths() -> list[Path]:
"""
Get paths to all latest data versions in the repository.
Returns
-------
List[Path]
List of Path objects representing all found directories
Examples
--------
>>> folders = get_latest_data_paths()
>>> print(folders[0])
./data/subfolder1/v1.2.3
"""
dataset_names = sorted(get_repository_data().keys())
dataset_paths = [get_abs_data_path(name, version="latest", location="mockup") for name in dataset_names]
return [Path(path) for path in dataset_paths]


def get_repository_path():
"""Return the path to the repository.yaml file from data/repository.yaml."""
# from importlib.resources import files
Expand Down
24 changes: 2 additions & 22 deletions tests/test_forbidden_file_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,7 @@

import pytest

from nhflodata.get_paths import get_abs_data_path, get_repository_data


def get_latest_data_paths() -> list[Path]:
"""
Get paths to all latest data versions in the repository.
Returns
-------
List[Path]
List of Path objects representing all found directories
Examples
--------
>>> folders = get_latest_data_paths()
>>> print(folders[0])
./data/subfolder1/v1.2.3
"""
dataset_names = sorted(get_repository_data().keys())
dataset_paths = [get_abs_data_path(name, version="latest", location="mockup") for name in dataset_names]
return [Path(path) for path in dataset_paths]
from nhflodata.get_paths import get_latest_data_paths


def find_files_by_extension(folder: Path, extensions: set[str]) -> list[Path]:
Expand Down Expand Up @@ -62,7 +42,7 @@ def find_files_by_extension(folder: Path, extensions: set[str]) -> list[Path]:
normalized_extensions = {(ext if ext.startswith(".") else f".{ext}").lower() for ext in extensions}

# Get all files in the folder and its subfolders
all_files = folder.glob("**/*")
all_files = Path(folder).glob("**/*")

# Check each file's extension case-insensitively
for file_path in all_files:
Expand Down

0 comments on commit 254a521

Please sign in to comment.