diff --git a/scripts/_utils.py b/scripts/_utils.py new file mode 100644 index 0000000000..623eaca9f7 --- /dev/null +++ b/scripts/_utils.py @@ -0,0 +1,13 @@ +import os +from pathlib import Path + +ROOT_DIR = Path(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + + +def dir_name(origin: str) -> str: + return origin.replace("-", "_") + + +def pascal_case(origin: str) -> str: + """Convert from snake-case to PascalCase.""" + return "".join(word.title() for word in origin.split("-")) diff --git a/scripts/add_plugin.py b/scripts/add_plugin.py index 96d3cb13d8..3fac8231e0 100755 --- a/scripts/add_plugin.py +++ b/scripts/add_plugin.py @@ -10,17 +10,8 @@ Example usage: import argparse import os -from pathlib import Path -ROOT_DIR = Path(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) - - -def dir_name(plugin: str) -> str: - return plugin.replace("-", "_") - - -def pascal_case(plugin: str) -> str: - return "".join(word.title() for word in plugin.split("-")) +from _utils import ROOT_DIR, dir_name, pascal_case def main(*, plugin: str, url: str) -> None: diff --git a/scripts/add_rule.py b/scripts/add_rule.py index 40e10fc3e6..988d4934a1 100755 --- a/scripts/add_rule.py +++ b/scripts/add_rule.py @@ -10,19 +10,8 @@ Example usage: """ import argparse -import os -from pathlib import Path -ROOT_DIR = Path(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) - - -def dir_name(origin: str) -> str: - return origin.replace("-", "_") - - -def pascal_case(origin: str) -> str: - """Convert from snake-case to PascalCase.""" - return "".join(word.title() for word in origin.split("-")) +from _utils import ROOT_DIR, dir_name def snake_case(name: str) -> str: