Skip to content

Commit 881079d

Browse files
committed
add constants in setup.py for image name
1 parent c5640a1 commit 881079d

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

setup.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,31 @@
55
from setuptools import setup, find_namespace_packages
66

77

8+
# Container image constants - single source of truth for image names
9+
DOCKER_IMAGE_NAME = "ants-nidm_bidsapp"
10+
DOCKER_IMAGE_TAG = "latest"
11+
DOCKER_IMAGE = f"{DOCKER_IMAGE_NAME}:{DOCKER_IMAGE_TAG}"
12+
SINGULARITY_IMAGE_NAME = f"{DOCKER_IMAGE_NAME}.sif"
13+
14+
815
def build_docker():
916
"""Build Docker container"""
1017
print("Building Docker image...")
1118
try:
12-
subprocess.run(["docker", "build", "-t", "ants-nidm_bidsapp:latest", "."], check=True)
13-
print("Docker image built successfully: ants-nidm_bidsapp:latest")
19+
subprocess.run(["docker", "build", "-t", DOCKER_IMAGE, "."], check=True)
20+
print(f"Docker image built successfully: {DOCKER_IMAGE}")
1421
except subprocess.CalledProcessError as e:
1522
print(f"Docker build failed: {e}")
1623
return False
1724
return True
1825

1926

20-
def docker_to_singularity(docker_image="ants-nidm_bidsapp:latest", output_path=None):
27+
def docker_to_singularity(docker_image=DOCKER_IMAGE, output_path=None):
2128
"""Convert Docker image to Singularity container"""
2229
print(f"Converting Docker image {docker_image} to Singularity...")
2330

2431
# Use custom output path if provided, otherwise use default
25-
output_file = output_path if output_path else "ants-nidm_bidsapp.sif"
32+
output_file = output_path if output_path else SINGULARITY_IMAGE_NAME
2633
output_file = str(Path(output_file).resolve())
2734

2835
try:
@@ -59,7 +66,7 @@ def build_singularity(output_path=None):
5966
):
6067
print("\nDetected Apptainer on cluster environment.")
6168
print("For cluster environments, please build directly with apptainer:")
62-
print("apptainer build --fakeroot ants-nidm_bidsapp.sif Singularity\n")
69+
print(f"apptainer build --fakeroot {SINGULARITY_IMAGE_NAME} Singularity\n")
6370
return False
6471
elif (
6572
subprocess.run(["which", "singularity"], capture_output=True).returncode == 0
@@ -70,7 +77,7 @@ def build_singularity(output_path=None):
7077
return False
7178

7279
# Use custom output path if provided, otherwise use default
73-
output_file = output_path if output_path else "ants-nidm_bidsapp.sif"
80+
output_file = output_path if output_path else SINGULARITY_IMAGE_NAME
7481
output_file = str(Path(output_file).resolve())
7582

7683
# Build command
@@ -92,9 +99,9 @@ def build_singularity(output_path=None):
9299
except subprocess.CalledProcessError as e:
93100
print(f"Build failed: {e}")
94101
print("\nFor cluster environments, please build directly with apptainer:")
95-
print("apptainer build --remote ants-nidm_bidsapp.sif Singularity")
102+
print(f"apptainer build --remote {SINGULARITY_IMAGE_NAME} Singularity")
96103
print("or")
97-
print("apptainer build --fakeroot ants-nidm_bidsapp.sif Singularity")
104+
print(f"apptainer build --fakeroot {SINGULARITY_IMAGE_NAME} Singularity")
98105
return False
99106

100107

@@ -126,7 +133,7 @@ def print_usage():
126133
print("\nOther Commands:")
127134
print(" python setup.py --init-git - Initialize git submodules")
128135
print("\nNote: For HPC environments without Docker, use 'singularity' command directly:")
129-
print(" apptainer build --fakeroot ants-nidm_bidsapp.sif Singularity")
136+
print(f" apptainer build --fakeroot {SINGULARITY_IMAGE_NAME} Singularity")
130137
print("\nFor more information, run: python setup.py --help")
131138

132139

0 commit comments

Comments
 (0)