From 3609b3aba86556bb54036c38907c7d7da45144cb Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Sun, 12 Jan 2020 10:08:36 -0600 Subject: [PATCH 1/2] Use pytools.natsorted --- dagrt/language.py | 4 ++-- dagrt/utils.py | 29 ----------------------------- 2 files changed, 2 insertions(+), 31 deletions(-) diff --git a/dagrt/language.py b/dagrt/language.py index 60a3709..4603d7b 100644 --- a/dagrt/language.py +++ b/dagrt/language.py @@ -25,13 +25,13 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ -from pytools import RecordWithoutPickling, memoize_method +from pytools import RecordWithoutPickling, memoize_method, natsorted from pymbolic.imperative.statement import ( ConditionalStatement as StatementBase, ConditionalAssignment as AssignBase, Nop as NopBase) -from dagrt.utils import get_variables, natsorted +from dagrt.utils import get_variables from contextlib import contextmanager import logging diff --git a/dagrt/utils.py b/dagrt/utils.py index 69f4640..bd8df2e 100644 --- a/dagrt/utils.py +++ b/dagrt/utils.py @@ -224,33 +224,4 @@ def run_fortran(sources, fortran_options=None, fortran_libraries=None): # }}} - -# {{{ sorting in natural order - -def natorder(key): - # Return natural ordering for strings, as opposed to dictionary order. - # E.g. will result in - # 'abc1' < 'abc9' < 'abc10' - # rather than - # 'abc1' < 'abc10' < 'abc9' - # Based on - # http://code.activestate.com/recipes/285264-natural-string-sorting/#c7 - import re - result = [] - for (int_val, string_val) in re.findall(r"(\d+)|(\D+)", key): - if int_val: - result.append(int(int_val)) - # Tie-breaker in case leading zeros in *int_val* cause distinct - # values to compare equally. - result.append(len(int_val)) - else: - result.append(string_val) - return result - - -def natsorted(seq, key=lambda x: x): - return sorted(seq, key=lambda y: natorder(key(y))) - -# }}} - # vim: foldmethod=marker -- GitLab From e9cdc56613e3554ea1969e1ccbe83d8e03631c01 Mon Sep 17 00:00:00 2001 From: Matt Wala Date: Sun, 12 Jan 2020 10:14:03 -0600 Subject: [PATCH 2/2] Bump pytools version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 053a8b7..706c6ed 100644 --- a/setup.py +++ b/setup.py @@ -41,7 +41,7 @@ def main(): packages=find_packages(), install_requires=[ "numpy>=1.5", - "pytools>=2014.1", + "pytools>=2020.1", "pymbolic>=2016.2", "pytest>=2.3", "mako", -- GitLab