-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdevelop.py
More file actions
executable file
·68 lines (59 loc) · 1.85 KB
/
Copy pathdevelop.py
File metadata and controls
executable file
·68 lines (59 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env poetry run python
import argparse
import os
import shutil
import juliapkg
script_dir = os.path.dirname(os.path.abspath(__file__))
source_file = os.path.join(script_dir, "src/finch/juliapkg.json")
backup_file = os.path.join(script_dir, "src/finch/juliapkg.json.orig")
# Parse command-line arguments
usage = """
Usage:
develop.py [--restore] [--path <path>]
Options:
--restore Restore the original juliapkg.json file.
--path Path to the local copy of Finch.jl [default: ../Finch.jl].
"""
parser = argparse.ArgumentParser(
description=(
"Development script for Finch. This script allows you to specify "
"the location of a local copy of Finch.jl."
),
usage=usage,
)
parser.add_argument(
"--path",
default=os.path.join(script_dir, "../Finch.jl"),
help="Path to the Finch.jl package.",
)
parser.add_argument(
"--restore", action="store_true", help="Restore the original juliapkg.json file."
)
args = parser.parse_args()
# Handle the --restore flag
if args.restore:
try:
shutil.copy(backup_file, source_file)
print("Restored src/finch/juliapkg.json from backup.")
except FileNotFoundError:
print("Error: Backup file src/finch/juliapkg.json.orig does not exist.")
except (OSError, PermissionError) as e:
print(f"An error occurred: {e}")
exit()
# Set the Finch path
finch_path = os.path.abspath(args.path)
# Define source and destination file paths and copy the file
try:
if not os.path.exists(backup_file):
shutil.copy(source_file, backup_file)
except (OSError, PermissionError) as e:
print(f"An error occurred: {e}")
# Checkout Finch for development
juliapkg.rm("Finch", target="src/finch/juliapkg.json")
juliapkg.add(
"Finch",
"9177782c-1635-4eb9-9bfb-d9dfa25e6bce",
dev=True,
path=finch_path,
target="src/finch/juliapkg.json",
)