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

Feature-152-fix-bugs-and-enhance-implementation #177

Merged
merged 8 commits into from
Oct 22, 2024
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ Here is a template for new release sections
- Update links in context.json and example.json for all versions [(#167)](https://github.com/OpenEnergyPlatform/oemetadata/pull/167)
- Restrict the version number to only major and minor versions since 2.0 [(#168)](https://github.com/OpenEnergyPlatform/oemetadata/pull/168)
- Update all descriptions and examples [(#175)](https://github.com/OpenEnergyPlatform/oemetadata/pull/175)
- Build scripts use a settings file to share variables [(#177)](https://github.com/OpenEnergyPlatform/oemetadata/pull/177)

### Removed

Expand Down
2 changes: 1 addition & 1 deletion metadata/latest/build_source/main_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"$ref": "sources.json#"
},
"licenses": {
"$ref": "licences.json#"
"$ref": "licenses.json#"
},
"contribution": {
"$ref": "contribution.json#"
Expand Down
2 changes: 1 addition & 1 deletion metadata/latest/build_source/schemas/licences.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "general.json#metadata/v20/schemas/licences.json",
"$id": "general.json#metadata/v20/schemas/licenses.json",
"type": "object",
"properties": {
"licenses": {
Expand Down
4 changes: 2 additions & 2 deletions metadata/v20/build_source/schema_structure.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "https://raw.githubusercontent.com/OpenEnergyPlatform/oemetadata/master/oemetadata/latest/schema.json",
"$id": "https://raw.githubusercontent.com/OpenEnergyPlatform/oemetadata/develop/metadata/v20/schema.json",
"description": "Open Energy Platform (OEP) metadata schema latest",
"type": "object",
"properties": {
Expand Down Expand Up @@ -29,7 +29,7 @@
"$ref": "sources.json#"
},
"licenses": {
"$ref": "licences.json#"
"$ref": "licenses.json#"
},
"provenance": {
"$ref": "provenance.json#"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "general.json#metadata/v20/schemas/licences.json",
"$id": "general.json#metadata/v20/schemas/licenses.json",
"type": "object",
"properties": {
"licenses": {
Expand Down
Empty file.
20 changes: 3 additions & 17 deletions metadata/v20/build_source/scripts/generate_example_from_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@

# Standard Library Imports
# import os
from os.path import dirname

import sys
import json
import logging

Expand All @@ -23,24 +21,12 @@
# from datetime import datetime
from pathlib import Path

from jsonschema import validate, ValidationError
from settings import VERSION_PATH, RESOLVED_SCHEMA_FILE_NAME, EXAMPLE_PATH, LOG_FORMAT

# Configuration
LOG_FORMAT = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
logging.basicConfig(level=logging.INFO, format=LOG_FORMAT)
logger = logging.getLogger(__name__)

# Constants
BASE_PATH = Path("metadata/")
VERSION = "v20"
VERSION_PATH = BASE_PATH / VERSION
SCHEMA_BUILD_PATH = VERSION_PATH / "build_source"
MAIN_SCHEMA_PATH = SCHEMA_BUILD_PATH / "schema_structure.json"
SCHEMA_REFS = SCHEMA_BUILD_PATH / "schemas"
RESOLVED_SCHEMA_FILE_NAME = VERSION_PATH / "schema.json"
EXPECTED_SCHEMA_PATH = VERSION_PATH / "schema.json"
EXAMPLE_PATH = VERSION_PATH / "example.json"


def read_schema(filename: str) -> Dict[str, Any]:
"""Read a JSON schema from a file.
Expand All @@ -51,7 +37,7 @@ def read_schema(filename: str) -> Dict[str, Any]:
Returns:
Dict[str, Any]: The JSON schema as a dictionary.
"""
# pwd = dirname(__file__)

with open(VERSION_PATH / filename, "r", encoding="utf-8") as file:
schema = json.load(file)
return schema
Expand Down Expand Up @@ -120,6 +106,6 @@ def save_json(data: Dict[str, Any], filename: Path) -> None:


if __name__ == "__main__":
schema_filename = "schema.json"
schema_filename = RESOLVED_SCHEMA_FILE_NAME
json_data = generate_json_from_schema(schema_filename)
save_json(json_data, EXAMPLE_PATH)
16 changes: 4 additions & 12 deletions metadata/v20/build_source/scripts/generate_template_from_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,14 @@

from jsonschema import validate, ValidationError


from settings import RESOLVED_SCHEMA_FILE_NAME, TEMPLATE_PATH, LOG_FORMAT

# Configuration
LOG_FORMAT = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"

logging.basicConfig(level=logging.INFO, format=LOG_FORMAT)
logger = logging.getLogger(__name__)

# Constants
BASE_PATH = Path("metadata/")
VERSION = "v20"
VERSION_PATH = BASE_PATH / VERSION
SCHEMA_BUILD_PATH = VERSION_PATH / "build_source"
MAIN_SCHEMA_PATH = SCHEMA_BUILD_PATH / "schema_structure.json"
SCHEMA_REFS = SCHEMA_BUILD_PATH / "schemas"
RESOLVED_SCHEMA_FILE_NAME = VERSION_PATH / "schema.json"
EXPECTED_SCHEMA_PATH = VERSION_PATH / "schema.json"
TEMPLATE_PATH = VERSION_PATH / "template.json"


def generate_template(schema):
if isinstance(schema, bool):
Expand Down
23 changes: 10 additions & 13 deletions metadata/v20/build_source/scripts/resolve_schema_refs.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

requires: "pip install jsonschema referencing"

Usage: Script with additional arguments --debug for more detailed output.
Usage: Script with additional arguments --debug for more detailed output.
Requires the folder structure introduced in oemetadata v2.0.0.
"""

Expand All @@ -22,28 +22,25 @@
import logging

# from datetime import datetime
from pathlib import Path
from urllib.parse import urljoin
import argparse

from referencing import Registry, Resource
from jsonschema import Draft7Validator

from settings import (
MAIN_SCHEMA_PATH,
SCHEMA_REFS,
RESOLVED_SCHEMA_FILE_NAME,
EXPECTED_SCHEMA_PATH,
LOG_FORMAT,
)

# Configuration
LOG_FORMAT = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"

logging.basicConfig(level=logging.INFO, format=LOG_FORMAT)
logger = logging.getLogger(__name__)

# Constants
BASE_PATH = Path("metadata/")
VERSION = "v20"
VERSION_PATH = BASE_PATH / VERSION
SCHEMA_BUILD_PATH = VERSION_PATH / "build_source"
MAIN_SCHEMA_PATH = SCHEMA_BUILD_PATH / "schema_structure.json"
SCHEMA_REFS = SCHEMA_BUILD_PATH / "schemas"
RESOLVED_SCHEMA_FILE_NAME = VERSION_PATH / "schema.json"
EXPECTED_SCHEMA_PATH = VERSION_PATH / "schema.json"


# Function Definitions
def setup():
Expand Down
16 changes: 16 additions & 0 deletions metadata/v20/build_source/scripts/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from pathlib import Path

LOG_FORMAT = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"

BASE_PATH = Path("metadata/")
VERSION = "v20"
VERSION_PATH = BASE_PATH / VERSION
SCHEMA_BUILD_PATH = VERSION_PATH / "build_source"
MAIN_SCHEMA_PATH = SCHEMA_BUILD_PATH / "schema_structure.json"
SCHEMA_REFS = SCHEMA_BUILD_PATH / "schemas"
RESOLVED_SCHEMA_FILE_NAME = VERSION_PATH / "schema.json"
EXPECTED_SCHEMA_PATH = VERSION_PATH / "schema.json"

EXAMPLE_PATH = VERSION_PATH / "example.json"

TEMPLATE_PATH = VERSION_PATH / "template.json"
Loading