Skip to content

Commit

Permalink
python format
Browse files Browse the repository at this point in the history
  • Loading branch information
sprutton1 committed Dec 20, 2024
1 parent 2120da3 commit dc8e480
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 100 deletions.
46 changes: 12 additions & 34 deletions prelude-si/deno/deno_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,15 @@

def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
"--input",
required=True,
type=pathlib.Path,
help="The path to compile, ideally a index.ts file"
)
parser.add_argument("--input",
required=True,
type=pathlib.Path,
help="The path to compile, ideally a index.ts file")
parser.add_argument(
"--output",
required=True,
type=pathlib.Path,
help="The target directory for outputting the artifact"
)
help="The target directory for outputting the artifact")
parser.add_argument(
"--permissions",
nargs='*',
Expand All @@ -51,19 +48,10 @@ def parse_unstable_flags(flags: List[str]) -> List[str]:
return [f'--unstable-{flag}' for flag in flags]


def run_compile(
input_path: str,
output_path: str,
permissions: List[str],
flags: List[str]
) -> None:
def run_compile(input_path: str, output_path: str, permissions: List[str],
flags: List[str]) -> None:
"""Run deno compile with the specified arguments."""
cmd = [
"deno",
"compile",
"--output",
output_path
]
cmd = ["deno", "compile", "--output", output_path]

if permissions:
cmd.extend(permissions)
Expand All @@ -74,12 +62,7 @@ def run_compile(
cmd.append(input_path)

try:
subprocess.run(
cmd,
check=True,
capture_output=True,
text=True
)
subprocess.run(cmd, check=True, capture_output=True, text=True)
except subprocess.CalledProcessError as e:
print("Error compiling Deno binary:", file=sys.stderr)
print(f"Command: {' '.join(cmd)}", file=sys.stderr)
Expand All @@ -98,21 +81,16 @@ def main() -> int:

if not os.path.exists(abs_input_path):
print(f"Error: Input file not found: {abs_input_path}",
file=sys.stderr
)
file=sys.stderr)
return 1

os.makedirs(os.path.dirname(abs_output_path), exist_ok=True)

permissions_list = parse_permissions(args.permissions)
flags_list = parse_unstable_flags(args.unstable_flags)

run_compile(
abs_input_path,
abs_output_path,
permissions_list,
flags_list
)
run_compile(abs_input_path, abs_output_path, permissions_list,
flags_list)

os.chmod(
abs_output_path,
Expand Down
47 changes: 15 additions & 32 deletions prelude-si/deno/deno_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,25 @@

def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
"--input",
action='append',
required=True,
type=pathlib.Path,
help="The files or directories to format"
)
parser.add_argument("--input",
action='append',
required=True,
type=pathlib.Path,
help="The files or directories to format")
parser.add_argument(
"--check",
action="store_true",
help="Check if files are formatted without making changes"
)
parser.add_argument(
"--ignore",
nargs='*',
default=[],
help="List of files or directories to ignore"
)
help="Check if files are formatted without making changes")
parser.add_argument("--ignore",
nargs='*',
default=[],
help="List of files or directories to ignore")

return parser.parse_args()


def run_format(
input_paths: List[str],
check_only: bool,
ignore_paths: List[str]
) -> None:
def run_format(input_paths: List[str], check_only: bool,
ignore_paths: List[str]) -> None:
"""Run deno fmt with the specified arguments."""
cmd = ["deno", "fmt"]

Expand All @@ -52,11 +44,7 @@ def run_format(
cmd.extend(input_paths)

try:
result = subprocess.run(
cmd,
check=True,
text=True
)
result = subprocess.run(cmd, check=True, text=True)
if result.stdout:
print(result.stdout)
except subprocess.CalledProcessError as e:
Expand All @@ -79,16 +67,11 @@ def main() -> int:
abs_path = os.path.abspath(input_path)
if not os.path.exists(abs_path):
print(f"Error: Input path not found: {abs_path}",
file=sys.stderr
)
file=sys.stderr)
return 1
input_paths.append(abs_path)

run_format(
input_paths,
args.check,
args.ignore
)
run_format(input_paths, args.check, args.ignore)

if args.check:
print("Format check completed successfully.")
Expand Down
52 changes: 18 additions & 34 deletions prelude-si/deno/deno_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,26 @@ def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument(
"--input",
action='append',
action="append",
required=True,
type=pathlib.Path,
help="The test file to run (can be specified multiple times)"
help="The test file to run (can be specified multiple times)",
)
parser.add_argument(
"--filter",
type=str,
help="Run tests with this string or pattern in the test name"
)
parser.add_argument(
"--ignore",
nargs='*',
default=[],
help="List of files or directories to ignore"
)
parser.add_argument(
"--parallel",
action="store_true",
help="Run tests in parallel"
)
parser.add_argument(
"--watch",
action="store_true",
help="Watch for file changes and restart tests"
help="Run tests with this string or pattern in the test name",
)
parser.add_argument("--ignore",
nargs="*",
default=[],
help="List of files or directories to ignore")
parser.add_argument("--parallel",
action="store_true",
help="Run tests in parallel")
parser.add_argument("--watch",
action="store_true",
help="Watch for file changes and restart tests")

return parser.parse_args()

Expand All @@ -49,7 +43,7 @@ def run_tests(
filter_pattern: str | None,
ignore_paths: List[str],
parallel: bool,
watch: bool
watch: bool,
) -> None:
"""Run deno test with the specified arguments."""
cmd = ["deno", "test"]
Expand All @@ -69,11 +63,7 @@ def run_tests(
cmd.extend(input_paths)

try:
result = subprocess.run(
cmd,
check=True,
text=True
)
result = subprocess.run(cmd, check=True, text=True)
if result.stdout:
print(result.stdout)
except subprocess.CalledProcessError as e:
Expand All @@ -96,18 +86,12 @@ def main() -> int:
abs_path = os.path.abspath(input_path)
if not os.path.exists(abs_path):
print(f"Error: Input path not found: {abs_path}",
file=sys.stderr
)
file=sys.stderr)
return 1
input_paths.append(abs_path)

run_tests(
input_paths,
args.filter,
args.ignore,
args.parallel,
args.watch
)
run_tests(input_paths, args.filter, args.ignore, args.parallel,
args.watch)

print("Tests completed successfully.")
return 0
Expand Down

0 comments on commit dc8e480

Please sign in to comment.