Skip to content

Commit 38aa30a

Browse files
authored
Merge pull request #648 from xylar/build-jigsaw-from-hash
Add arguments for hash and subdirectory to `build_jigsaw`
2 parents 5985d4f + f2f0873 commit 38aa30a

File tree

1 file changed

+50
-14
lines changed

1 file changed

+50
-14
lines changed

conda_package/mpas_tools/mesh/creation/jigsaw_driver.py

Lines changed: 50 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def jigsaw_driver(
102102
check_call(['jigsaw', opts.jcfg_file], logger=logger)
103103

104104

105-
def build_jigsaw(logger=None, clone=False):
105+
def build_jigsaw(logger=None, clone=False, subdir='jigsaw-python', hash=None):
106106
"""
107107
Build the JIGSAW and JIGSAW-Python tools using conda-forge compilers
108108
@@ -114,6 +114,15 @@ def build_jigsaw(logger=None, clone=False):
114114
clone : bool, optional
115115
If True, clone the jigsaw-python repository from github
116116
and build it. If False, just build the existing repository.
117+
118+
subdir : str, optional
119+
The subdirectory where the jigsaw-python repository is located or will
120+
be cloned. Default is 'jigsaw-python'.
121+
122+
hash : str, optional
123+
A git hash to checkout after cloning the repository.
124+
Ignored if `clone` is False.
125+
If None and `clone` is True, the latest version will be used.
117126
"""
118127
conda_env_path = os.getenv('CONDA_PREFIX')
119128
if conda_env_path is None:
@@ -145,19 +154,25 @@ def build_jigsaw(logger=None, clone=False):
145154

146155
# remove conda jigsaw and jigsaw-python
147156
t0 = time.time()
148-
commands = f'{activate_env}conda remove -y --force-remove jigsaw jigsawpy'
157+
commands = (
158+
f'{activate_env}'
159+
f'pip uninstall -y jigsawpy; '
160+
f'conda remove -y --force-remove jigsaw jigsawpy'
161+
)
149162
try:
150163
check_call(commands, logger=logger, executable='/bin/bash', shell=True)
151164
except subprocess.CalledProcessError:
152165
# ignore errors if not installed
153166
pass
154167

155168
if clone:
156-
commands = (
157-
f'{activate_env}'
158-
f'rm -rf jigsaw-python && '
159-
f'git clone https://github.com/dengwirda/jigsaw-python.git'
160-
)
169+
url = 'https://github.com/dengwirda/jigsaw-python.git'
170+
commands = f'{activate_env}rm -rf {subdir} && git clone {url} {subdir}'
171+
if hash is not None:
172+
commands += (
173+
f' && cd {subdir} && '
174+
f'git -c advice.detachedHead=false checkout {hash}'
175+
)
161176
check_call(commands, logger=logger, executable='/bin/bash', shell=True)
162177

163178
# add build tools to deployment env, not polaris env
@@ -184,7 +199,7 @@ def build_jigsaw(logger=None, clone=False):
184199
# Build JIGSAW
185200
commands = (
186201
f'{activate_env}'
187-
f'cd jigsaw-python/external/jigsaw && '
202+
f'cd {subdir}/external/jigsaw && '
188203
f'rm -rf tmp && '
189204
f'mkdir tmp && '
190205
f'cd tmp && '
@@ -197,7 +212,7 @@ def build_jigsaw(logger=None, clone=False):
197212
# Set up JIGSAW-Python
198213
commands = (
199214
f'{activate_env}'
200-
f'cd jigsaw-python && '
215+
f'cd {subdir} && '
201216
f'rm -rf jigsawpy/_bin jigsawpy/_lib && '
202217
f'cp -r external/jigsaw/bin/ jigsawpy/_bin && '
203218
f'cp -r external/jigsaw/lib/ jigsawpy/_lib'
@@ -207,15 +222,16 @@ def build_jigsaw(logger=None, clone=False):
207222
print('Installing JIGSAW-Python\n')
208223
commands = (
209224
f'{activate_env}'
210-
f'cd jigsaw-python && '
225+
f'cd {subdir} && '
211226
f'python -m pip install --no-deps --no-build-isolation -e . && '
212227
f'cp jigsawpy/_bin/* ${{CONDA_PREFIX}}/bin'
213228
)
214229
check_call(commands, logger=logger, executable='/bin/bash', shell=True)
215230

216231
t1 = time.time()
217232
total = int(t1 - t0 + 0.5)
218-
message = f'JIGSAW install took {total:.1f} s.'
233+
minutes, seconds = divmod(total, 60)
234+
message = f'JIGSAW install took {minutes} min {seconds} s.'
219235
if logger is None:
220236
print(message)
221237
else:
@@ -235,10 +251,30 @@ def main_build_jigsaw():
235251
dest='clone',
236252
action='store_true',
237253
help=(
238-
'Clone the jigsaw-python repository into the jigsaw-python dir '
239-
'for you. Otherwise, you must already have cloned it.'
254+
'Clone the jigsaw-python repository into the directory specified '
255+
'with --subdir for you. If --clone is not specified, you must '
256+
'already have cloned it.'
257+
),
258+
)
259+
parser.add_argument(
260+
'--subdir',
261+
dest='subdir',
262+
default='jigsaw-python',
263+
help=(
264+
'A subdirectory of the current work directory where the '
265+
'jigsaw-python repository is located or will be cloned. Default '
266+
'is "jigsaw-python".'
267+
),
268+
)
269+
parser.add_argument(
270+
'--hash',
271+
dest='hash',
272+
help=(
273+
'A git hash to checkout after cloning the repository. '
274+
'Ignored if --clone is not provided. If --clone is provided and '
275+
'--hash is not, the latest version will be used.'
240276
),
241277
)
242278
args = parser.parse_args()
243279

244-
build_jigsaw(clone=args.clone)
280+
build_jigsaw(clone=args.clone, subdir=args.subdir, hash=args.hash)

0 commit comments

Comments
 (0)