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

Allow relative paths in FCPath #40

Merged
merged 16 commits into from
Jan 7, 2025
Merged

Allow relative paths in FCPath #40

merged 16 commits into from
Jan 7, 2025

Conversation

rfrenchseti
Copy link
Collaborator

@rfrenchseti rfrenchseti commented Jan 6, 2025

Fixed Issues

Summary of Changes

  • When the operations "retrieve", "exists", "get_local_path", "upload", and "unlink" are performed on an FCPath, allow the use of relative paths which are converted to absolute paths using expanduser().resolve().

Known Problems

  • None

Summary by Bito

This PR enhances FCPath by implementing relative path support and simplifying path handling logic. It introduces as_absolute() and _make_paths_absolute() methods for automatic conversion of relative paths to absolute using expanduser() and resolve(). The changes include debug printing capabilities for path splitting operations and consolidate code paths for different path types. A comprehensive test suite validates file operations including retrieve, exists, get_local_path, upload, and unlink functionalities.

Unit tests added: True

Estimated effort to review (1-5, lower is better): 3

@pds-admin
Copy link
Collaborator

pds-admin commented Jan 6, 2025

Code Review Agent Run #87dbbf

Actionable Suggestions - 3
  • filecache/file_cache_path.py - 3
Review Details
  • Files reviewed - 3 · Commit Range: 64be6e6..64be6e6
    • filecache/file_cache_path.py
    • tests/test_file_cache.py
    • tests/test_file_cache_path.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

AI Code Review powered by Bito Logo

@pds-admin
Copy link
Collaborator

pds-admin commented Jan 6, 2025

Changelist by Bito

This pull request implements the following key changes.

Key Change Files Impacted
Feature Improvement - Enhanced Path Handling in FCPath

file_cache_path.py - Added relative path support and simplified path handling logic with new as_absolute() and _make_paths_absolute() methods

test_file_cache.py - Removed redundant relative path error test cases

test_file_cache_path.py - Added comprehensive test coverage for relative path handling functionality

if not FCPath._is_absolute(str(new_sub_path2)):
raise ValueError(
f'Derived path must be absolute, got {new_sub_path2}')
new_sub_path = self._make_paths_absolute(sub_path)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider validating optional sub_path parameter

Consider validating sub_path before calling _make_paths_absolute() to ensure it's not None. While the type hint suggests Optional[StrOrPathOrSeqType], there's no explicit check.

Code suggestion
Check the AI-generated fix before applying
Suggested change
new_sub_path = self._make_paths_absolute(sub_path)
if sub_path is None:
sub_path = ''
new_sub_path = self._make_paths_absolute(sub_path)

Code Review Run #87dbbf


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

Comment on lines 630 to 633
if not FCPath._is_absolute(new_sub_path):
new_sub_path = (FCPath(Path(new_sub_path).expanduser().resolve())
.as_posix())
new_sub_paths.append(new_sub_path)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding path validation checks

Consider adding validation for the resolved absolute path to ensure it stays within allowed directories for security. The current implementation could potentially allow access to sensitive files outside intended directories.

Code suggestion
Check the AI-generated fix before applying
Suggested change
if not FCPath._is_absolute(new_sub_path):
new_sub_path = (FCPath(Path(new_sub_path).expanduser().resolve())
.as_posix())
new_sub_paths.append(new_sub_path)
if not FCPath._is_absolute(new_sub_path):
new_sub_path = (FCPath(Path(new_sub_path).expanduser().resolve())
.as_posix())
base_dir = Path(self._path).parent.resolve()
resolved_path = Path(new_sub_path).resolve()
if not str(resolved_path).startswith(str(base_dir)):
raise ValueError(f'Path {new_sub_path} resolves outside allowed directory {base_dir}')
new_sub_paths.append(new_sub_path)

Code Review Run #87dbbf


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

Comment on lines +1099 to +1105
return self._filecache_to_use.unlink(cast(StrOrPathOrSeqType,
new_sub_path),
missing_ok=missing_ok,
anonymous=self._anonymous,
nthreads=nthreads,
exception_on_fail=exception_on_fail,
url_to_path=url_to_path)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider consolidating duplicate unlink parameters

Consider consolidating the duplicate unlink call parameters into a dictionary to reduce code duplication and improve maintainability. The same parameter list appears in both branches of the if statement.

