Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move get_latest_data_paths #22

Merged
merged 6 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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