Skip to content

Commit

Permalink
Merge pull request #9 from Qualytics/sc-15320/cli-bug-related-to-tick…
Browse files Browse the repository at this point in the history
…et-66302957

Cli bug related to ticket 66302957
  • Loading branch information
shindiogawa authored Jan 2, 2024
2 parents 3ffb61e + 21168e4 commit e6bba7b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.1.5
current_version = 0.1.6
commit = True
tag = True
tag_name = {new_version}
Expand Down
23 changes: 16 additions & 7 deletions qualytics/qualytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from typing_extensions import Annotated
from croniter import croniter

__version__ = "0.1.5"
__version__ = "0.1.6"

app = typer.Typer()

Expand Down Expand Up @@ -83,6 +83,10 @@ def _get_default_headers(token):


def distinct_file_content(file_path):
# Check if the file exists before opening it
if not os.path.exists(file_path):
return # Return early if the file doesn't exist

with open(file_path, 'r') as file:
# Using a set to automatically get distinct lines
distinct_lines = set(file.readlines())
Expand All @@ -93,6 +97,11 @@ def distinct_file_content(file_path):


def log_error(message, file_path):
# Check if the file exists before opening it
if not os.path.exists(file_path):
with open(file_path, 'w'):
pass # Create an empty file if it doesn't exist

with open(file_path, 'a') as file:
file.write(message + '\n')
file.flush()
Expand Down Expand Up @@ -293,7 +302,7 @@ def checks_import(datastore: str = typer.Option(..., "--datastore",
config = load_config()
base_url = validate_and_format_url(config['url'])
token = is_token_valid(config['token'])

error_log_path = f"/errors-{datetime.now().strftime('%Y-%m-%d')}.log"
if token:
with open(input_file, 'r') as f:
all_quality_checks = json.load(f)
Expand All @@ -318,7 +327,7 @@ def checks_import(datastore: str = typer.Option(..., "--datastore",
f"[bold red] Profile `{quality_check['container']['name']}` was not found in datastore id: {datastore_id}[/bold red]")
log_error(
f"Profile `{quality_check['container']['name']}` of quality check {quality_check['id']} was not found in datastore id: {datastore_id}",
BASE_PATH + "/errors.log")
BASE_PATH + error_log_path)

if container_id:
description = f"[from quality check id: {quality_check['id']} - main datastore id: {datastore_id}]"
Expand Down Expand Up @@ -357,7 +366,7 @@ def checks_import(datastore: str = typer.Option(..., "--datastore",
print(f"[bold red]Error updating quality check id: {quality_check_id} [/bold red]")
log_error(
f"Error updating quality check id: {quality_check_id} on datastore id: {datastore_id}. Details: {response.text}",
BASE_PATH + "/errors.log")
BASE_PATH + error_log_path)
# If a quality check does not contain the description:
# 1. We try to create quality check and verify for conflict
# a. If we notify a conflict, it will update the check
Expand All @@ -379,19 +388,19 @@ def checks_import(datastore: str = typer.Option(..., "--datastore",
print(f"[bold red]Error updating quality check id: {match.group(1)} [/bold red]")
log_error(
f"Error updating quality check id: {match.group(1)} on datastore id: {datastore_id}. Details: {response.text}",
BASE_PATH + "/errors.log")
BASE_PATH + error_log_path)
elif response.status_code == 200:
print(
f"[bold green]Quality check id: {response.json()['id']} for container: {quality_check['container']['name']} created successfully[/bold green]")
total_created_checks += 1
else:
log_error(
f"Error creating quality check for datastore id: {datastore_id}. Details: {response.text}",
BASE_PATH + "/errors.log")
BASE_PATH + error_log_path)

print(f"Updated a total of {total_updated_checks} quality checks.")
print(f"Created a tottal of {total_created_checks} quality checks.")
distinct_file_content(BASE_PATH + "/errors.log")
distinct_file_content(BASE_PATH + error_log_path)


@schedule_app.command("export-metadata")
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
'GitHub': 'https://github.com/Qualytics/qualytics-cli',
'Userguide': 'https://qualytics.github.io/userguide/'
}
__version__ = "0.1.5"
__version__ = "0.1.6"
setup(
name="qualytics-cli",
packages=find_packages(),
Expand Down

0 comments on commit e6bba7b

Please sign in to comment.