-
Notifications
You must be signed in to change notification settings - Fork 197
stdlib_system: essential path functionality
#999
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
Conversation
Thanks for the PR, @wassup05. Just a minor point (not related to functionality) about examples for now: It's always useful - esp. for those learning by examples - to have an idea of the expected output. Other stdlib examples add the expected print results as a comment below the respective commands. I would recommend to do the same here.
I will add that with the other reviews @sebastian-mutz, I don't want to trigger the ci/cd workflow just for a few comments. Also on a second thought maybe instead of the if (ISWIN) ... thing I could separate the two examples...
The issue with Ninja detecting a "circular dependency" (there was non) was related to the stdlib_system.F90 file not being visible in a correct manner in the CMakeLists.txt file.
The group:
# Preprocessed files to contain preprocessor directives -> .F90 set(cppFiles
corresponds to .fypp files for which the suffix should be changed to .F90. Not for already .F90 files.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM @wassup05! Thanks for this nice work!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces essential path manipulation functions and related operator overloads to simplify path handling across platforms. Key changes include:
- Implementation of joinpath (and its operator(/)) for concatenating paths.
- Addition of splitpath and its derivatives (basename, dirname) for decomposing paths.
- Updates to tests, examples, documentation, and build files to support and illustrate the new functionality.
Reviewed Changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| test/system/test_path.f90 | Adds unit tests for new path functions and operator functionality. |
| test/system/CMakeLists.txt | Registers the new "path" test. |
| src/stdlib_system_path.f90 | Implements joinpath, operator(/), splitpath, basename, and dirname. |
| src/stdlib_system.F90 | Defines interfaces and exports for the new path functionality. |
| src/CMakeLists.txt | Includes the new path source file in the build. |
| example/system/*.f90 | Provides usage examples for joinpath, splitpath, dirname, and basename. |
| doc/specs/stdlib_system.md | Updates the spec documentation to incorporate the new interfaces. |
| config/fypp_deployment.py | Passes the uppercase system name flag to the build commands. |
| CMakeLists.txt | Adds compile options to define the system name macro. |
Comments suppressed due to low confidence (2)
example/system/example_path_dirname.f90:2
- The program name 'example_path_splitpath' does not match the file's purpose (dirname functionality). Consider renaming it to 'example_path_dirname'.
program example_path_splitpath
example/system/example_path_basename.f90:2
- The program name 'example_path_splitpath' in this file appears to be a copy-paste error; it should reflect basename functionality (e.g., 'example_path_basename').
program example_path_splitpath
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice start @wassup05, thank you for this PR. It's a bit long so I tried to give some initial comments first hand. Let's first discuss and iterate around these comments, and then we can start planning about more path functionality, thank you.
src/stdlib_system.F90
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please add short FORD comment blocks for theese APIs? As an example:
Lines 102 to 116 in ca867f8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the documentation is added here, it should be placed following the interface declaration or within the function declaration if there is no additional interface, and not before the public statement as it is done within this module currently. I actually have issues with FORD locally to produce the documentation because of that but haven't mention it yet to avoid mixing issues within the same PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it is a good idea to address (these and perhaps more of) FORD issues in a separate PR. For the current PR, I think it's ok to stay consistent with the current syntax.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added the docs following the interface blocks of these interfaces... Isn't that enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for implementing these updates @wassup05.
Request for changes was fully addressed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this PR @wassup05, I have left a few final comments.
doc/specs/stdlib_system.md
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because stdlib offers a string type, it would be nice if these string manipulation functions were interfaces working with either character strings (as currently proposed), or the internal string_type type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made these functions interfaces keeping this possibility in mind... But what is considered a good way of doing this? Writing procedures for string_type and then, when calling them with character variables just assign these to the new string_type variables and call the string_type version of the interface itself or code duplication, keeping the code separate for these two although they are in essence the same?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I got it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes: the easiest option is to keep the character implementation and then return the result to a string via move:
stdlib/src/stdlib_string_type.fypp
Lines 220 to 227 in d8a90aa
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added the relevant changes... But it doesn't use move, it uses assignment(=) and char, Let me know what you think of it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It works @wassup05, however, there are two copies: string->char for the input arguments, and then char -> string on the assignment. Using move would at least avoid incurring the last copy. Just do:
character(:), allocatable :: join_char
join_char = join_path(char(a),char(b))
call move(from=join_char,to=...result variable...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because the internal string_type representation is just an allocatable character variable, I would also support (to be discussed with the community as a separate PR) the implementation of a tiny zero-copy "view" function for the string type, see here:
!> Zero-copy view of the string as a character array pure function view(string) result(char_array) type(string_type), intent(in), target :: string character(:), pointer :: char_array if (allocated(string%raw)) then char_array => string%raw else nullify(char_array) end if end function view
In absence of further comments, I will merge this one, thank you.
A few path related functions for ease of future functionality have been added.
joinpath: joins the given paths according to the platform'spath-separator.operator(/): as was suggested in the Fortran discourse here an operator is also provided for the same functionalitysplitpath: splits the path following the lastpath-separatorand returns theheadandtail.basename: just returns thetailofsplitpathdirname: just returns theheadofsplitpathThe
pathsepparametercontains either/or\depending on the platform and is a compile-time constant now, so is theparameter,ISWINDo let me know your thoughts.