Remove StringList & Hash* from python API - #1263
Conversation
fc62f4b to
03dcf79
Compare
There was a problem hiding this comment.
Pull request overview
This PR removes the StringList type from the Python-facing API and migrates the underlying C++/pybind surfaces away from stringlist_type* toward standard containers (std::vector<std::string> / std::set<std::string>), updating tests and call sites accordingly.
Changes:
- Removed Python
StringList(and its dependentHashwrappers) and deleted/updated tests that exercised those APIs. - Updated Summary-related APIs/bindings to return native Python lists (via STL containers in pybind) and adjusted key selection/export paths accordingly.
- Refactored file-list selection utilities to return
std::vector<std::string>and removedstringlist_select_*helpers from the C API surface.
Reviewed changes
Copilot reviewed 28 out of 28 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/util_tests/test_string_list.py | Removed tests for the deleted Python StringList API. |
| tests/util_tests/test_hash.py | Removed tests for the deleted Python Hash wrappers. |
| tests/rd_tests/test_sum_equinor.py | Updated imports/assertions to no longer reference StringList. |
| tests/rd_tests/test_rd_sum.py | Updated expectations to treat Summary.keys()/wells()/groups() as lists, not StringList. |
| tests/rd_tests/test_npv.py | Updated imports to no longer reference StringList. |
| python/resdata/util/util/stringlist.py | Deleted the Python StringList wrapper. |
| python/resdata/util/util/hash.py | Deleted Python Hash wrappers that depended on StringList. |
| python/resdata/util/util/init.py | Stopped exporting StringList/Hash* from resdata.util.util. |
| python/resdata/summary/rd_sum.py | Switched keys()/wells()/groups() plumbing to list/STL-based bindings; added natural sorting for keys. |
| lib/util/tests/ert_util_stringlist_test.cpp | Removed predicate-matching test coverage tied to removed stringlist_select_files. |
| lib/util/stringlist.cpp | Removed stringlist_select_files() and stringlist_select_matching_files() implementations. |
| lib/tests/test_rd_sum.cpp | Updated tests to match new container-returning APIs (set/vector) instead of stringlist. |
| lib/resdata/tests/well_ts.cpp | Updated restart file list handling to use std::vector<std::string> and STL sorting. |
| lib/resdata/tests/rd_filenames.cpp | Updated file-list tests to use std::vector<std::string> return values. |
| lib/resdata/rd_util.cpp | Implemented vector-returning file selection helpers; moved matching/dir scanning logic here. |
| lib/resdata/rd_sum.cpp | Migrated summary read/export and key selection APIs to STL containers. |
| lib/resdata/rd_sum_vector.cpp | Updated key expansion to use set-returning key selection and explicit sorting. |
| lib/resdata/rd_sum_pybind.cpp | Updated pybind layer to pass/return STL containers instead of cwrap StringList. |
| lib/resdata/rd_sum_file_data.cpp | Updated data-file reading to accept std::vector<std::string> and throw on invalid inputs. |
| lib/resdata/rd_sum_data.cpp | Updated rd_sum_data_fread to accept std::vector<std::string>. |
| lib/resdata/rd_smspec.cpp | Changed matching-key selection to return std::set<std::string> and map-list APIs to return vectors. |
| lib/resdata/cwrap_pybind.cpp | Removed StringList cwrap conversion helpers. |
| lib/private-include/detail/resdata/rd_sum_file_data.hpp | Updated interface to accept std::vector<std::string> instead of stringlist_type*. |
| lib/include/resdata/rd_util.hpp | Updated rd_select_filelist signature and added select_matching_files declaration. |
| lib/include/resdata/rd_sum.hpp | Updated public summary API signatures to use STL containers. |
| lib/include/resdata/rd_sum_data.hpp | Updated rd_sum_data_fread signature to use STL containers. |
| lib/include/resdata/rd_smspec.hpp | Updated selection/list APIs toward STL containers (but currently still declares a removed stringlist alloc API). |
| lib/include/ert/util/stringlist.hpp | Removed declarations for stringlist_select_files and stringlist_select_matching_files. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
ae50ee7 to
fea613e
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 28 out of 28 changed files in this pull request and generated no new comments.
Suppressed comments (2)
lib/resdata/rd_util.cpp:594
- On Windows,
FindClose(file_handle)is called unconditionally even whenFindFirstFilereturnsINVALID_HANDLE_VALUE. CallingFindCloseon an invalid handle can fail and may crash in some environments. Only close the handle when it was successfully opened.
file_handle = FindFirstFile(pattern, &file_data);
if (file_handle != INVALID_HANDLE_VALUE) {
do {
char *full_path = util_alloc_filename(
path.c_str(), file_data.cFileName, NULL);
names.emplace_back(full_path);
free(full_path);
} while (FindNextFile(file_handle, &file_data) != 0);
}
FindClose(file_handle);
free(pattern);
lib/resdata/rd_util.cpp:649
- The sort comparator takes its arguments by value (
std::string a, std::string b), which copies each string during sorting. Useconst std::string¶meters to avoid unnecessary allocations/copies.
std::sort(filelist.begin(), filelist.end(),
[](std::string a, std::string b) {
return rd_fname_report_cmp(a.c_str(), b.c_str()) < 0;
});
fea613e to
8180f93
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 44 out of 44 changed files in this pull request and generated no new comments.
Suppressed comments (2)
lib/resdata/tests/well_ts.cpp:44
- The former second
WellInfoblock loaded the restart files in reverse order, so deleting it removes regression coverage that loading is order-independent. Replacingstringlist_reversewithstd::reversepreserves that scenario without usingStringList.
for (const auto &file_name : file_list) {
printf("Loading file:%s \n", file_name.c_str());
well_info.load_rstfile(file_name, true);
python/resdata/util/util/init.py:35
- Removing this export together with
hash.pyalso deletes the publicHash,StringHash,IntegerHash, andDoubleHashAPIs, although this change is scoped to removingStringList. Existingfrom resdata.util.util import StringHashconsumers will now fail. Keep the hash wrappers and makeHash.keys()return a native Python list, or explicitly include this additional breaking API removal in the intended scope and migration plan.
8180f93 to
d69b0cc
Compare
d69b0cc to
b558b34
Compare
b558b34 to
ecc22ba
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 44 out of 44 changed files in this pull request and generated no new comments.
Suppressed comments (1)
lib/resdata/rd_smspec.cpp:1228
- The new API comment is grammatically incorrect: “Returns a all” should be “Returns all.”
/** Returns a all the (valid) well names.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 44 out of 44 changed files in this pull request and generated no new comments.
Suppressed comments (2)
lib/resdata/rd_util.cpp:538
- This copied comment is now inaccurate: the helper returns a fresh
std::vectorand no longer clears a caller-provided string list. Please describe the returned matches instead so the implementation contract is not misleading.
/*
This function uses the stdlib function glob() to select file/path
names matching a pattern. The stringlist is cleared when the
function starts.
lib/include/resdata/rd_util.hpp:159
select_matching_filesis only used internally byrd_sum.cpp, but declaring this generic global helper in an installed public header unintentionally expands the library API and risks name collisions for consumers. Please place it in a private/detail header (and preferably therdnamespace) instead.
std::vector<std::string> select_matching_files(const std::string &path,
const std::string &file_pattern);
ecc22ba to
9d9fced
Compare
c2e9c29 to
f2d180d
Compare
f2d180d to
17a37f5
Compare
Note that this removes the behavior of base == nullptr meaning "*". This was never used and it didn't work as bas_has_upper had UB for base==nullptr.
This also checks return values for windows equivalent code.
These are redundant since util_abort is noreturn
this avoids manually handling the memory for the return value of rd_alloc_filename_static.
In rd_select_filelist we want base="*" and file_type=FileType::EGRID to match against "*.EGRID". Also fixes a bug where summary files were matched with prefix of basename rather than the full basename, and added unit tests for these.
17a37f5 to
c3ba5b5
Compare
6ff2fbb to
6b169ed
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 52 out of 52 changed files in this pull request and generated no new comments.
Suppressed comments (1)
lib/resdata/rd_util.cpp:507
is_directory(..., ec)reports permission and I/O failures throughec, but this branch treats everyfalseresult as a missing/non-directory path. That contradicts the contract above and makes inaccessible summary directories silently appear empty; checkecfirst and propagate it.
std::error_code ec;
if (!fs::is_directory(scan_dir, ec))
return {};
ajaust
left a comment
There was a problem hiding this comment.
Nice!
Only found a tiny typo in one commit message.
| const char *base = strrchr(input_base, UTIL_PATH_SEP_CHAR); | ||
| if (base == NULL) | ||
| base = input_base; | ||
| static bool base_has_upper(std::string_view input_base) { |
There was a problem hiding this comment.
Small type in commit message where it says bas_has_upper instead of base_... (commit "Remove StringList from python API").
This fixes a number of buggy behaviors: