Skip to content

Commit

Permalink
fix: docker
Browse files Browse the repository at this point in the history
  • Loading branch information
YaoYinYing committed Sep 24, 2024
1 parent 47f3e6f commit 0aafc69
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/rosetta_finder/rosetta_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def from_filename(cls, dirname: str, filename: str):
Raises:
ValueError: If the filename does not match the expected pattern.
"""
# Regular expression to parse the filename
# Regular expression to parse the filenam
regex = r"""
^(?P<binary_name>.+?)\.
((?P<mode>default|mpi|static|cxx11threadserialization)\.)?
Expand Down Expand Up @@ -204,12 +204,21 @@ def main() -> None:
Returns:
None
"""
import shutil

bin_str = sys.argv[1]
bin_path = sys.argv[2] if len(sys.argv) > 2 else None

which_bin = shutil.which(bin_str)

if which_bin and os.path.isfile(which_bin):
# dockerized
print(which_bin)
return

finder = RosettaFinder(bin_path)
binary_path = finder.find_binary(bin_str)
if not os.path.isfile(binary_path.full_path):
raise FileNotFoundError(f"Binary '{binary_path.full_path}' does not exist.")

print(binary_path.full_path)
# return binary_path.full_path
43 changes: 43 additions & 0 deletions tests/test_whichrosetta.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,49 @@ def test_integration_whichrosetta_success(self):
# Clean up the temporary directory
shutil.rmtree(temp_dir)

def test_dockerized_whichrosetta_success(self):
# Create a temporary directory to act as ROSETTA_BIN
temp_dir = tempfile.mkdtemp()
try:
# Create a mock binary file
binary_name = "rosetta_scripts"
binary_path = os.path.join(temp_dir, binary_name)

with open(binary_path, "w") as f:
f.write("# Mock Rosetta binary")

os.chmod(binary_path, 755)

# Set the ROSETTA_BIN environment variable to the temp directory
env = os.environ.copy()
env["PATH"] = temp_dir + ":" + env["PATH"]

for key in os.environ.keys():
if "ROSETTA" in key:
del env[key]

# Patch sys.platform to 'linux'
with patch("sys.platform", "linux"):
# Invoke the whichrosetta command
result = subprocess.run(
["whichrosetta", "rosetta_scripts"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
env=env,
)

# Check that the command was successful
print(result.stderr)
print(result.stdout)
self.assertEqual(result.returncode, 0)
expected_output = f"{binary_path}\n"
self.assertEqual(result.stdout, expected_output)
self.assertEqual(result.stderr, "")
finally:
# Clean up the temporary directory
shutil.rmtree(temp_dir)

def test_integration_whichrosetta_not_found(self):
# Create a temporary directory to act as ROSETTA_BIN
temp_dir = tempfile.mkdtemp()
Expand Down

0 comments on commit 0aafc69

Please sign in to comment.