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

feat: ✨ add path_readme() #1100

Merged
merged 3 commits into from
Mar 4, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
8 changes: 5 additions & 3 deletions src/seedcase_sprout/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
path_package,
path_packages,
path_properties,
path_readme,
)
from .path_resource_functions import (
path_resource,
Expand Down Expand Up @@ -88,9 +89,10 @@
# "delete_resource_data",
# "delete_resource_properties",
# Path -----
"path_package",
"path_properties",
"path_packages",
path_package,
path_packages,
path_properties,
path_readme,
"path_resource",
"path_resource_data",
"path_resource_raw",
Expand Down
35 changes: 35 additions & 0 deletions src/seedcase_sprout/core/path_package_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,38 @@ def path_packages() -> Path:
"""
path = path_sprout_global() / "packages"
return create_dir(path) if not path.exists() else check_is_dir(path)


def path_readme(package_id: int) -> Path:
"""Get the path to the README file for the specified package.

Args:
package_id: The ID of the package.

Returns:
The absolute path to the README file.

Examples:
```{python}
import os
import tempfile

import seedcase_sprout.core as sp

# Create a temporary directory for the example
with tempfile.TemporaryDirectory() as temp_dir:
os.environ["SPROUT_GLOBAL"] = temp_dir

# Create a package structure first
sp.create_package_properties(
properties=sp.example_package_properties(),
path=sp.path_packages()
)

# TODO: Need to modify after revising to "local-first"
# Get the path to the package README
# sp.path_readme(package_id=1)
```
"""
path = path_package(package_id=package_id) / "README.md"
return check_is_file(path)
1 change: 1 addition & 0 deletions tests/core/directory_structure_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def create_test_package_structure(global_path: Path, package_id: int) -> Path:
path_package = global_path / "packages" / str(package_id)
path_package.mkdir(parents=True)
(path_package / "datapackage.json").touch()
(path_package / "README.md").touch()

return path_package

Expand Down
4 changes: 3 additions & 1 deletion tests/core/test_path_package_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
path_package,
path_packages,
path_properties,
path_readme,
)
from tests.core.directory_structure_setup import (
create_test_package_structure,
Expand All @@ -27,6 +28,7 @@ def tmp_sprout_global(monkeypatch, tmp_path):
[
(path_package, "packages/1"),
(path_properties, "packages/1/datapackage.json"),
(path_readme, "packages/1/README.md"),
],
)
def test_path_package_functions_return_expected_path(
Expand All @@ -39,7 +41,7 @@ def test_path_package_functions_return_expected_path(

@mark.parametrize(
"function",
[path_package, path_properties],
[path_package, path_properties, path_readme],
)
def test_path_package_functions_raise_error_if_package_id_does_not_exist(
tmp_sprout_global, function
Expand Down