Skip to content
Open
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 doc/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

<!-- Upcoming Release -->
<!-- ================= -->
* Fix: `pixi run generate-config` now runs on Windows: read and write files as UTF-8 and write paths with `/`.
* Fix: Gas pipelines ending in regions without an onshore region, e.g. offshore junctions at high resolution, now get gas and H2 buses instead of leaving the network inconsistent ([#2429](https://github.com/PyPSA/pypsa-eur/pull/2429)).
* Fix: Offshore wind profiles no longer fail for clustered buses without an onshore region; the nearest onshore regions then serve as the shoreline ([#2425](https://github.com/PyPSA/pypsa-eur/pull/2425)).
* Fix: Hydro reservoir storage (`renewable: hydro: hydro_max_hours`) no longer depends on the first unit of each country, and the default now matches the country totals. This changes default results ([#2428](https://github.com/PyPSA/pypsa-eur/pull/2428)).
Expand Down
7 changes: 4 additions & 3 deletions scripts/lib/validation/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ def _write_defaults_yaml(path: str, config: ConfigSchema, defaults: dict) -> Non
def str_representer(dumper, data):
"""Use block style for multiline, quotes for special chars, plain otherwise."""
TAG = "tag:yaml.org,2002:str"
data = str(data) # Ensure it's a plain string (not e.g. Path)
# Plain string; Paths with "/" on every OS
data = data.as_posix() if isinstance(data, pathlib.PurePath) else str(data)
if "\n" in data:
return dumper.represent_scalar(TAG, data, style="|")
if data == "" or any(c in data for c in ":{}[]&*#?|-<>=!%@"):
Expand All @@ -227,7 +228,7 @@ def str_representer(dumper, data):
data.yaml_set_comment_before_after_key(key, before=f"\ndocs in {docs_url}")

# Write to file
with open(path, "w") as f:
with open(path, "w", encoding="utf-8") as f:
yaml_writer.dump(data, f)


Expand Down Expand Up @@ -376,7 +377,7 @@ def rst_to_md(text):
schema = remove_nested_titles(schema)
schema = remove_object_type(schema)
schema = convert_rst_to_markdown(schema)
with open(path.format(configname=config._name), "w") as f:
with open(path.format(configname=config._name), "w", encoding="utf-8") as f:
json.dump(schema, f, indent=2)
f.write("\n")
return schema
Expand Down
8 changes: 4 additions & 4 deletions test/test_config_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def _check_file_in_sync(existing_path: Path, generate_func, file_type: str):
"""Check if a file is in sync with the generated content."""
assert existing_path.exists(), f"{existing_path} does not exist"

existing_content = existing_path.read_text()
existing_content = existing_path.read_text(encoding="utf-8")

with tempfile.NamedTemporaryFile(
mode="w", suffix=f".{file_type}", delete=False
Expand All @@ -60,7 +60,7 @@ def _check_file_in_sync(existing_path: Path, generate_func, file_type: str):

try:
generate_func(temp_path)
generated_content = Path(temp_path).read_text()
generated_content = Path(temp_path).read_text(encoding="utf-8")
finally:
Path(temp_path).unlink(missing_ok=True)

Expand Down Expand Up @@ -223,12 +223,12 @@ def test_migrate_deprecated_keys_ignores_current_keys():
@pytest.mark.parametrize("old", DEPRECATED_KEYS)
def test_deprecated_keys_not_in_default_config(old, config_file):
*parents, key = old.split(".")
defaults = yaml.safe_load(config_file.read_text())
defaults = yaml.safe_load(config_file.read_text(encoding="utf-8"))
assert key not in reduce(dict.get, parents, defaults)


def _load_config(path: str) -> dict:
return yaml.safe_load(Path(path).read_text()) or {}
return yaml.safe_load(Path(path).read_text(encoding="utf-8")) or {}


class TestFindInvalidEntries:
Expand Down
Loading