Code suggestion
Check the AI-generated fix before applying
 @@ -1088,21 +1088,19 @@
          new_sub_path = self._make_paths_absolute(sub_path)

 +        unlink_params = {
 +            'missing_ok': missing_ok,
 +            'anonymous': self._anonymous,
 +            'nthreads': nthreads,
 +            'exception_on_fail': exception_on_fail,
 +            'url_to_path': url_to_path
 +        }
 +
          if isinstance(new_sub_path, (list, tuple)):
 -            return self._filecache_to_use.unlink(cast(StrOrPathOrSeqType,
 -                                                      new_sub_path),
 -                                                 missing_ok=missing_ok,
 -                                                 anonymous=self._anonymous,
 -                                                 nthreads=nthreads,
 -                                                 exception_on_fail=exception_on_fail,
 -                                                 url_to_path=url_to_path)
 +            return self._filecache_to_use.unlink(cast(StrOrPathOrSeqType, new_sub_path),
 +                                                 **unlink_params)

 -        return self._filecache_to_use.unlink(cast(StrOrPathOrSeqType,
 -                                                  new_sub_path),
 -                                             missing_ok=missing_ok,
 -                                             anonymous=self._anonymous,
 -                                             nthreads=nthreads,
 -                                             exception_on_fail=exception_on_fail,
 -                                             url_to_path=url_to_path)

Code Review Run #87dbbf


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

Copy link

codecov bot commented Jan 6, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.03%. Comparing base (24647ee) to head (d72d8b6).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #40      +/-   ##
==========================================
+ Coverage   92.93%   93.03%   +0.10%     
==========================================
  Files           5        5              
  Lines        1784     1767      -17     
  Branches      370      359      -11     
==========================================
- Hits         1658     1644      -14     
+ Misses         75       70       -5     
- Partials       51       53       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@pds-admin
Copy link
Collaborator

pds-admin commented Jan 6, 2025

Code Review Agent Run #a438ce

Actionable Suggestions - 1
  • filecache/file_cache_path.py - 1
Review Details
  • Files reviewed - 2 · Commit Range: 64be6e6..b81dc74
    • filecache/file_cache_path.py
    • tests/test_file_cache.py
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

AI Code Review powered by Bito Logo

Comment on lines +1058 to +1060
nthreads = self._validate_nthreads(nthreads)

new_sub_path = self._make_paths_absolute(sub_path)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider keeping original operation order

Consider keeping the original order of operations where path validation happens before nthreads validation. The current change could affect error handling flow since invalid paths would not be caught before validating thread count.

Code suggestion
Check the AI-generated fix before applying
 @@ -1058,1060 +1058,1060 @@
 -        nthreads = self._validate_nthreads(nthreads)
 -        new_sub_path = self._make_paths_absolute(sub_path)
 +        new_sub_path = self._make_paths_absolute(sub_path)
 +        nthreads = self._validate_nthreads(nthreads)

Code Review Run #a438ce


Is this a valid issue, or was it incorrectly flagged by the Agent?

  • it was incorrectly flagged

@pds-admin
Copy link
Collaborator

pds-admin commented Jan 7, 2025

Code Review Agent Run #7d2767

Actionable Suggestions - 1
  • tests/test_file_cache_path.py - 1
Review Details
  • Files reviewed - 2 · Commit Range: b81dc74..6a5e605
    • filecache/file_cache_path.py
    • tests/test_file_cache_path.py
  • Files skipped - 1
    • .github/workflows/run-tests.yml - Reason: Filter setting
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • MyPy (Static Code Analysis) - ✔︎ Successful
    • Astral Ruff (Static Code Analysis) - ✔︎ Successful

AI Code Review powered by Bito Logo

@rfrenchseti rfrenchseti merged commit a2320f5 into main Jan 7, 2025
18 checks passed
@rfrenchseti rfrenchseti deleted the rf_250106_pdstemplate branch January 7, 2025 02:57
@pds-admin
Copy link
Collaborator

pds-admin commented Jan 7, 2025

Code Review Agent Run Status

  • Limitations and other issues: ❌ Failure - Bito Code Review Agent couldn't review this pull request because it is no longer valid. It may have been merged, or the source/target branch may not exist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable support for local file paths that are not absolute
2 participants