Skip to content

Commit

Permalink
Use the extract functions from Burly
Browse files Browse the repository at this point in the history
  • Loading branch information
ssorj committed Jan 19, 2024
1 parent d322a30 commit 53b0db8
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 43 deletions.
18 changes: 1 addition & 17 deletions .plano.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
# under the License.
#

import re

from burly import *
from plano import *

@command
Expand Down Expand Up @@ -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__"))
Expand Down
24 changes: 2 additions & 22 deletions external/burly-main/.plano.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# under the License.
#

from burly import *
from plano import *

@command
Expand All @@ -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")

Expand All @@ -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")
Expand All @@ -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)
Expand All @@ -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():
"""
Expand Down
20 changes: 20 additions & 0 deletions external/burly-main/python/burly/__init__.py
Original file line number Diff line number Diff line change
@@ -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 *
39 changes: 39 additions & 0 deletions external/burly-main/python/burly/main.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ usage() {
fi

cat <<EOF
Usage: ${0} [OPTION...]
Usage: install.sh [OPTION...]
Install the Skupper command-line tool
Expand Down
2 changes: 1 addition & 1 deletion install.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ usage() {
fi

cat <<EOF
Usage: ${0} [OPTION...]
Usage: install.sh [OPTION...]
Install the Skupper command-line tool
Expand Down
1 change: 1 addition & 0 deletions python/burly
2 changes: 1 addition & 1 deletion uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ usage() {
fi

cat <<EOF
Usage: ${0} [OPTION...]
Usage: uninstall.sh [OPTION...]
Uninstall the Skupper command-line tool
Expand Down
2 changes: 1 addition & 1 deletion uninstall.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ usage() {
fi

cat <<EOF
Usage: ${0} [OPTION...]
Usage: uninstall.sh [OPTION...]
Uninstall the Skupper command-line tool
Expand Down

0 comments on commit 53b0db8

Please sign in to comment.