-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Error handling during conversion; fixed env bug to allow vips to be a…
…ccessible from subprocess (#22) * Implemented run_wrapper() method to handle verbosity and fix env bug * use wrapper in convert methods; handle errors gracefully * Skip images that fail * Linted code * Bump v0.1.2
- Loading branch information
Showing
4 changed files
with
66 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
|
||
setup( | ||
name="vsi2tif", | ||
version="0.1.1", | ||
version="0.1.2", | ||
author="André Pedersen, Sebastian Krossa, Erik Smistad", | ||
author_email="[email protected]", | ||
license="MIT", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import logging | ||
import os | ||
import subprocess as sp | ||
|
||
|
||
def run_wrapper(cmd: str, verbose: int = 0, max_mem: int = 4): | ||
# merge current environment with the new BF_MAX_MEM variable | ||
env = os.environ.copy() | ||
env["BF_MAX_MEM"] = f"{max_mem}g" | ||
|
||
if verbose == 0: | ||
# capture the output silently when verbose is disabled | ||
result = sp.run(cmd, shell=True, env=env, capture_output=True, text=True) | ||
|
||
# check if the process failed | ||
if result.returncode != 0: | ||
raise RuntimeError(f"Command failed with error: {result.stderr}") | ||
|
||
else: | ||
# stream output in real-time if verbose is enabled | ||
process = sp.Popen(cmd, shell=True, env=env, stdout=sp.PIPE, stderr=sp.PIPE, text=True) | ||
|
||
# stream stdout in real-time | ||
for stdout_line in iter(process.stdout.readline, ""): | ||
logging.info(stdout_line.strip()) # Log each line of output | ||
process.stdout.close() | ||
|
||
# wait for process to finish | ||
process.wait() | ||
|
||
# check if the process failed | ||
if process.returncode != 0: | ||
stderr_output = process.stderr.read().strip() | ||
process.stderr.close() | ||
raise RuntimeError(f"Command failed with error: {stderr_output}") | ||
|
||
process.stderr.close() |