mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-08 19:40:54 +00:00
refactor: Reduce code duplication in scripts/
This commit is contained in:
parent
6cc160bc2b
commit
67ca50e9f2
3 changed files with 15 additions and 22 deletions
13
scripts/_utils.py
Normal file
13
scripts/_utils.py
Normal file
|
@ -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("-"))
|
|
@ -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:
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue