Skip to content

Commit d7457d4

Browse files
authored
Merge pull request #284 from maurerle/improve_usage
Improve usage
2 parents 5e435ab + 27ba1e4 commit d7457d4

9 files changed

Lines changed: 24 additions & 20 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2121

2222
### Changed
2323
- Update TLDR URL in example sourceLicenses [(#275)](https://github.com/OpenEnergyPlatform/oemetadata/pull/275)
24+
- Scripts in build_source produce same json as provided in repo [(#284)](https://github.com/OpenEnergyPlatform/oemetadata/pull/284)
25+
- Update python env instructions to latest version [(#284)](https://github.com/OpenEnergyPlatform/oemetadata/pull/284)
2426

2527
### Removed
2628

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ Collaboration
6363
| Everyone is invited to develop this repository with good intentions.
6464
| Please follow the workflow described in the `CONTRIBUTING.md <CONTRIBUTING.md>`_.
6565
| Development work that aims to extend the oemetadata specification is added to the build_source/schemas/ directory for each release.
66-
| To generate the schema, template & example JSON files see your script based `tooling <.metadata/latest/build_source/>`_
66+
| To generate the schema, template & example JSON files see the scripts based `tooling <oemetadata/v2/v20/build_source/>`_
6767
6868
Contributors:
6969

RELEASE_PROCEDURE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ If you messed up, remove tags and start again
153153

154154
- Change to `production` branch: 💠`git checkout production`
155155
- Update with online version: 💠`git pull`
156-
- Activate environment and enter repository: 💻`activate py310`
156+
- Activate environment and enter repository: 💻`activate oemetadata`
157157
- Test version: 💻`mike serve`
158158
- Publish new version: 💻`mike deploy --push --update-aliases 0.1 latest`
159159

docs/user_documentation/install/index.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
With conda, you can create, export, list, remove, and update environments
66
that have different versions of Python and/or packages installed in them. <br>
77
Switching or moving between environments is called activating the environment.
8-
You can also share an environment file and import from 📝 `requirements.txt`.
9-
8+
You can also share an environment file and import from 📝 `requirements.txt`.<br>
9+
<br>
1010
💻 `conda env create -f environment.yaml` Create conda environment <br>
11-
💻 `conda activate py310` Activate environment <br>
11+
💻 `conda activate oemetadata` Activate environment <br>
1212
💻 `python --version` Check python version
1313

1414
Delete existing environment: <br>
1515
💻 `conda deactivate` <br>
16-
💻 `conda remove --name py310 --all`
16+
💻 `conda remove --name oemetadata --all`
1717

1818
## Requirements
1919

environment.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
# SPDX-FileCopyrightText: super-repo v0.5.0 <https://github.com/rl-institut/super-repo>
33
# SPDX-License-Identifier: MIT
44

5-
name: py310
5+
name: oemetadata
66
channels:
77
- conda-forge
88
dependencies:
9-
- python=3.10
9+
- python=3.13
1010
- pip
1111
- pip:
1212
- -r requirements.txt

oemetadata/v2/v20/build_source/scripts/create_example.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ def read_metadata_schema(filepath: str) -> Dict[str, Any]:
6161
Dict[str, Any]: The JSON schema as a dictionary.
6262
"""
6363
if not os.path.exists(filepath):
64-
logger.info(f"Error: File '{filepath}' does not exist.")
65-
return {}
64+
raise FileNotFoundError(f"Error: File '{filepath}' does not exist.")
6665

6766
try:
6867
with open(filepath, encoding="utf-8") as file:
@@ -78,8 +77,8 @@ def read_metadata_schema(filepath: str) -> Dict[str, Any]:
7877

7978
# Additional debugging info: Check expected keys
8079
if "$schema" not in schema or "type" not in schema:
81-
logger.info(
82-
"Warning: Schema may be missing key fields like '$schema' or 'type'."
80+
logger.warning(
81+
"Schema may be missing key fields like '$schema' or 'type'."
8382
)
8483

8584
logger.info(
@@ -89,11 +88,9 @@ def read_metadata_schema(filepath: str) -> Dict[str, Any]:
8988
return schema
9089

9190
except json.JSONDecodeError as e:
92-
logger.info(f"Error reading JSON: {e}")
93-
return {}
91+
raise Exception(f"Error reading JSON: {e}")
9492
except Exception as e:
95-
logger.info(f"An unexpected error occurred while reading the schema: {e}")
96-
return {}
93+
raise Exception(f"An unexpected error occurred while reading the schema: {e}")
9794

9895

9996
# def generate_example_old(
@@ -220,7 +217,8 @@ def save_json(data: Dict[str, Any], filename: Path) -> None:
220217
filename (str): The filename where the JSON data will be saved.
221218
"""
222219
with open(filename, "w", encoding="utf-8") as file:
223-
json.dump(data, file, ensure_ascii=False, indent=4)
220+
json.dump(data, file, indent=2)
221+
file.write("\n")
224222

225223
logger.info(f"example JSON generated and saved to {filename}")
226224

@@ -262,7 +260,8 @@ def replace_key_in_json(file_path, target_key, new_value):
262260
if find_and_replace_key(data, target_key, new_value):
263261
# Save the updated JSON data back to the file
264262
with open(file_path, "w", encoding="utf-8") as file:
265-
json.dump(data, file, ensure_ascii=False, indent=4)
263+
json.dump(data, file, ensure_ascii=False, indent=2)
264+
file.write("\n")
266265
logger.info(f"Updated '{target_key}' to '{new_value}' in {file_path}")
267266
else:
268267
logger.info(f"Key '{target_key}' not found in JSON file.")

oemetadata/v2/v20/build_source/scripts/create_schema.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ def main(debug):
193193

194194
# Save the resolved schema to a new file
195195
with open(RESOLVED_SCHEMA_FILE_NAME, "w", encoding="utf-8") as output_file:
196-
json.dump(resolved_schema, output_file, indent=2)
196+
json.dump(resolved_schema, output_file, ensure_ascii=False, indent=2)
197+
output_file.write("\n")
197198

198199
# Load the expected schema and validate
199200
expected_schema = load_expected_schema(EXPECTED_SCHEMA_PATH)

oemetadata/v2/v20/build_source/scripts/create_template.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,8 @@ def replace_key_in_json(file_path, target_key, new_value):
133133
if find_and_replace_key(data, target_key, new_value):
134134
# Save the updated JSON data back to the file
135135
with open(file_path, "w") as file:
136-
json.dump(data, file, indent=4)
136+
json.dump(data, file, indent=2)
137+
file.write("\n")
137138
print(f"Updated '{target_key}' to '{new_value}' in {file_path}")
138139
else:
139140
print(f"Key '{target_key}' not found in JSON file.")

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,4 @@ tox
2323
twine
2424
uv
2525
wheel
26+
-e .

0 commit comments

Comments
 (0)