Skip to content

Commit

Permalink
Convert format.bash to format.py
Browse files Browse the repository at this point in the history
  • Loading branch information
hisaac committed Dec 9, 2024
1 parent 20e81f8 commit a328b46
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 36 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"killall",
"othr",
"pycache",
"shfmt",
"swiftpm",
"venv",
"yapf"
Expand Down
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ test: up
"{{ scripts_dir }}/test.bash"

format: up
"{{ scripts_dir }}/format.bash"
python "{{ scripts_dir }}/main.py" format

lint: up
"{{ scripts_dir }}/lint.bash"
Expand Down
1 change: 1 addition & 0 deletions scripts/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
TUIST_DIR = PROJECT_ROOT / "tuist"

MISE_BIN = Path.home() / ".local/bin/mise"
XCRUN_BIN = "/usr/bin/xcrun"


def _get_xcode_version() -> str:
Expand Down
5 changes: 4 additions & 1 deletion scripts/commands/build.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import argparse
import subprocess

from commands import PROJECT_ROOT, MISE_BIN
from commands import (
MISE_BIN,
PROJECT_ROOT,
)


def setup_parser(subparser) -> argparse.ArgumentParser:
Expand Down
51 changes: 51 additions & 0 deletions scripts/commands/format.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import argparse
import subprocess

from commands import (
CONFIG_DIR,
MISE_BIN,
PROJECT_ROOT,
SCRIPTS_DIR,
SOURCES_DIR,
TUIST_DIR,
XCRUN_BIN,
)


def setup_parser(subparser) -> argparse.ArgumentParser:
return subparser.add_parser("format", help="Format the project")


def handle(args) -> None:
format_bash()
format_swift()
format_python()


def format_bash() -> None:
subprocess.run(
[MISE_BIN, "exec", "--", "shfmt", "--write", SCRIPTS_DIR], check=True
)


def format_swift() -> None:
subprocess.run(
[
XCRUN_BIN,
"swift-format",
"format",
"--configuration",
CONFIG_DIR / "swift-format.json",
"--in-place",
"--recursive",
SOURCES_DIR,
TUIST_DIR,
PROJECT_ROOT / "Project.swift",
PROJECT_ROOT / "Tuist.swift",
],
check=True,
)


def format_python() -> None:
subprocess.run([MISE_BIN, "exec", "--", "black", SCRIPTS_DIR], check=True)
34 changes: 0 additions & 34 deletions scripts/format.bash

This file was deleted.

4 changes: 4 additions & 0 deletions scripts/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@


from commands import build
from commands import format


def main():
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(dest="command")

build.setup_parser(subparsers)
format.setup_parser(subparsers)

args = parser.parse_args()

if args.command == "build":
build.handle(args)
elif args.command == "format":
format.handle(args)


if __name__ == "__main__":
Expand Down

0 comments on commit a328b46

Please sign in to comment.