Conversation
nmaarnio
reviewed
Mar 18, 2025
Collaborator
There was a problem hiding this comment.
I think using context managers is a pretty good idea. However, I would make it a bit simpler than in your implementation and get rid of string parameters. I propose the following structure:
I propose using helper classes like these:
class ProgressLog():
@contextmanager
@staticmethod
def reading_input_files():
# typer.echo(f"Progress: {progress_at_start}%")
typer.echo("Opening input files....")
yield
typer.echo("✅ Input files read\n")
@contextmanager
@staticmethod
def running_algorithm():
typer.echo("Running algorithm...")
yield
typer.echo("✅ Algorithm run succesfully\n")
@contextmanager
@staticmethod
def saving_output_files():
# typer.echo(f"Progress: {progress_at_start}%")
typer.echo("Saving output files...")
yield
typer.echo("✅ Output files saved\n")
@staticmethod
def finish():
typer.echo("✅ Algorithm execution finished succesfully\n")
class ResultSender():
@staticmethod
def send_dict_as_json(dictionary: dict):
typer.echo(f"Results: {json.dumps(dictionary)}")
here is one example cli func with this proposed structure:
# NORMALITY TEST RASTER
@app.command()
def normality_test_raster_cli(input_raster: INPUT_FILE_OPTION, bands: Optional[List[int]] = None):
"""Compute Shapiro-Wilk test for normality on the input raster data."""
from eis_toolkit.exploratory_analyses.normality_test import normality_test_array
with ProgressLog.reading_input_files():
with rasterio.open(input_raster) as raster:
data = raster.read()
if len(bands) == 0:
bands = None
with ProgressLog.running_algorithm():
results_dict = normality_test_array(data=data, bands=bands, nodata_value=raster.nodata)
ResultSender.send_dict_as_json(results_dict)
ProgressLog.finish()
Collaborator
|
I can take care of adjusting EIS QGIS Plugin to these new messages since I already started tinkering with that |
0b89ba2 to
597116d
Compare
Handle savepath printing in method saving_output_files
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I edited the CLI functions so that they now provide user with messages on their progress. I wanted to avoid hardcoding the messages in the CLI functions but at the same time to make sure they are handed out at correct times. Therefore I used the
contextlib.contextmanager. @nmaarnio Let me know what you think.