Skip to content

Commit

Permalink
Merge pull request #233 from NOAA-GFDL/fix-executable-permission
Browse files Browse the repository at this point in the history
 Fix making checkout script executable before running
  • Loading branch information
singhd789 authored Oct 30, 2024
2 parents 12b35f0 + 8f655ce commit ba3f07c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
7 changes: 4 additions & 3 deletions fre/make/createCheckout.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ def checkout_create(yamlfile,platform,target,no_parallel_checkout,jobs,execute,v
freCheckout = checkout.checkout("checkout.sh",srcDir)
freCheckout.writeCheckout(modelYaml.compile.getCompileYaml(),jobs,pc)
freCheckout.finish(pc)
click.echo("\nCheckout script created in "+ srcDir + "/checkout.sh \n")
# Make checkout script executable
os.chmod(srcDir+"/checkout.sh", 0o744)
print("\nCheckout script created in "+ srcDir + "/checkout.sh \n")

# Run the checkout script
if run == True:
Expand All @@ -85,7 +87,6 @@ def checkout_create(yamlfile,platform,target,no_parallel_checkout,jobs,execute,v
else:
print("\nCheckout script PREVIOUSLY created in "+ srcDir + "/checkout.sh \n")
if run == True:
os.chmod(srcDir+"/checkout.sh", 0o744)
try:
subprocess.run(args=[srcDir+"/checkout.sh"], check=True)
except:
Expand All @@ -102,7 +103,7 @@ def checkout_create(yamlfile,platform,target,no_parallel_checkout,jobs,execute,v
freCheckout = checkout.checkoutForContainer("checkout.sh", srcDir, tmpDir)
freCheckout.writeCheckout(modelYaml.compile.getCompileYaml(),jobs,pc)
freCheckout.finish(pc)
click.echo("\nCheckout script created at " + tmpDir + "/checkout.sh" + "\n")
print("\nCheckout script created at " + tmpDir + "/checkout.sh" + "\n")


if __name__ == "__main__":
Expand Down
3 changes: 0 additions & 3 deletions fre/make/gfdlfremake/checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,6 @@ def finish (self,pc):
else:
self.checkoutScript.close()

# Make checkout script executable
os.chmod(self.src+"/"+self.fname, 0o744)

## TODO: batch script building
def run (self):
"""
Expand Down
42 changes: 41 additions & 1 deletion fre/tests/test_fre_make_cli.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
''' test "fre make" calls '''

from click.testing import CliRunner

from pathlib import Path
import os
from fre import fre

runner = CliRunner()
Expand All @@ -20,3 +21,42 @@ def test_cli_fre_make_opt_dne():
''' fre make optionDNE '''
result = runner.invoke(fre.fre, args=["make", "optionDNE"])
assert result.exit_code == 2

def test_cli_fre_make_create_checkout_baremetal():
''' fre make create-checkout -y am5.yaml -p ncrc5.intel23 -t debug'''
# Set paths and click options
test_dir = Path("fre/tests")
yamlfile = Path("fre/make/tests/AM5_example/")
platform = "ncrc5.intel23"
target = "debug"

# Create output path to test that files exist
out_path=f"{test_dir}/fremake_out"
Path(out_path).mkdir(parents=True,exist_ok=True)

# Set HOME for modelRoot location (output location) in fre make
os.environ["HOME"]=str(Path(out_path))

# run create-checkout
result = runner.invoke(fre.fre, args=["make", "create-checkout", "-y", f"{yamlfile}/am5.yaml", "-p", platform, "-t", target])

# Check for successful command, creation of checkout script, and that script is executable (os.access - checks is file has specific access mode, os.X_OK - checks executable permission)
assert all ([result.exit_code == 0,
Path(f"{out_path}/fremake_canopy/test/am5/src/checkout.sh").exists(),
os.access(Path(f"{out_path}/fremake_canopy/test/am5/src/checkout.sh"), os.X_OK)])

def test_cli_fre_make_create_checkout_container():
''' fre make create-checkout -y am5.yaml -p hpcme.2023 -t debug'''
# Set paths and click options
test_dir = Path("fre/tests")
yamlfile = Path("fre/make/tests/AM5_example/")
platform = "hpcme.2023"
target = "debug"

# run create-checkout
result = runner.invoke(fre.fre, args=["make", "create-checkout", "-y", f"{yamlfile}/am5.yaml", "-p", platform, "-t", target])

# Check for successful command, creation of checkout script, and that script is executable (os.access - checks is file has specific access mode, os.X_OK - checks executable permission)
assert all ([result.exit_code == 0,
Path(f"tmp/{platform}/checkout.sh").exists(),
os.access(Path(f"tmp/{platform}/checkout.sh"), os.X_OK) == False ])

0 comments on commit ba3f07c

Please sign in to comment.