Skip to content

Commit

Permalink
chore: remove tabs (DEV-3043) (#661)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nora-Olivia-Ammann committed Nov 30, 2023
1 parent 107b1b0 commit 286abf8
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 66 deletions.
4 changes: 2 additions & 2 deletions src/dsp_tools/commands/excel2json/lists.py
Expand Up @@ -58,12 +58,12 @@ def expand_lists_from_excel(
_list["nodes"] = returned_lists_section[0]["nodes"]
new_lists.append(_list)
print(
f"\tThe list '{_list['name']}' contains a reference to the folder '{foldername}'. The Excel "
f" The list '{_list['name']}' contains a reference to the folder '{foldername}'. The Excel "
f"files therein have been temporarily expanded into the 'lists' section of your project."
)
except BaseError as err:
raise UserError(
f"\tWARNING: The list '{_list['name']}' contains a reference to the folder '{foldername}', but a "
f" WARNING: The list '{_list['name']}' contains a reference to the folder '{foldername}', but a "
f"problem occurred while trying to expand the Excel files therein into the 'lists' section of "
f"your project: {err.message}"
) from None
Expand Down
58 changes: 30 additions & 28 deletions src/dsp_tools/commands/project/create/project_create.py
Expand Up @@ -60,7 +60,7 @@ def _create_project_on_server(
project_remote: Project = try_network_action(project_local.read)
proj_designation = f"'{project_remote.shortname}' ({project_remote.shortcode})"
msg = f"Project {proj_designation} already exists on the DSP server. Updating it..."
print(f"\tWARNING: {msg}")
print(f" WARNING: {msg}")
logger.warning(msg)
# try to update the basic info
project_remote, _ = _update_basic_info_of_project(
Expand Down Expand Up @@ -94,7 +94,7 @@ def _create_project_on_server(
err_msg = f"Cannot create project '{shortname}' ({shortcode}) on DSP server."
logger.error(err_msg, exc_info=True)
raise UserError(err_msg) from None
print(f"\tCreated project '{project_remote.shortname}' ({project_remote.shortcode}).")
print(f" Created project '{project_remote.shortname}' ({project_remote.shortcode}).")
logger.info(f"Created project '{project_remote.shortname}' ({project_remote.shortcode}).")
return project_remote, success

Expand Down Expand Up @@ -136,7 +136,7 @@ def _update_basic_info_of_project(
try:
project_remote: Project = try_network_action(project.update)
if verbose:
print(f"\tUpdated project '{shortname}' ({shortcode}).")
print(f" Updated project '{shortname}' ({shortcode}).")
logger.info(f"Updated project '{shortname}' ({shortcode}).")
return project_remote, True
except BaseError:
Expand Down Expand Up @@ -190,7 +190,7 @@ def _create_groups(
# if the group already exists, add it to "current_project_groups" (for later usage), then skip it
if remotely_existing_group := [g for g in remote_groups if g.name == group_name]:
current_project_groups[group_name] = remotely_existing_group[0]
print(f"\tWARNING: Group name '{group_name}' already exists on the DSP server. Skipping...")
print(f" WARNING: Group name '{group_name}' already exists on the DSP server. Skipping...")
logger.warning(f"Group name '{group_name}' already exists on the DSP server. Skipping...")
overall_success = False
continue
Expand All @@ -207,13 +207,13 @@ def _create_groups(
try:
group_remote: Group = try_network_action(group_local.create)
except BaseError:
print(f"\tWARNING: Unable to create group '{group_name}'.")
print(f" WARNING: Unable to create group '{group_name}'.")
logger.warning(f"Unable to create group '{group_name}'.", exc_info=True)
overall_success = False
continue

current_project_groups[str(group_remote.name)] = group_remote
print(f"\tCreated group '{group_name}'.")
print(f" Created group '{group_name}'.")
logger.info(f"Created group '{group_name}'.")

return current_project_groups, overall_success
Expand Down Expand Up @@ -256,15 +256,15 @@ def _get_group_iris_for_user(
f"User {username} cannot be added to group {full_group_name}, because such a group doesn't exist."
)
if ":" not in full_group_name and full_group_name != "SystemAdmin":
print(f"\tWARNING: {inexisting_group_msg}")
print(f" WARNING: {inexisting_group_msg}")
logger.warning(inexisting_group_msg)
success = False
continue

if full_group_name == "SystemAdmin":
sysadmin = True
if verbose:
print(f"\tAdded user '{username}' to group 'SystemAdmin'.")
print(f" Added user '{username}' to group 'SystemAdmin'.")
logger.info(f"Added user '{username}' to group 'SystemAdmin'.")
continue

Expand All @@ -273,7 +273,7 @@ def _get_group_iris_for_user(
if not project_shortname:
# full_group_name refers to a group inside the same project
if group_name not in current_project_groups:
print(f"\tWARNING: {inexisting_group_msg}")
print(f" WARNING: {inexisting_group_msg}")
logger.warning(inexisting_group_msg)
success = False
continue
Expand All @@ -288,13 +288,13 @@ def _get_group_iris_for_user(
f"User '{username}' is referring to the group {full_group_name} that "
f"exists on the DSP server, but no groups could be retrieved from the DSP server."
)
print(f"\tWARNING: {err_msg}")
print(f" WARNING: {err_msg}")
logger.warning(err_msg, exc_info=True)
success = False
continue
existing_group = [g for g in remote_groups if g.project == current_project.iri and g.name == group_name]
if not existing_group:
print(f"\tWARNING: {inexisting_group_msg}")
print(f" WARNING: {inexisting_group_msg}")
logger.warning(inexisting_group_msg)
success = False
continue
Expand All @@ -304,7 +304,7 @@ def _get_group_iris_for_user(
raise BaseError(f"Group '{group}' has no IRI.")
group_iris.add(group.iri)
if verbose:
print(f"\tAdded user '{username}' to group '{full_group_name}'.")
print(f" Added user '{username}' to group '{full_group_name}'.")
logger.info(f"Added user '{username}' to group '{full_group_name}'.")

return group_iris, sysadmin, success
Expand Down Expand Up @@ -335,7 +335,9 @@ def _get_projects_where_user_is_admin(
for full_project_name in json_user_definition.get("projects", []):
# full_project_name has the form '[project_name]:member' or '[project_name]:admin'
if ":" not in full_project_name:
print(f"\tWARNING: Provided project '{full_project_name}' for user '{username}' is not valid. Skipping...")
print(
f" WARNING: Provided project '{full_project_name}' for user '{username}' is not valid. Skipping..."
)
logger.warning(f"Provided project '{full_project_name}' for user '{username}' is not valid. Skipping...")
success = False
continue
Expand All @@ -354,14 +356,14 @@ def _get_projects_where_user_is_admin(
f"User '{username}' cannot be added to the projects {json_user_definition['projects']} "
f"because the projects cannot be retrieved from the DSP server."
)
print(f"\tWARNING: {err_msg}")
print(f" WARNING: {err_msg}")
logger.warning(err_msg, exc_info=True)
success = False
continue
in_project_list = [p for p in remote_projects if p.shortname == project_name]
if not in_project_list:
msg = f"Provided project '{full_project_name}' for user '{username}' is not valid. Skipping..."
print(f"\tWARNING: {msg}")
print(f" WARNING: {msg}")
logger.warning(msg)
success = False
continue
Expand All @@ -370,7 +372,7 @@ def _get_projects_where_user_is_admin(
is_admin = project_role == "admin"
project_info[str(in_project.iri)] = is_admin
if verbose:
print(f"\tAdded user '{username}' as {project_role} to project '{in_project.shortname}'.")
print(f" Added user '{username}' as {project_role} to project '{in_project.shortname}'.")
logger.info(f"Added user '{username}' as {project_role} to project '{in_project.shortname}'.")

return project_info, success
Expand Down Expand Up @@ -406,7 +408,7 @@ def _create_users(
with contextlib.suppress(BaseError):
# the normal case is that this block fails
try_network_action(User(con, email=json_user_definition["email"]).read)
print(f"\tWARNING: User '{username}' already exists on the DSP server. Skipping...")
print(f" WARNING: User '{username}' already exists on the DSP server. Skipping...")
logger.warning(f"User '{username}' already exists on the DSP server. Skipping...")
overall_success = False
continue
Expand Down Expand Up @@ -448,11 +450,11 @@ def _create_users(
try:
try_network_action(user_local.create)
except BaseError:
print(f"\tWARNING: Unable to create user '{username}'.")
print(f" WARNING: Unable to create user '{username}'.")
logger.warning(f"Unable to create user '{username}'.", exc_info=True)
overall_success = False
continue
print(f"\tCreated user '{username}'.")
print(f" Created user '{username}'.")
logger.info(f"Created user '{username}'.")

return overall_success
Expand Down Expand Up @@ -562,7 +564,7 @@ def _create_ontology(
"""
# skip if it already exists on the DSP server
if onto_name in [onto.name for onto in project_ontologies]:
print(f"\tWARNING: Ontology '{onto_name}' already exists on the DSP server. Skipping...")
print(f" WARNING: Ontology '{onto_name}' already exists on the DSP server. Skipping...")
logger.warning(f"Ontology '{onto_name}' already exists on the DSP server. Skipping...")
return None

Expand All @@ -583,7 +585,7 @@ def _create_ontology(
raise UserError(f"ERROR while trying to create ontology '{onto_name}'.") from None

if verbose:
print(f"\tCreated ontology '{onto_name}'.")
print(f" Created ontology '{onto_name}'.")
logger.info(f"Created ontology '{onto_name}'.")

context.add_context(
Expand Down Expand Up @@ -730,7 +732,7 @@ def _add_resource_classes_to_remote_ontology(
"""

overall_success = True
print("\tCreate resource classes...")
print(" Create resource classes...")
logger.info("Create resource classes...")
new_res_classes: dict[str, ResourceClass] = {}
sorted_resources = _sort_resources(resclass_definitions, onto_name)
Expand All @@ -755,7 +757,7 @@ def _add_resource_classes_to_remote_ontology(
new_res_classes[str(res_class_remote.iri)] = res_class_remote
ontology_remote.lastModificationDate = last_modification_date
if verbose:
print(f"\tCreated resource class '{res_class['name']}'")
print(f" Created resource class '{res_class['name']}'")
logger.info(f"Created resource class '{res_class['name']}'")
except BaseError:
print(f"WARNING: Unable to create resource class '{res_class['name']}'.")
Expand Down Expand Up @@ -795,7 +797,7 @@ def _add_property_classes_to_remote_ontology(
a tuple consisting of the last modification date of the ontology, and the success status
"""
overall_success = True
print("\tCreate property classes...")
print(" Create property classes...")
logger.info("Create property classes...")
sorted_prop_classes = _sort_prop_classes(property_definitions, onto_name)
for prop_class in sorted_prop_classes:
Expand Down Expand Up @@ -850,7 +852,7 @@ def _add_property_classes_to_remote_ontology(
last_modification_date, _ = try_network_action(prop_class_local.create, last_modification_date)
ontology_remote.lastModificationDate = last_modification_date
if verbose:
print(f"\tCreated property class '{prop_class['name']}'")
print(f" Created property class '{prop_class['name']}'")
logger.info(f"Created property class '{prop_class['name']}'")
except BaseError:
print(f"WARNING: Unable to create property class '{prop_class['name']}'.")
Expand Down Expand Up @@ -886,7 +888,7 @@ def _add_cardinalities_to_resource_classes(
success status
"""
overall_success = True
print("\tAdd cardinalities to resource classes...")
print(" Add cardinalities to resource classes...")
logger.info("Add cardinalities to resource classes...")
switcher = {
"1": Cardinality.C_1,
Expand Down Expand Up @@ -921,7 +923,7 @@ def _add_cardinalities_to_resource_classes(
last_modification_date=last_modification_date,
)
if verbose:
print(f"\tAdded cardinality '{card_info['propname']}' to resource class '{res_class['name']}'")
print(f" Added cardinality '{card_info['propname']}' to resource class '{res_class['name']}'")
logger.info(f"Added cardinality '{card_info['propname']}' to resource class '{res_class['name']}'")
except BaseError:
err_msg = f"Unable to add cardinality '{qualified_propname}' to resource class {res_class['name']}."
Expand Down Expand Up @@ -1042,7 +1044,7 @@ def create_project(

# validate against JSON schema
validate_project(project_definition, expand_lists=False)
print("\tJSON project file is syntactically correct and passed validation.")
print(" JSON project file is syntactically correct and passed validation.")
logger.info("JSON project file is syntactically correct and passed validation.")

# rectify the "hlist" of the "gui_attributes" of the properties
Expand Down
4 changes: 2 additions & 2 deletions src/dsp_tools/commands/project/create/project_create_lists.py
Expand Up @@ -118,15 +118,15 @@ def create_lists_on_server(
"id": existing_lst[0].iri,
"nodes": new_lst["nodes"],
}
print(f"\tWARNING: List '{new_lst['name']}' already exists on the DSP server. Skipping...")
print(f" WARNING: List '{new_lst['name']}' already exists on the DSP server. Skipping...")
overall_success = False
continue

created_list, success = _create_list_node(con=con, project=project_remote, node=new_lst)
current_project_lists.update(created_list)
if not success:
overall_success = False
print(f"\tCreated list '{new_lst['name']}'.")
print(f" Created list '{new_lst['name']}'.")

return current_project_lists, overall_success

Expand Down
2 changes: 1 addition & 1 deletion src/dsp_tools/commands/project/create/project_validate.py
Expand Up @@ -306,7 +306,7 @@ def _check_cardinalities_of_circular_references(project_definition: dict[Any, An
"Please make sure that the following properties have a cardinality of 0-1 or 0-n:"
)
for error in errors:
error_message = f"{error_message}\n\t- Resource {error[0]}, property {error[1]}"
error_message = f"{error_message}\n - Resource {error[0]}, property {error[1]}"
raise BaseError(error_message)


Expand Down
8 changes: 4 additions & 4 deletions src/dsp_tools/commands/project/get.py
Expand Up @@ -70,7 +70,7 @@ def get_project(
for group in groups:
groups_obj.append(group.createDefinitionFileObj())
if verbose:
print(f"\tGot group '{group.name}'")
print(f" Got group '{group.name}'")
project_obj["groups"] = groups_obj

# get users
Expand All @@ -91,7 +91,7 @@ def get_project(
)
)
if verbose:
print(f"\tGot user '{usr.username}'")
print(f" Got user '{usr.username}'")
project_obj["users"] = users_obj

# get the lists
Expand All @@ -103,7 +103,7 @@ def get_project(
complete_list = list_root.getAllNodes()
list_obj.append(complete_list.createDefinitionFileObj())
if verbose:
print(f"\tGot list '{list_root.name}'")
print(f" Got list '{list_root.name}'")
project_obj["lists"] = list_obj

# get the ontologies
Expand All @@ -121,7 +121,7 @@ def get_project(
project_obj["ontologies"].append(ontology.createDefinitionFileObj())
prefixes.update(ontology.context.get_externals_used())
if verbose:
print(f"\tGot ontology '{name}'")
print(f" Got ontology '{name}'")

schema = "https://raw.githubusercontent.com/dasch-swiss/dsp-tools/main/src/dsp_tools/resources/schema/project.json"
outfile_content = {
Expand Down
Expand Up @@ -86,8 +86,8 @@ def _compose_problem_string_cls(self) -> str | None:
separator = "\n----------------------------\n"

def _format_cls(cls_tup: tuple[str, list[str], str]) -> str:
ids = "\n\t- " + "\n\t- ".join(cls_tup[1])
return f"\tResource Type: '{cls_tup[0]}'\n\tProblem: '{cls_tup[2]}'\n\tResource ID(s):{ids}"
ids = "\n - " + "\n - ".join(cls_tup[1])
return f" Resource Type: '{cls_tup[0]}'\n Problem: '{cls_tup[2]}'\n Resource ID(s):{ids}"

problems = [_format_cls(x) for x in self.classes]

Expand All @@ -100,8 +100,8 @@ def _compose_problem_string_props(self) -> str | None:
separator = "\n----------------------------\n"

def _format_prop(prop_tup: tuple[str, list[str], str]) -> str:
ids = "\n\t- " + "\n\t- ".join(prop_tup[1])
return f"\tProperty Name: '{prop_tup[0]}'\n\tProblem: '{prop_tup[2]}'\n\tResource ID(s):{ids}"
ids = "\n - " + "\n - ".join(prop_tup[1])
return f" Property Name: '{prop_tup[0]}'\n Problem: '{prop_tup[2]}'\n Resource ID(s):{ids}"

problems = [_format_prop(x) for x in self.properties]
return "The following resource(s) have invalid property type(s):\n\n" + separator.join(problems)
Expand Down
8 changes: 4 additions & 4 deletions test/e2e/commands/xmlupload/test_xmlupload.py
Expand Up @@ -33,10 +33,10 @@ def test_error_on_nonexistant_onto_name(self) -> None:
r"\nSome property and/or class type\(s\) used in the XML are unknown\:\n\n"
r"---------------------------------------\n\n"
r"The following resource\(s\) have an invalid resource type\:\n\n"
r"\tResource Type\: '\:minimalResource'\n"
r"\tProblem\: 'Unknown ontology prefix'\n"
r"\tResource ID\(s\)\:\n"
r"\t- the_only_resource\n\n"
r" Resource Type\: '\:minimalResource'\n"
r" Problem\: 'Unknown ontology prefix'\n"
r" Resource ID\(s\)\:\n"
r" - the_only_resource\n\n"
r"---------------------------------------\n\n"
)
with self.assertRaisesRegex(UserError, expected):
Expand Down

0 comments on commit 286abf8

Please sign in to comment.