Skip to content

Commit

Permalink
Use POSIX ERE for sub function (#321)
Browse files Browse the repository at this point in the history
implements openwdl/wdl#243
  • Loading branch information
DavyCats authored Jan 31, 2020
1 parent 8b87267 commit 1e59170
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
6 changes: 4 additions & 2 deletions WDL/StdLib.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# pylint: disable=protected-access,exec-used
import math
import os
import re
import regex
import json
import tempfile
from typing import List, Tuple, Callable, BinaryIO, Optional
Expand Down Expand Up @@ -67,7 +67,9 @@ def static(

@static([Type.String(), Type.String(), Type.String()], Type.String())
def sub(input: Value.String, pattern: Value.String, replace: Value.String) -> Value.String:
return Value.String(re.compile(pattern.value).sub(replace.value, input.value))
return Value.String(
regex.compile(pattern.value, flags=regex.POSIX).sub(replace.value, input.value)
)

static([Type.String(), Type.String(optional=True)], Type.String())(basename)

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ pygtail>=0.11.0
coloredlogs
psutil
importlib-metadata
regex
7 changes: 7 additions & 0 deletions stubs/regex/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from typing import Any

POSIX: int


def compile(pattern, flags=0, **kwargs) -> Any:
...
6 changes: 5 additions & 1 deletion tests/test_5stdlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,14 +220,18 @@ def test_sub(self):
String chocolove = sub(chocolike, "like", "love") # I love chocolate when it's late
String chocoearly = sub(chocolike, "late", "early") # I like chocoearly when it's early
String chocolate = sub(chocolike, "late$", "early") # I like chocolate when it's early
String chocoearlylate = sub(chocolike, "[^ ]late", "early") # I like chocearly when it's late
String choco4 = sub(chocolike, " [[:alpha:]]{4} ", " 4444 ") # I 4444 chocolate 4444 it's late
}
}
""")
self.assertEqual(outputs, {
"chocolike": "I like chocolate when it's late",
"chocolove": "I love chocolate when it's late",
"chocoearly": "I like chocoearly when it's early",
"chocolate": "I like chocolate when it's early"
"chocolate": "I like chocolate when it's early",
"chocoearlylate": "I like chocearly when it's late",
"choco4": "I 4444 chocolate 4444 it's late"
})
outputs = self._test_task(R"""
task example {
Expand Down

0 comments on commit 1e59170

Please sign in to comment.