From 53b0db841a2e819a04672e36fad5d4e89307495b Mon Sep 17 00:00:00 2001 From: Justin Ross Date: Fri, 19 Jan 2024 10:03:22 -0500 Subject: [PATCH] Use the extract functions from Burly --- .plano.py | 18 +-------- external/burly-main/.plano.py | 24 +----------- external/burly-main/python/burly/__init__.py | 20 ++++++++++ external/burly-main/python/burly/main.py | 39 ++++++++++++++++++++ install.sh | 2 +- install.sh.in | 2 +- python/burly | 1 + uninstall.sh | 2 +- uninstall.sh.in | 2 +- 9 files changed, 67 insertions(+), 43 deletions(-) create mode 100644 external/burly-main/python/burly/__init__.py create mode 100644 external/burly-main/python/burly/main.py create mode 120000 python/burly diff --git a/.plano.py b/.plano.py index 85383bc..15a3c39 100644 --- a/.plano.py +++ b/.plano.py @@ -17,8 +17,7 @@ # under the License. # -import re - +from burly import * from plano import * @command @@ -72,21 +71,6 @@ def build(): write("install.sh", install_sh) write("uninstall.sh", uninstall_sh) -def extract_boilerplate(code): - boilerplate = re.search(r"# BEGIN BOILERPLATE\n(.*?)\n# END BOILERPLATE", code, re.DOTALL) - - if boilerplate: - return boilerplate.group(1).strip() - -def extract_functions(code): - functions = dict() - matches = re.finditer(r"\n(\w+)\s*\(\)\s+{\n.*?\n}", code, re.DOTALL) - - for match in matches: - functions[match.group(1)] = match.group(0) - - return functions - @command def clean(): remove(find(".", "__pycache__")) diff --git a/external/burly-main/.plano.py b/external/burly-main/.plano.py index fe63be6..f01d30c 100644 --- a/external/burly-main/.plano.py +++ b/external/burly-main/.plano.py @@ -17,6 +17,7 @@ # under the License. # +from burly import * from plano import * @command @@ -29,7 +30,7 @@ def test(verbose=False, coverage=False): if coverage: check_program("kcov") - run(f"kcov ~/coverage bats {'--trace' if verbose else ''} tests/main.sh") + run(f"kcov coverage bats {'--trace' if verbose else ''} tests/main.sh") else: run(f"bats {'--trace' if verbose else ''} tests/main.sh") @@ -45,7 +46,6 @@ def lint(): """ Use shellcheck to scan for problems """ - check_program("shellcheck") run("shellcheck --shell sh --enable all --exclude SC3043,SC2310,SC2312 burly.sh") @@ -61,7 +61,6 @@ def extract(*function_names): """ Produce code containing only the named functions and some setup logic """ - code = read("burly.sh") boilerplate = extract_boilerplate(code) @@ -72,25 +71,6 @@ def extract(*function_names): for name in function_names: print(funcs[name]) -def extract_boilerplate(code): - import re - - boilerplate = re.search(r"# BEGIN BOILERPLATE\n(.*?)\n# END BOILERPLATE", code, re.DOTALL) - - if boilerplate: - return boilerplate.group(1).strip() - -def extract_functions(code): - import re - - functions = dict() - matches = re.finditer(r"\n(\w+)\s*\(\)\s+{\n.*?\n}", code, re.DOTALL) - - for match in matches: - functions[match.group(1)] = match.group(0) - - return functions - @command def update_plano(): """ diff --git a/external/burly-main/python/burly/__init__.py b/external/burly-main/python/burly/__init__.py new file mode 100644 index 0000000..3324b21 --- /dev/null +++ b/external/burly-main/python/burly/__init__.py @@ -0,0 +1,20 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +from .main import * diff --git a/external/burly-main/python/burly/main.py b/external/burly-main/python/burly/main.py new file mode 100644 index 0000000..838e007 --- /dev/null +++ b/external/burly-main/python/burly/main.py @@ -0,0 +1,39 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +import re + +from plano import * + +__all__ = "extract_boilerplate", "extract_functions" + +def extract_boilerplate(code): + boilerplate = re.search(r"# BEGIN BOILERPLATE\n(.*?)\n# END BOILERPLATE", code, re.DOTALL) + + if boilerplate: + return boilerplate.group(1).strip() + +def extract_functions(code): + functions = dict() + matches = re.finditer(r"\n(\w+)\s*\(\)\s+{\n.*?\n}", code, re.DOTALL) + + for match in matches: + functions[match.group(1)] = match.group(0) + + return functions diff --git a/install.sh b/install.sh index bca982a..443e8ff 100644 --- a/install.sh +++ b/install.sh @@ -424,7 +424,7 @@ usage() { fi cat <