Skip to content

Commit

Permalink
fix linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel-VM committed Feb 11, 2025
1 parent c3b16f6 commit 82fef8c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
1 change: 0 additions & 1 deletion relecov_tools/assets/schema_utils/jsonschema_draft.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import rich.console

import relecov_tools.utils
import pkg_resources
import jsonschema
from jsonschema import Draft202012Validator

Expand Down
22 changes: 14 additions & 8 deletions relecov_tools/build_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
force_terminal=relecov_tools.utils.rich_force_colors(),
)


# TODO: implement descriptive stats in a dataframe summarizing number of properties, type etc.
class SchemaBuilder:
def __init__(
Expand All @@ -54,16 +55,20 @@ def __init__(

# Validate output folder creation
if not out_dir:
self.output_folder = relecov_tools.utils.prompt_create_outdir(path=None, out_dir=None)
self.output_folder = relecov_tools.utils.prompt_create_outdir(
path=None, out_dir=None
)
else:
self.output_folder = os.path.abspath(out_dir)
if not os.path.exists(self.output_folder):
self.output_folder = relecov_tools.utils.prompt_create_outdir(path=None, out_dir=out_dir)
self.output_folder = relecov_tools.utils.prompt_create_outdir(
path=None, out_dir=out_dir
)

# Get version option
if not version:
# If not defined, then ask via prompt
self.version = relecov_tools.utils.prompt_text(
self.version = relecov_tools.utils.prompt_text(
"Write the desired version using semantic versioning:"
)
self.version = version
Expand Down Expand Up @@ -162,7 +167,7 @@ def validate_database_definition(self, json_data):
missing_features.append(feature)

# Summarize validation
if len(missing_features) > 0 :
if len(missing_features) > 0:
return missing_features
else:
return None
Expand Down Expand Up @@ -228,8 +233,7 @@ def create_schema_draft_template(self):
"""
draft_template = (
relecov_tools.assets.schema_utils.jsonschema_draft.create_draft(
draft_version=self.draft_version,
required_items=True
draft_version=self.draft_version, required_items=True
)
)
return draft_template
Expand Down Expand Up @@ -323,7 +327,9 @@ def build_new_schema(self, json_data, schema_draft):
project_name = relecov_tools.utils.get_package_name()
new_schema["$id"] = relecov_tools.utils.get_schema_url()
new_schema["title"] = f"{project_name} Schema."
new_schema["description"] = f"Json Schema that specifies the structure, content, and validation rules for {project_name}"
new_schema["description"] = (
f"Json Schema that specifies the structure, content, and validation rules for {project_name}"
)
new_schema["version"] = self.version

# Fill schema properties
Expand Down Expand Up @@ -401,7 +407,7 @@ def build_new_schema(self, json_data, schema_draft):
for key, values in required_property.items():
if values == "Y":
required_property_unique.append(key)
# TODO: So far it appears at the end of the new json schema. Ideally it should be placed before the properties statement.
# TODO: So far it appears at the end of the new json schema. Ideally it should be placed before the properties statement.
new_schema["required"] = required_property_unique

# Return new schema
Expand Down
6 changes: 3 additions & 3 deletions relecov_tools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,7 @@ def adjust_sheet_size(sheet, wrap_text=True, col_width=30):
value = col_width
sheet.column_dimensions[openpyxl.utils.get_column_letter(col_num)].width = value


def validate_semantic_version(version):
try:
ver = semantic_version.Version(version)
Expand All @@ -562,7 +563,7 @@ def validate_semantic_version(version):
def get_package_name():
"""Get project name"""
try:
package_name = importlib.metadata.metadata(__name__.split('.')[0])["Name"]
package_name = importlib.metadata.metadata(__name__.split(".")[0])["Name"]
return package_name
except importlib.metadata.PackageNotFoundError:
return "unknown_package"
Expand All @@ -585,8 +586,7 @@ def get_schema_url():
"""Generates the schema url dinamically"""
package_name = get_package_name()
branch_name = get_git_branch()

base_url = "https://github.com/BU-ISCIII"
schema_path = f"{package_name}/blob/{branch_name}/{package_name.replace('-','_')}/schema/relecov_schema.json"

return f"{base_url}/{schema_path}"

0 comments on commit 82fef8c

Please sign in to comment.