Skip to content

Commit

Permalink
refactor: improved libvips installation and error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
acycliq committed Nov 7, 2024
1 parent 20690de commit 1e2d22c
Showing 1 changed file with 13 additions and 19 deletions.
32 changes: 13 additions & 19 deletions pciSeq/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,25 @@ def install(package):


def install_libvips():
subprocess.check_call("apt-get update", shell=True)
subprocess.check_call("apt-get install", shell=True)
subprocess.check_call(['apt-get', 'install', '-y', 'libvips'],
stdout=open(os.devnull, 'wb'), stderr=subprocess.STDOUT)
subprocess.check_call([sys.executable, "-m", "pip", "install", "pyvips"])

#
# def check_libvips(logger):
# confirm = confirm_prompt('Install libvips?')
# if confirm:
# install_libvips()
# else:
# print('>>>> libvips not installed')
# return confirm

try:
subprocess.check_call("apt-get update", shell=True)
subprocess.check_call("apt-get install -y libvips", shell=True) # Combined command with -y flag
subprocess.check_call([sys.executable, "-m", "pip", "install", "pyvips"])
return True
except subprocess.CalledProcessError as e:
init_logger.error(f"Failed to install libvips: {str(e)}")
return False

def check_libvips():
try:
import pyvips
status = True
except OSError:
status = False
return True
except ImportError: # More specific exception
init_logger.warning('libvips not found. Please install it manually or run with sudo privileges.')
return False
except Exception as err:
init_logger.error(f"Unexpected error checking libvips: {str(err)}")
raise
return status


if check_libvips():
Expand Down

0 comments on commit 1e2d22c

Please sign in to comment.