Skip to content

Commit

Permalink
changed list directory files implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
FrederickDeny committed Mar 7, 2024
1 parent f1a7d48 commit 1e584bf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
21 changes: 19 additions & 2 deletions e4s_cl/cf/containers/barebones.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pathlib import Path
from typing import List, Union, Optional
from e4s_cl import logger, BAREBONES_SCRIPT, BAREBONES_LIBRARY_DIR
from e4s_cl.util import run_subprocess, create_symlink, empty_dir, mkdirp, list_directory_sofiles
from e4s_cl.util import run_subprocess, create_symlink, empty_dir, mkdirp, list_directory_files
from e4s_cl.cf.libraries import cache_libraries
from e4s_cl.cf.containers import Container, FileOptions, BackendNotAvailableError
from e4s_cl.cf.wi4mpi import wi4mpi_root
Expand Down Expand Up @@ -66,6 +66,22 @@ def _format():

self.env.update({"BAREBONES_BIND": ','.join(_format())})


def list_directory_sofiles(self, path: Path):
"""Lists all the so files of a directory.
Args:
path (Path): path of the directory list the so files of.
Returns:
A list of paths of the so files in the given directory.
"""
file_paths = list_directory_files(path)
for file_path in file_paths:
if '.so' in file_path.suffixes: # Check if it is a library file
file_paths.append(file_path.absolute())
return file_paths

def _prepare(self, command: List[str], overload: bool = True) -> List[str]:
"""
Return the command to run in a list of string
Expand All @@ -74,8 +90,9 @@ def _prepare(self, command: List[str], overload: bool = True) -> List[str]:
# Chech the environment for the use of Wi4MPI
wi4mpi_install_dir = wi4mpi_root()
# If WI4MPI is to be used, we don't preload the mpi's libraries
import pdb;pdb.set_trace()
if wi4mpi_install_dir is None:
to_be_preloaded = list_directory_sofiles(Path(BAREBONES_LIBRARY_DIR))
to_be_preloaded = self.list_directory_sofiles(Path(BAREBONES_LIBRARY_DIR))
for file_path in to_be_preloaded:
self.add_ld_preload(str(file_path))
self.env.update(
Expand Down
11 changes: 5 additions & 6 deletions e4s_cl/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,19 +311,18 @@ def parse_bool(value, additional_true=None, additional_false=None):
raise TypeError
return bool(value)

def list_directory_sofiles(path: Path):
"""Lists all the so files of a directory.
def list_directory_files(path: Path):
"""Lists all the files of a directory.
Args:
path (Path): path of the directory list the so files of.
path (Path): path of the directory list the files of.
Returns:
A list of paths of the so files in the given directory.
A list of paths of the files in the given directory.
"""
file_paths = []
for file_path in path.iterdir():
if '.so' in file_path.suffixes: # Check if it is a library file
file_paths.append(file_path.absolute())
file_paths.append(file_path)
return file_paths

def empty_dir(path: Path):
Expand Down

0 comments on commit 1e584bf

Please sign in to comment.