Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debugging Logs for Definitions From CSV #94

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
long_description=readme,
long_description_content_type='text/markdown',
name="tableau_utilities",
version="2.2.11",
version="2.2.12",
requires_python=">=3.8",
packages=[
'tableau_utilities',
Expand Down
8 changes: 7 additions & 1 deletion tableau_utilities/scripts/gen_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from tableau_utilities.tableau_server.tableau_server import TableauServer


def load_csv_with_definitions(file=None):
def load_csv_with_definitions(file=None, debugging_logs=False):
""" Returns a dictionary with the definitions from a csv. The columns are expected to include column_name and description

Args:
Expand All @@ -35,6 +35,12 @@ def load_csv_with_definitions(file=None):
if str(column['description']) != 'nan':
definitions_mapping[column['column_name']] = column['description']

if debugging_logs:
print(column['column_name'], column['description'])

if debugging_logs:
print(definitions_mapping)

return definitions_mapping


Expand Down
29 changes: 22 additions & 7 deletions tableau_utilities/scripts/merge_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
from tableau_utilities.general.cli_styling import Color, Symbol
from tableau_utilities.scripts.gen_config import load_csv_with_definitions, generate_config

# Print Styling
color = Color()
symbol = Symbol()

def read_file(file_path):
""" Read a JSON file to a dictionary
Expand Down Expand Up @@ -31,7 +34,7 @@ def write_file(file_name, config, debugging_logs=False):
print('CONFIG PATH:', file_name)


def add_definitions_mapping(config, definitions_mapping):
def add_definitions_mapping(config, definitions_mapping, debugging_logs=False):
""" Adds definitions from a mapping to the config. Chooses the definition from the mapping if needed

Args:
Expand All @@ -40,8 +43,15 @@ def add_definitions_mapping(config, definitions_mapping):

"""
for column, definition in definitions_mapping.items():
if len(definition) > 0 and column in config:
has_definition = len(definition) > 0
in_config = column in config

if debugging_logs:
print(column, has_definition, in_config)

if has_definition and in_config:
config[column]['description'] = definition

return config


Expand Down Expand Up @@ -165,21 +175,26 @@ def merge_configs(args, server=None):
debugging_logs = args.debugging_logs
existing_config = args.existing_config

# Print Styling
color = Color()
symbol = Symbol()

# Merge 2 configs
if merge_with == 'config':
read_merge_write(existing_config_path, additional_config_path, file_name, debugging_logs)

# Merge a config with a definitions csv
elif merge_with == 'csv':
# Log paths
if debugging_logs:
print(f'{color.fg_yellow}EXISTING CONFIG PATH {symbol.arrow_r} '
f'{color.fg_grey}{existing_config}{color.reset}')
print(f'{color.fg_yellow}DEFINITIONS CSV PATH {symbol.arrow_r} '
f'{color.fg_grey}{definitions_csv_path}{color.reset}')

# Read files
existing_config = read_file(existing_config)
definitions_mapping = load_csv_with_definitions(file=definitions_csv_path)
definitions_mapping = load_csv_with_definitions(file=definitions_csv_path, debugging_logs=debugging_logs)

# Merge
new_config = add_definitions_mapping(existing_config, definitions_mapping)
new_config = add_definitions_mapping(existing_config, definitions_mapping, debugging_logs)
# Sort and write the merged config
new_config = sort_config(new_config, debugging_logs)
write_file(file_name=file_name, config=new_config, debugging_logs=debugging_logs)
Expand Down