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

Clarify that reason is not yet implemented #59

Merged
merged 1 commit into from
Mar 23, 2023
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
8 changes: 2 additions & 6 deletions src/pyprojroot/criterion.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""
"""Set and use criteria to find the project root.

This module is inspired by the `rprojroot` library for R.
See https://github.com/r-lib/rprojroot.

Expand All @@ -20,11 +21,6 @@
Iterable[Callable[[Path], bool]],
]

# TODO: It would be nice to have a class that encapsulates these checks,
# so that we can implement methods like |, !, &, ^ operators

# TODO: Refactor in a way that allows creation of reasons


def as_root_criterion(
criterion: _CriterionType,
Expand Down
9 changes: 6 additions & 3 deletions src/pyprojroot/here.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""
"""Convenience to find the path for a file or directory relative to the root.

This module is inspired by the `here` library for R.
See https://github.com/r-lib/here.

Expand Down Expand Up @@ -28,7 +29,7 @@


def get_here() -> Tuple[Path, str]:
# TODO: This should only find_root once per session
"""Return a tuple with the root path and a reason"""
start = Path.cwd()
path, reason = find_root_with_reason(CRITERIA, start=start)
return path, reason
Expand All @@ -42,12 +43,14 @@ def here(
) -> Path:
"""
Returns the path relative to the projects root directory.

:param relative_project_path: relative path from project root
:param warn_missing: warn user if path does not exist (default=False)
:return: pathlib path

Note: `reason` is not yet implemented.
"""
path, reason = get_here()
# TODO: Show reason when requested

if relative_project_path:
path = path / relative_project_path
Expand Down
8 changes: 4 additions & 4 deletions src/pyprojroot/root.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
See https://github.com/r-lib/rprojroot.

It is intended for interactive or programmatic only.

NOTE: `reason` is not fully implemented.
"""

from pathlib import Path
Expand Down Expand Up @@ -33,8 +35,9 @@ def find_root_with_reason(

Recursively search parents of start path for directory
matching root criterion with reason.

NOTE: `reason` is not fully implemented.
"""
# TODO: Implement reasons

# Prepare inputs
criterion = _as_root_criterion(criterion)
Expand All @@ -45,13 +48,10 @@ def find_root_with_reason(
return start, "Pass"

# Iterate over all parents
# TODO: Consider adding maximum depth
# TODO: Consider limiting depth to path (e.g. "if p == stop: raise")
for p in start.parents:
if criterion(p):
return p, "Pass"

# Not found
raise RuntimeError("Project root not found.")


Expand Down