Skip to content

Commit 6f79227

Browse files
authored
Merge pull request #53 from JesseMckinzie/get_regex_fix
Fix error when importing get_regex
2 parents 595d3f4 + 8883923 commit 6f79227

File tree

5 files changed

+20
-3
lines changed

5 files changed

+20
-3
lines changed

src/filepattern/cpp/bindings.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ PYBIND11_MODULE(backend, m){
3333
.def("setGroup", py::overload_cast<const std::vector<std::string>&>(&FilePattern::setGroup))
3434
.def("setGroupStr", py::overload_cast<std::string&>(&FilePattern::setGroup))
3535
.def("length", &FilePattern::length)
36+
.def_static("getRegex", &FilePattern::getRegex)
3637
.def_static("inferPattern", py::overload_cast<const std::string&, std::string&, const std::string&>(&FilePattern::inferPattern))
3738
.def_static("inferPattern", py::overload_cast<std::vector<std::string>&, std::string&>(&FilePattern::inferPattern))
3839
.def("__iter__", [](FilePattern &v){

src/filepattern/cpp/include/filepattern.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ class FILEPATTERN_EXPORT FilePattern {
9999

100100
std::pair<std::vector<std::pair<std::string, Types>> , std::vector<Tuple>> getGroupedSliceByIdx(int idx);
101101

102+
static std::string getRegex(std::string filepattern, bool suppress_warnings);
103+
102104
std::string getPattern();
103105
void setPattern(std::string& pattern);
104106
std::string getPath();

src/filepattern/cpp/interface/filepattern.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,7 @@ const std::unique_ptr<PatternObject>& FilePattern::getPatternObject() const{
185185
std::pair<std::vector<std::pair<std::string, Types>> , std::vector<Tuple>> FilePattern::getGroupedSliceByIdx(int idx) {
186186
return fp_->get_grouped_file_by_idx(idx);
187187
}
188+
189+
std::string FilePattern::getRegex(std::string filepattern, bool suppress_warnings) {
190+
return std::get<0>(Pattern::getRegex(filepattern, suppress_warnings));
191+
}

src/filepattern/functions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Reference/Functions
44

55

6-
def get_regex(filepattern: str, suppress_warnings=False) -> tuple:
6+
def get_regex(filepattern: str, suppress_warnings=False) -> str:
77
"""Returns the regex equivalent of the filepattern.
88
99
Args:
@@ -14,8 +14,8 @@ def get_regex(filepattern: str, suppress_warnings=False) -> tuple:
1414
String containing the regex equivalent of the filepattern
1515
1616
"""
17-
result = backend.FilePattern.getRegex(filepattern, suppress_warnings)
18-
return result[0:2]
17+
return backend.FilePattern.getRegex(filepattern, suppress_warnings)
18+
1919

2020

2121
def infer_pattern(

tests/test_filepattern.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@
55
import test_generate_filepattern_data
66
import test_filepattern_data as fp_data
77

8+
class TestFilePatternFunctions():
9+
10+
def test_get_regex(self):
11+
12+
pattern = 'img_{row:c}{col:dd}f{f:dd}d{channel:d}.tif'
13+
14+
regex_pattern = fp.get_regex(pattern)
15+
16+
assert regex_pattern == 'img_([a-zA-Z])([0-9][0-9])f([0-9][0-9])d([0-9]).tif'
17+
818

919
class TestFilePattern():
1020

0 commit comments

Comments
 (0)