Skip to content

feat: path functions is_abs and abs_path#1027

Open
wassup05 wants to merge 9 commits intofortran-lang:masterfrom
wassup05:abs_path
Open

feat: path functions is_abs and abs_path#1027
wassup05 wants to merge 9 commits intofortran-lang:masterfrom
wassup05:abs_path

Conversation

@wassup05
Copy link
Contributor

@wassup05 wassup05 commented Aug 11, 2025

User facing functions added are:

  • is_abs(path): returns a logical indicating if the path is absolute.
  • abs_path(path [, err]): returns the absolutized version of the path.

is_abs does pure string manipulation checking if

  • on POSIX systems, path starts with /
  • on Windows systems it is either an UNC path or starts with a drive letter like C:\

abs_path performs a syscall to get the current working directory and then joins it to the path, returning the joined path

Prior Art

os.path.abspath (Python)
os.path.isabs (Python)

Copy link
Member

@sebastian-mutz sebastian-mutz left a comment

Choose a reason for hiding this comment

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

Thanks, @wassup05!
I'm wondering if is_abs_path may be better to use. While "path" is the first thing many will think of from context, it is entirely implied. Even in the use statement stdlib_system, only: is_abs, it's not visible (c.f. Python's os.path.isabs).

@wassup05
Copy link
Contributor Author

I had that in mind too @sebastian-mutz, and I have changed it now.

Copy link
Member

@sebastian-mutz sebastian-mutz left a comment

Choose a reason for hiding this comment

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

LGTM with the recent change, @wassup05. Many thanks.

end if

! join the cwd and path
abs_p = cwd / p
Copy link
Member

Choose a reason for hiding this comment

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

what happens if p is already an absolute path on input?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 85745a4, it just returns the path unchanged.

@@ -167,4 +167,58 @@ module function dir_name_string(p) result(dir)

call split_path(p, dir, temp)
end function dir_name_string

module logical function is_abs_path_char(p)
Copy link
Member

@perazz perazz Sep 1, 2025

Choose a reason for hiding this comment

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

the is_abs_path function only tests the form of a path specification, not the fact that it must actually exist in the filesystem. So I wonder if giving these functions the same name as is_file, is_directory etc., that instead test the actual filesystem, wouldn't be confusing for some. Also, do other library implementations only check the form, or do they require the actual path to exist?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a valid concern I feel but that is how most path related functions work.. even in other libraries like python, go etc and considering all these functions have path in their name should make the required distinction I believe.

@codecov
Copy link

codecov bot commented Mar 9, 2026

Codecov Report

❌ Patch coverage is 58.25243% with 43 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.94%. Comparing base (1c534cb) to head (a3df735).
⚠️ Report is 41 commits behind head on master.

Files with missing lines Patch % Lines
test/system/test_path.f90 67.64% 22 Missing ⚠️
example/system/example_path_abs.f90 0.00% 11 Missing ⚠️
src/system/stdlib_system_path.f90 58.33% 10 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1027      +/-   ##
==========================================
- Coverage   68.05%   67.94%   -0.11%     
==========================================
  Files         402      403       +1     
  Lines       12839    12942     +103     
  Branches     1383     1406      +23     
==========================================
+ Hits         8738     8794      +56     
- Misses       4101     4148      +47     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

3 participants