cim-builder 0.1.0a1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cim_builder-0.1.0a1/.github/dependabot.yml +34 -0
- cim_builder-0.1.0a1/.github/scripts/raise_security_floors.py +55 -0
- cim_builder-0.1.0a1/.github/scripts/test_raise_security_floors.py +39 -0
- cim_builder-0.1.0a1/.github/workflows/release.yml +125 -0
- cim_builder-0.1.0a1/.github/workflows/tests.yml +107 -0
- cim_builder-0.1.0a1/.gitignore +166 -0
- cim_builder-0.1.0a1/AGENTS.md +175 -0
- cim_builder-0.1.0a1/CLAUDE.md +112 -0
- cim_builder-0.1.0a1/LICENSE +28 -0
- cim_builder-0.1.0a1/PKG-INFO +47 -0
- cim_builder-0.1.0a1/README.md +36 -0
- cim_builder-0.1.0a1/cimbuilder/__init__.py +0 -0
- cim_builder-0.1.0a1/cimbuilder/core/sort_terminals.py +43 -0
- cim_builder-0.1.0a1/cimbuilder/core/tap_steps.py +24 -0
- cim_builder-0.1.0a1/cimbuilder/feeder_builder/aggregate_feeder.py +182 -0
- cim_builder-0.1.0a1/cimbuilder/network.py +61 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/__init__.py +203 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/base/__init__.py +13 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/base/base_quantities.py +71 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/conducting_asset_info.py +40 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/container/__init__.py +15 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/container/feeder.py +49 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/container/substation.py +38 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/container/voltage_level.py +88 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/control/__init__.py +9 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/control/regulating_control.py +64 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/deprecated/create_houses.py +780 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/generator/__init__.py +14 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/generator/asynchronous_machine.py +41 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/generator/rotating_machine.py +114 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/generator/synchronous_machine.py +84 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/inverter/__init__.py +36 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/inverter/battery_info.py +40 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/inverter/inverter_info.py +72 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/inverter/power_electronics_connection.py +139 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/inverter/power_electronics_connection_phase.py +50 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/inverter/power_electronics_unit.py +125 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/inverter/solar_panel_info.py +40 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/limit/__init__.py +8 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/limit/operational_limit_set.py +272 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/line/__init__.py +36 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/line/ac_line_segment.py +202 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/line/ac_line_segment_phase.py +54 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/line/cable_info.py +61 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/line/concentric_neutral_cable_info.py +41 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/line/conductor_distance_spacing.py +76 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/line/overhead_wire_info.py +11 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/line/per_length_impedance.py +200 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/line/series_compensator.py +109 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/line/wire_configuration.py +108 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/line/wire_info.py +97 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/line/xy_wire_spacing.py +68 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/load/__init__.py +14 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/load/energy_consumer.py +149 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/load/energy_consumer_phase.py +74 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/load/load_response_characteristic.py +54 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/measurement/__init__.py +11 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/measurement/analog.py +131 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/measurement/discrete.py +45 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/measurement/measurement.py +190 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/object_builder.py +100 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/protection/__init__.py +9 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/protection/under_frequency_protection_function_block.py +54 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/shunt/__init__.py +12 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/shunt/linear_shunt_compensator.py +211 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/shunt/linear_shunt_compensator_phase.py +89 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/source/__init__.py +7 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/source/energy_source.py +150 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/switch/__init__.py +38 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/switch/protected_switch.py +94 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/switch/switch.py +179 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/switch/switch_info.py +51 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/switch/switch_phase.py +65 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/topology/__init__.py +17 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/topology/connectivity_node.py +52 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/topology/connector.py +117 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/topology/topological_node.py +33 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/transformer/__init__.py +69 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/transformer/cooling_info.py +29 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/transformer/phase_tap_changer.py +18 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/transformer/phase_tap_changer_asymmetrical.py +54 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/transformer/phase_tap_changer_linear.py +48 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/transformer/phase_tap_changer_non_linear.py +49 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/transformer/phase_tap_changer_symmetrical.py +17 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/transformer/phase_tap_changer_table.py +55 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/transformer/phase_tap_changer_tabular.py +53 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/transformer/power_transformer.py +193 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/transformer/ratio_tap_changer.py +42 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/transformer/series_reactor_info.py +88 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/transformer/tap_changer.py +132 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/transformer/tap_changer_control.py +79 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/transformer/tap_changer_info.py +76 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/transformer/transformer_bank.py +386 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/transformer/transformer_tank_configuration.py +318 -0
- cim_builder-0.1.0a1/cimbuilder/object_builder/transformer/voltage_regulator.py +205 -0
- cim_builder-0.1.0a1/cimbuilder/substation_builder/__init__.py +27 -0
- cim_builder-0.1.0a1/cimbuilder/substation_builder/breaker_and_a_half.py +68 -0
- cim_builder-0.1.0a1/cimbuilder/substation_builder/double_bus_double_breaker.py +0 -0
- cim_builder-0.1.0a1/cimbuilder/substation_builder/double_bus_single_breaker.py +71 -0
- cim_builder-0.1.0a1/cimbuilder/substation_builder/main_and_transfer.py +54 -0
- cim_builder-0.1.0a1/cimbuilder/substation_builder/ring_bus.py +58 -0
- cim_builder-0.1.0a1/cimbuilder/substation_builder/sectionalized_bus.py +50 -0
- cim_builder-0.1.0a1/cimbuilder/substation_builder/single_bus.py +33 -0
- cim_builder-0.1.0a1/cimbuilder/substation_builder/substation_builder.py +161 -0
- cim_builder-0.1.0a1/cimbuilder/utils/__init__.py +2 -0
- cim_builder-0.1.0a1/cimbuilder/utils/catalog_parser.py +41 -0
- cim_builder-0.1.0a1/cimbuilder/utils/get_base_impedance.py +0 -0
- cim_builder-0.1.0a1/cimbuilder/utils/get_base_voltage.py +0 -0
- cim_builder-0.1.0a1/cimbuilder/utils/get_source_bus.py +37 -0
- cim_builder-0.1.0a1/debug.ipynb +183 -0
- cim_builder-0.1.0a1/docs/.readthedocs.yaml +32 -0
- cim_builder-0.1.0a1/docs/01_overview/1_1_overview.ipynb +66 -0
- cim_builder-0.1.0a1/docs/01_overview/1_2_installation.ipynb +220 -0
- cim_builder-0.1.0a1/docs/01_overview/1_3_structure.ipynb +23 -0
- cim_builder-0.1.0a1/docs/01_overview/1_4_contributing.ipynb +124 -0
- cim_builder-0.1.0a1/docs/02_object_builder/2_1_object_builder.ipynb +68 -0
- cim_builder-0.1.0a1/docs/02_object_builder/2_2_one_terminal_object.ipynb +23 -0
- cim_builder-0.1.0a1/docs/02_object_builder/2_3_two_terminal_object.ipynb +23 -0
- cim_builder-0.1.0a1/docs/03_substation_builder/3_1_single_bus.ipynb +560 -0
- cim_builder-0.1.0a1/docs/03_substation_builder/3_2_sectionalized_bus.ipynb +556 -0
- cim_builder-0.1.0a1/docs/03_substation_builder/3_3_main_and_transfer.ipynb +555 -0
- cim_builder-0.1.0a1/docs/03_substation_builder/3_4_double_bus_single_breaker.ipynb +559 -0
- cim_builder-0.1.0a1/docs/03_substation_builder/3_5_ring_bus.ipynb +554 -0
- cim_builder-0.1.0a1/docs/03_substation_builder/3_6_breaker_and_half.ipynb +565 -0
- cim_builder-0.1.0a1/docs/03_substation_builder/deliverable.ipynb +503 -0
- cim_builder-0.1.0a1/docs/03_substation_builder/new_single_bus.json +429 -0
- cim_builder-0.1.0a1/docs/03_substation_builder/new_single_bus.xml +205 -0
- cim_builder-0.1.0a1/docs/03_substation_builder/single_bus_and_feeders.xml +8745 -0
- cim_builder-0.1.0a1/docs/Makefile +0 -0
- cim_builder-0.1.0a1/docs/conf.py +75 -0
- cim_builder-0.1.0a1/docs/images/breaker_and_half.png +0 -0
- cim_builder-0.1.0a1/docs/images/double_bus_double_breaker.png +0 -0
- cim_builder-0.1.0a1/docs/images/double_bus_single_breaker.png +0 -0
- cim_builder-0.1.0a1/docs/images/main_transfer.png +0 -0
- cim_builder-0.1.0a1/docs/images/ring_bus.png +0 -0
- cim_builder-0.1.0a1/docs/images/ring_bus_2.png +0 -0
- cim_builder-0.1.0a1/docs/images/sectionalized_bus.png +0 -0
- cim_builder-0.1.0a1/docs/images/single_bus.png +0 -0
- cim_builder-0.1.0a1/docs/index.rst +43 -0
- cim_builder-0.1.0a1/docs/make.bat +35 -0
- cim_builder-0.1.0a1/docs/requirements.txt +13 -0
- cim_builder-0.1.0a1/pyproject.toml +33 -0
- cim_builder-0.1.0a1/tests/core/test_tap_steps.py +21 -0
- cim_builder-0.1.0a1/tests/feeder_builder/test_aggregate_feeder.py +97 -0
- cim_builder-0.1.0a1/tests/object_builder/base/test_base_quantities.py +26 -0
- cim_builder-0.1.0a1/tests/object_builder/conftest.py +37 -0
- cim_builder-0.1.0a1/tests/object_builder/container/test_feeder_substation.py +24 -0
- cim_builder-0.1.0a1/tests/object_builder/container/test_voltage_level.py +49 -0
- cim_builder-0.1.0a1/tests/object_builder/generator/test_rotating_machine.py +108 -0
- cim_builder-0.1.0a1/tests/object_builder/inverter/test_inverter_info.py +61 -0
- cim_builder-0.1.0a1/tests/object_builder/inverter/test_power_electronics_connection.py +50 -0
- cim_builder-0.1.0a1/tests/object_builder/inverter/test_power_electronics_connection_phase.py +29 -0
- cim_builder-0.1.0a1/tests/object_builder/inverter/test_power_electronics_unit.py +87 -0
- cim_builder-0.1.0a1/tests/object_builder/limit/test_operational_limit_set.py +105 -0
- cim_builder-0.1.0a1/tests/object_builder/line/test_ac_line_segment.py +82 -0
- cim_builder-0.1.0a1/tests/object_builder/line/test_ac_line_segment_phase.py +28 -0
- cim_builder-0.1.0a1/tests/object_builder/line/test_conductor_distance_spacing.py +39 -0
- cim_builder-0.1.0a1/tests/object_builder/line/test_per_length_impedance.py +116 -0
- cim_builder-0.1.0a1/tests/object_builder/line/test_series_compensator.py +34 -0
- cim_builder-0.1.0a1/tests/object_builder/line/test_wire_configuration.py +48 -0
- cim_builder-0.1.0a1/tests/object_builder/line/test_wire_info.py +43 -0
- cim_builder-0.1.0a1/tests/object_builder/line/test_xy_wire_spacing.py +37 -0
- cim_builder-0.1.0a1/tests/object_builder/load/test_energy_consumer.py +59 -0
- cim_builder-0.1.0a1/tests/object_builder/load/test_energy_consumer_phase.py +32 -0
- cim_builder-0.1.0a1/tests/object_builder/load/test_load_response_characteristic.py +29 -0
- cim_builder-0.1.0a1/tests/object_builder/measurement/test_measurement.py +231 -0
- cim_builder-0.1.0a1/tests/object_builder/protection/test_under_frequency_protection_function_block.py +14 -0
- cim_builder-0.1.0a1/tests/object_builder/shunt/test_linear_shunt_compensator.py +101 -0
- cim_builder-0.1.0a1/tests/object_builder/shunt/test_linear_shunt_compensator_phase.py +41 -0
- cim_builder-0.1.0a1/tests/object_builder/source/test_energy_source.py +28 -0
- cim_builder-0.1.0a1/tests/object_builder/switch/test_protected_switch.py +48 -0
- cim_builder-0.1.0a1/tests/object_builder/switch/test_switch.py +96 -0
- cim_builder-0.1.0a1/tests/object_builder/switch/test_switch_info.py +11 -0
- cim_builder-0.1.0a1/tests/object_builder/switch/test_switch_phase.py +34 -0
- cim_builder-0.1.0a1/tests/object_builder/test_asset_info_fields.py +224 -0
- cim_builder-0.1.0a1/tests/object_builder/test_network.py +80 -0
- cim_builder-0.1.0a1/tests/object_builder/test_object_builder.py +24 -0
- cim_builder-0.1.0a1/tests/object_builder/topology/test_connectivity_node.py +17 -0
- cim_builder-0.1.0a1/tests/object_builder/topology/test_connector.py +34 -0
- cim_builder-0.1.0a1/tests/object_builder/topology/test_topological_node.py +17 -0
- cim_builder-0.1.0a1/tests/object_builder/transformer/test_cooling_info.py +9 -0
- cim_builder-0.1.0a1/tests/object_builder/transformer/test_phase_tap_changer.py +99 -0
- cim_builder-0.1.0a1/tests/object_builder/transformer/test_power_transformer.py +144 -0
- cim_builder-0.1.0a1/tests/object_builder/transformer/test_series_reactor_info.py +9 -0
- cim_builder-0.1.0a1/tests/object_builder/transformer/test_tap_changer.py +72 -0
- cim_builder-0.1.0a1/tests/object_builder/transformer/test_tap_changer_info.py +27 -0
- cim_builder-0.1.0a1/tests/object_builder/transformer/test_transformer_bank.py +140 -0
- cim_builder-0.1.0a1/tests/object_builder/transformer/test_transformer_bank_from_configuration.py +96 -0
- cim_builder-0.1.0a1/tests/object_builder/transformer/test_transformer_tank_configuration.py +199 -0
- cim_builder-0.1.0a1/tests/object_builder/transformer/test_voltage_regulator.py +149 -0
- cim_builder-0.1.0a1/tests/substation_builder/test_substation_builder.py +230 -0
- cim_builder-0.1.0a1/tests/test_models/IEEE13.xml +3899 -0
- cim_builder-0.1.0a1/tests/test_models/IEEE13_Assets.xml +3351 -0
- cim_builder-0.1.0a1/tests/test_models/hv69_12.json +39 -0
- cim_builder-0.1.0a1/tests/test_models/p10uhs4.xml +276976 -0
- cim_builder-0.1.0a1/tests/test_models/p1rhs5.xml +17329 -0
- cim_builder-0.1.0a1/uv.lock +1283 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
---
|
|
2
|
+
# Requires develop as the repository's default branch: Dependabot opens all PRs
|
|
3
|
+
# against it, and security updates ignore these options when target-branch is
|
|
4
|
+
# set. Minor/patch bumps and security fixes are grouped into one PR each;
|
|
5
|
+
# majors get their own PR for review.
|
|
6
|
+
version: 2
|
|
7
|
+
updates:
|
|
8
|
+
- package-ecosystem: "github-actions"
|
|
9
|
+
directory: "/"
|
|
10
|
+
schedule:
|
|
11
|
+
interval: "monthly"
|
|
12
|
+
cooldown:
|
|
13
|
+
default-days: 7
|
|
14
|
+
groups:
|
|
15
|
+
actions:
|
|
16
|
+
patterns: ["*"]
|
|
17
|
+
update-types: ["minor", "patch"]
|
|
18
|
+
|
|
19
|
+
- package-ecosystem: "uv"
|
|
20
|
+
directory: "/"
|
|
21
|
+
schedule:
|
|
22
|
+
interval: "monthly"
|
|
23
|
+
cooldown:
|
|
24
|
+
default-days: 7
|
|
25
|
+
allow:
|
|
26
|
+
# No scheduled bumps of transitive (lockfile-only) deps
|
|
27
|
+
- dependency-type: "direct"
|
|
28
|
+
groups:
|
|
29
|
+
python:
|
|
30
|
+
patterns: ["*"]
|
|
31
|
+
update-types: ["minor", "patch"]
|
|
32
|
+
python-security:
|
|
33
|
+
applies-to: security-updates
|
|
34
|
+
patterns: ["*"]
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"""Raise pyproject.toml minimum versions for runtime deps in a Dependabot security PR.
|
|
2
|
+
|
|
3
|
+
Only [project] dependencies and optional-dependencies ship to PyPI users; dev,
|
|
4
|
+
docs and transitive deps are lockfile-only and left alone. Reads the
|
|
5
|
+
fetch-metadata `updated-dependencies-json` from $UPDATED_DEPENDENCIES, rewrites
|
|
6
|
+
pyproject.toml in place and prints each raised requirement (nothing if none).
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
import json
|
|
10
|
+
import os
|
|
11
|
+
import re
|
|
12
|
+
import tomllib
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
|
|
15
|
+
NAME_PATTERN = re.compile(r'[A-Za-z0-9._-]+')
|
|
16
|
+
LOWER_BOUND_PATTERN = re.compile(r'>=\s*[^,;\s]+')
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def normalize(name: str) -> str:
|
|
20
|
+
return re.sub(r'[-_.]+', '-', name).lower()
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def runtime_requirements(pyproject_text: str) -> list[str]:
|
|
24
|
+
project = tomllib.loads(pyproject_text)['project']
|
|
25
|
+
requirements = list(project.get('dependencies', []))
|
|
26
|
+
for extra in project.get('optional-dependencies', {}).values():
|
|
27
|
+
requirements.extend(extra)
|
|
28
|
+
return requirements
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def raise_floors(pyproject_text: str, updates: list[dict]) -> tuple[str, list[str]]:
|
|
32
|
+
new_versions = {normalize(u['dependencyName']): u['newVersion'] for u in updates}
|
|
33
|
+
raised = []
|
|
34
|
+
for requirement in runtime_requirements(pyproject_text):
|
|
35
|
+
name = normalize(NAME_PATTERN.match(requirement).group())
|
|
36
|
+
if name not in new_versions:
|
|
37
|
+
continue
|
|
38
|
+
if not LOWER_BOUND_PATTERN.search(requirement):
|
|
39
|
+
raise ValueError(f'{requirement!r} has no >= bound to raise; update pyproject.toml manually')
|
|
40
|
+
new_requirement = LOWER_BOUND_PATTERN.sub(f'>={new_versions[name]}', requirement, count=1)
|
|
41
|
+
pyproject_text = pyproject_text.replace(f'"{requirement}"', f'"{new_requirement}"')
|
|
42
|
+
raised.append(new_requirement)
|
|
43
|
+
return pyproject_text, raised
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def main() -> None:
|
|
47
|
+
pyproject = Path('pyproject.toml')
|
|
48
|
+
updates = json.loads(os.environ['UPDATED_DEPENDENCIES'])
|
|
49
|
+
new_text, raised = raise_floors(pyproject.read_text(), updates)
|
|
50
|
+
pyproject.write_text(new_text)
|
|
51
|
+
print('\n'.join(raised))
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
if __name__ == '__main__':
|
|
55
|
+
main()
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from raise_security_floors import raise_floors
|
|
3
|
+
|
|
4
|
+
PYPROJECT = '''
|
|
5
|
+
[project]
|
|
6
|
+
name = "example"
|
|
7
|
+
dependencies = [
|
|
8
|
+
"pint>=0.24.4",
|
|
9
|
+
"Some_Package[extra]>=1.0,<2",
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
[project.optional-dependencies]
|
|
13
|
+
neo4j = ["neo4j>=5.10.0"]
|
|
14
|
+
|
|
15
|
+
[dependency-groups]
|
|
16
|
+
dev = ["pytest>=8.3.5"]
|
|
17
|
+
'''
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def update(name, version):
|
|
21
|
+
return {'dependencyName': name, 'newVersion': version}
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def test_raises_runtime_and_optional_floors_keeping_upper_bounds():
|
|
25
|
+
text, raised = raise_floors(PYPROJECT, [update('pint', '0.25.1'), update('some-package', '1.2'),
|
|
26
|
+
update('neo4j', '5.11.0')])
|
|
27
|
+
assert raised == ['pint>=0.25.1', 'Some_Package[extra]>=1.2,<2', 'neo4j>=5.11.0']
|
|
28
|
+
assert '"Some_Package[extra]>=1.2,<2"' in text
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def test_ignores_dev_and_transitive_deps():
|
|
32
|
+
text, raised = raise_floors(PYPROJECT, [update('pytest', '9.0'), update('urllib3', '2.8.0')])
|
|
33
|
+
assert raised == []
|
|
34
|
+
assert text == PYPROJECT
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def test_fails_without_lower_bound():
|
|
38
|
+
with pytest.raises(ValueError, match='no >= bound'):
|
|
39
|
+
raise_floors('[project]\ndependencies = ["pint"]\n', [update('pint', '0.25.1')])
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
---
|
|
2
|
+
# Publishes cim-builder (import name cimbuilder) to PyPI (the same chain as CIM-Profiles).
|
|
3
|
+
# develop -> alpha pre-release (0.1.0a1, 0.1.0a2, ...)
|
|
4
|
+
# main -> full release (0.1.0)
|
|
5
|
+
#
|
|
6
|
+
# pyproject.toml holds the next release target (X.Y.Z). The published version
|
|
7
|
+
# is derived from PyPI at build time and never committed, so nothing pushes to
|
|
8
|
+
# the protected branches: alphas take the next free aN, and once the target is
|
|
9
|
+
# released both branches move on to the next patch. Bump the target in a PR
|
|
10
|
+
# for minor/major releases.
|
|
11
|
+
#
|
|
12
|
+
# cim-tables, cim-graph and cim-profiles come from PyPI here: [tool.uv.sources] points at
|
|
13
|
+
# sibling checkouts for local development only, so every uv call that resolves
|
|
14
|
+
# takes --no-sources, and `uv version` writes with --frozen (it would re-lock
|
|
15
|
+
# against those missing paths). The lockfile is the sibling one, so it is not
|
|
16
|
+
# used (--locked) in CI.
|
|
17
|
+
#
|
|
18
|
+
# Uses PyPI Trusted Publishing (OIDC); no API token is stored. One-time setup:
|
|
19
|
+
# 1. PyPI -> Publishing -> add a pending GitHub publisher for project cim-builder:
|
|
20
|
+
# owner PNNL-CIM-Tools, repo CIM-Builder, workflow release.yml, environment pypi
|
|
21
|
+
# 2. GitHub repo -> Settings -> Environments -> create "pypi"
|
|
22
|
+
name: Release
|
|
23
|
+
|
|
24
|
+
on:
|
|
25
|
+
push:
|
|
26
|
+
branches: [main, develop]
|
|
27
|
+
paths:
|
|
28
|
+
- "cimbuilder/**"
|
|
29
|
+
- "pyproject.toml"
|
|
30
|
+
workflow_dispatch:
|
|
31
|
+
|
|
32
|
+
concurrency:
|
|
33
|
+
group: release-${{ github.ref }}
|
|
34
|
+
cancel-in-progress: false
|
|
35
|
+
|
|
36
|
+
permissions: {}
|
|
37
|
+
|
|
38
|
+
jobs:
|
|
39
|
+
build:
|
|
40
|
+
if: github.ref_name == 'main' || github.ref_name == 'develop'
|
|
41
|
+
runs-on: ubuntu-latest
|
|
42
|
+
permissions:
|
|
43
|
+
contents: read
|
|
44
|
+
outputs:
|
|
45
|
+
version: ${{ steps.bump.outputs.version }}
|
|
46
|
+
steps:
|
|
47
|
+
- uses: actions/checkout@v7
|
|
48
|
+
with:
|
|
49
|
+
persist-credentials: false
|
|
50
|
+
|
|
51
|
+
- uses: astral-sh/setup-uv@v10.3.2
|
|
52
|
+
with:
|
|
53
|
+
python-version: "3.10"
|
|
54
|
+
|
|
55
|
+
- name: Set version
|
|
56
|
+
id: bump
|
|
57
|
+
run: |
|
|
58
|
+
TARGET=$(uv version --short)
|
|
59
|
+
if [[ ! "$TARGET" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
|
60
|
+
echo "::error::pyproject.toml version must be the next release target X.Y.Z, got $TARGET"
|
|
61
|
+
exit 1
|
|
62
|
+
fi
|
|
63
|
+
PUBLISHED=$(curl -sf https://pypi.org/pypi/cim-builder/json | jq -r '.releases | keys[]')
|
|
64
|
+
while grep -qxF "$TARGET" <<< "$PUBLISHED"; do
|
|
65
|
+
TARGET=$(uv version --bump patch --frozen --short)
|
|
66
|
+
done
|
|
67
|
+
if [[ "$GITHUB_REF_NAME" == "main" ]]; then
|
|
68
|
+
VERSION="$TARGET"
|
|
69
|
+
else
|
|
70
|
+
LAST_ALPHA=$(grep -E "^${TARGET//./\\.}a[0-9]+$" <<< "$PUBLISHED" | sed 's/.*a//' | sort -n | tail -1 || true)
|
|
71
|
+
VERSION="${TARGET}a$(( ${LAST_ALPHA:-0} + 1 ))"
|
|
72
|
+
fi
|
|
73
|
+
uv version "$VERSION" --frozen
|
|
74
|
+
echo "version=$VERSION" >> "$GITHUB_OUTPUT"
|
|
75
|
+
|
|
76
|
+
- name: Test
|
|
77
|
+
run: uv run --no-sources pytest
|
|
78
|
+
|
|
79
|
+
- name: Build
|
|
80
|
+
run: uv build --no-sources
|
|
81
|
+
|
|
82
|
+
- uses: actions/upload-artifact@v7
|
|
83
|
+
with:
|
|
84
|
+
name: dist
|
|
85
|
+
path: dist/
|
|
86
|
+
|
|
87
|
+
publish:
|
|
88
|
+
needs: build
|
|
89
|
+
runs-on: ubuntu-latest
|
|
90
|
+
environment:
|
|
91
|
+
name: pypi
|
|
92
|
+
url: https://pypi.org/project/cim-builder/${{ needs.build.outputs.version }}/
|
|
93
|
+
permissions:
|
|
94
|
+
id-token: write
|
|
95
|
+
steps:
|
|
96
|
+
- uses: actions/download-artifact@v8
|
|
97
|
+
with:
|
|
98
|
+
name: dist
|
|
99
|
+
path: dist/
|
|
100
|
+
|
|
101
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
102
|
+
|
|
103
|
+
github-release:
|
|
104
|
+
needs: [build, publish]
|
|
105
|
+
runs-on: ubuntu-latest
|
|
106
|
+
permissions:
|
|
107
|
+
contents: write
|
|
108
|
+
steps:
|
|
109
|
+
- uses: actions/download-artifact@v8
|
|
110
|
+
with:
|
|
111
|
+
name: dist
|
|
112
|
+
path: dist/
|
|
113
|
+
|
|
114
|
+
# Tags the built commit through the API; tags aren't covered by the branch rulesets
|
|
115
|
+
- name: Create GitHub release
|
|
116
|
+
env:
|
|
117
|
+
GH_TOKEN: ${{ github.token }}
|
|
118
|
+
GH_REPO: ${{ github.repository }}
|
|
119
|
+
VERSION: ${{ needs.build.outputs.version }}
|
|
120
|
+
run: |
|
|
121
|
+
PRERELEASE_FLAG=""
|
|
122
|
+
if [[ "$GITHUB_REF_NAME" == "develop" ]]; then
|
|
123
|
+
PRERELEASE_FLAG="--prerelease"
|
|
124
|
+
fi
|
|
125
|
+
gh release create "v$VERSION" dist/* --target "$GITHUB_SHA" --generate-notes $PRERELEASE_FLAG
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
---
|
|
2
|
+
# Runs tests on every PR, then routes Dependabot PRs into develop by group
|
|
3
|
+
# (the same chain as CIM-Profiles; --no-sources: see release.yml)
|
|
4
|
+
# (see dependabot.yml):
|
|
5
|
+
# python lockfile-only minor/patch bumps -> merge, no release
|
|
6
|
+
# python-security merge; if a runtime dep is affected, raise its
|
|
7
|
+
# minimum in pyproject.toml, publish an alpha and open the
|
|
8
|
+
# develop -> main PR for the patch release
|
|
9
|
+
# actions, majors left for manual review (workflow changes can't be merged
|
|
10
|
+
# with GITHUB_TOKEN, and they touch the release pipeline)
|
|
11
|
+
name: Tests
|
|
12
|
+
|
|
13
|
+
on:
|
|
14
|
+
pull_request:
|
|
15
|
+
|
|
16
|
+
permissions: {}
|
|
17
|
+
|
|
18
|
+
jobs:
|
|
19
|
+
test:
|
|
20
|
+
runs-on: ubuntu-latest
|
|
21
|
+
permissions:
|
|
22
|
+
contents: read
|
|
23
|
+
steps:
|
|
24
|
+
- uses: actions/checkout@v7
|
|
25
|
+
with:
|
|
26
|
+
persist-credentials: false
|
|
27
|
+
|
|
28
|
+
- uses: astral-sh/setup-uv@v10.3.2
|
|
29
|
+
with:
|
|
30
|
+
python-version: "3.10"
|
|
31
|
+
|
|
32
|
+
- name: Test
|
|
33
|
+
run: uv run --no-sources pytest
|
|
34
|
+
|
|
35
|
+
dependabot:
|
|
36
|
+
needs: test
|
|
37
|
+
if: github.event.pull_request.user.login == 'dependabot[bot]' && github.base_ref == 'develop'
|
|
38
|
+
runs-on: ubuntu-latest
|
|
39
|
+
permissions:
|
|
40
|
+
contents: write
|
|
41
|
+
pull-requests: write
|
|
42
|
+
actions: write
|
|
43
|
+
env:
|
|
44
|
+
GH_TOKEN: ${{ github.token }}
|
|
45
|
+
GH_REPO: ${{ github.repository }}
|
|
46
|
+
PR_NUMBER: ${{ github.event.pull_request.number }}
|
|
47
|
+
steps:
|
|
48
|
+
- id: metadata
|
|
49
|
+
uses: dependabot/fetch-metadata@v3
|
|
50
|
+
|
|
51
|
+
- uses: actions/checkout@v7
|
|
52
|
+
if: steps.metadata.outputs.dependency-group == 'python-security'
|
|
53
|
+
with:
|
|
54
|
+
ref: ${{ github.head_ref }}
|
|
55
|
+
|
|
56
|
+
- uses: astral-sh/setup-uv@v10.3.2
|
|
57
|
+
if: steps.metadata.outputs.dependency-group == 'python-security'
|
|
58
|
+
with:
|
|
59
|
+
python-version: "3.12"
|
|
60
|
+
|
|
61
|
+
- name: Raise minimum versions of runtime deps
|
|
62
|
+
id: floors
|
|
63
|
+
if: steps.metadata.outputs.dependency-group == 'python-security'
|
|
64
|
+
env:
|
|
65
|
+
UPDATED_DEPENDENCIES: ${{ steps.metadata.outputs.updated-dependencies-json }}
|
|
66
|
+
run: |
|
|
67
|
+
RAISED=$(uv run --no-project python .github/scripts/raise_security_floors.py)
|
|
68
|
+
if [[ -z "$RAISED" ]]; then
|
|
69
|
+
echo "Only dev or transitive deps affected; no release needed"
|
|
70
|
+
exit 0
|
|
71
|
+
fi
|
|
72
|
+
uv lock --no-sources
|
|
73
|
+
git config user.name "github-actions[bot]"
|
|
74
|
+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
|
75
|
+
git commit -am "Raise minimum versions for security fixes" -m "$RAISED"
|
|
76
|
+
git push
|
|
77
|
+
{
|
|
78
|
+
echo "head=$(git rev-parse HEAD)"
|
|
79
|
+
echo "raised<<EOF"
|
|
80
|
+
echo "$RAISED"
|
|
81
|
+
echo "EOF"
|
|
82
|
+
} >> "$GITHUB_OUTPUT"
|
|
83
|
+
|
|
84
|
+
# The approval satisfies the ruleset's required review (needs "Allow GitHub
|
|
85
|
+
# Actions to create and approve pull requests"); tests above are the gate.
|
|
86
|
+
- name: Approve and merge
|
|
87
|
+
if: contains(fromJSON('["python", "python-security"]'), steps.metadata.outputs.dependency-group)
|
|
88
|
+
env:
|
|
89
|
+
HEAD_SHA: ${{ steps.floors.outputs.head || github.event.pull_request.head.sha }}
|
|
90
|
+
run: |
|
|
91
|
+
gh pr review "$PR_NUMBER" --approve --body "Tests passed; auto-merging ${{ steps.metadata.outputs.dependency-group }} update."
|
|
92
|
+
gh pr merge "$PR_NUMBER" --merge --delete-branch --match-head-commit "$HEAD_SHA"
|
|
93
|
+
|
|
94
|
+
# Merges made with GITHUB_TOKEN don't fire push events, so start the release explicitly.
|
|
95
|
+
- name: Release security fix
|
|
96
|
+
if: steps.floors.outputs.raised != ''
|
|
97
|
+
env:
|
|
98
|
+
RAISED: ${{ steps.floors.outputs.raised }}
|
|
99
|
+
run: |
|
|
100
|
+
gh workflow run release.yml --ref develop
|
|
101
|
+
BODY=$(printf 'Publishes a patch release with raised minimum versions for security fixes:\n\n%s\n\nFrom #%s.' "$RAISED" "$PR_NUMBER")
|
|
102
|
+
EXISTING=$(gh pr list --base main --head develop --json number -q '.[0].number')
|
|
103
|
+
if [[ -n "$EXISTING" ]]; then
|
|
104
|
+
gh pr comment "$EXISTING" --body "$BODY"
|
|
105
|
+
else
|
|
106
|
+
gh pr create --base main --head develop --title "Security patch release" --body "$BODY"
|
|
107
|
+
fi
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# local
|
|
2
|
+
/local/
|
|
3
|
+
|
|
4
|
+
# XML written by the docs notebooks
|
|
5
|
+
docs/03_substation_builder/output/
|
|
6
|
+
|
|
7
|
+
# Byte-compiled / optimized / DLL files
|
|
8
|
+
__pycache__/
|
|
9
|
+
*.py[cod]
|
|
10
|
+
*$py.class
|
|
11
|
+
.vscode/
|
|
12
|
+
# C extensions
|
|
13
|
+
*.so
|
|
14
|
+
|
|
15
|
+
# Distribution / packaging
|
|
16
|
+
.Python
|
|
17
|
+
build/
|
|
18
|
+
develop-eggs/
|
|
19
|
+
dist/
|
|
20
|
+
downloads/
|
|
21
|
+
eggs/
|
|
22
|
+
.eggs/
|
|
23
|
+
lib/
|
|
24
|
+
lib64/
|
|
25
|
+
parts/
|
|
26
|
+
sdist/
|
|
27
|
+
var/
|
|
28
|
+
wheels/
|
|
29
|
+
share/python-wheels/
|
|
30
|
+
*.egg-info/
|
|
31
|
+
.installed.cfg
|
|
32
|
+
*.egg
|
|
33
|
+
MANIFEST
|
|
34
|
+
|
|
35
|
+
# PyInstaller
|
|
36
|
+
# Usually these files are written by a python script from a template
|
|
37
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
38
|
+
*.manifest
|
|
39
|
+
*.spec
|
|
40
|
+
|
|
41
|
+
# Installer logs
|
|
42
|
+
pip-log.txt
|
|
43
|
+
pip-delete-this-directory.txt
|
|
44
|
+
|
|
45
|
+
# Unit test / coverage reports
|
|
46
|
+
htmlcov/
|
|
47
|
+
.tox/
|
|
48
|
+
.nox/
|
|
49
|
+
.coverage
|
|
50
|
+
.coverage.*
|
|
51
|
+
.cache
|
|
52
|
+
nosetests.xml
|
|
53
|
+
coverage.xml
|
|
54
|
+
*.cover
|
|
55
|
+
*.py,cover
|
|
56
|
+
.hypothesis/
|
|
57
|
+
.pytest_cache/
|
|
58
|
+
cover/
|
|
59
|
+
|
|
60
|
+
# Translations
|
|
61
|
+
*.mo
|
|
62
|
+
*.pot
|
|
63
|
+
|
|
64
|
+
# Django stuff:
|
|
65
|
+
*.log
|
|
66
|
+
local_settings.py
|
|
67
|
+
db.sqlite3
|
|
68
|
+
db.sqlite3-journal
|
|
69
|
+
|
|
70
|
+
# Flask stuff:
|
|
71
|
+
instance/
|
|
72
|
+
.webassets-cache
|
|
73
|
+
|
|
74
|
+
# Scrapy stuff:
|
|
75
|
+
.scrapy
|
|
76
|
+
|
|
77
|
+
# Sphinx documentation
|
|
78
|
+
docs/_build/
|
|
79
|
+
|
|
80
|
+
# PyBuilder
|
|
81
|
+
.pybuilder/
|
|
82
|
+
target/
|
|
83
|
+
|
|
84
|
+
# Jupyter Notebook
|
|
85
|
+
.ipynb_checkpoints
|
|
86
|
+
|
|
87
|
+
# IPython
|
|
88
|
+
profile_default/
|
|
89
|
+
ipython_config.py
|
|
90
|
+
|
|
91
|
+
# pyenv
|
|
92
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
93
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
94
|
+
# .python-version
|
|
95
|
+
|
|
96
|
+
# pipenv
|
|
97
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
98
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
99
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
100
|
+
# install all needed dependencies.
|
|
101
|
+
#Pipfile.lock
|
|
102
|
+
|
|
103
|
+
# poetry
|
|
104
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
105
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
106
|
+
# commonly ignored for libraries.
|
|
107
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
108
|
+
#poetry.lock
|
|
109
|
+
|
|
110
|
+
# pdm
|
|
111
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
112
|
+
#pdm.lock
|
|
113
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
114
|
+
# in version control.
|
|
115
|
+
# https://pdm.fming.dev/#use-with-ide
|
|
116
|
+
.pdm.toml
|
|
117
|
+
|
|
118
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
119
|
+
__pypackages__/
|
|
120
|
+
|
|
121
|
+
# Celery stuff
|
|
122
|
+
celerybeat-schedule
|
|
123
|
+
celerybeat.pid
|
|
124
|
+
|
|
125
|
+
# SageMath parsed files
|
|
126
|
+
*.sage.py
|
|
127
|
+
|
|
128
|
+
# Environments
|
|
129
|
+
.env
|
|
130
|
+
.venv
|
|
131
|
+
env/
|
|
132
|
+
venv/
|
|
133
|
+
ENV/
|
|
134
|
+
env.bak/
|
|
135
|
+
venv.bak/
|
|
136
|
+
|
|
137
|
+
# Spyder project settings
|
|
138
|
+
.spyderproject
|
|
139
|
+
.spyproject
|
|
140
|
+
|
|
141
|
+
# Rope project settings
|
|
142
|
+
.ropeproject
|
|
143
|
+
|
|
144
|
+
# mkdocs documentation
|
|
145
|
+
/site
|
|
146
|
+
|
|
147
|
+
# mypy
|
|
148
|
+
.mypy_cache/
|
|
149
|
+
.dmypy.json
|
|
150
|
+
dmypy.json
|
|
151
|
+
|
|
152
|
+
# Pyre type checker
|
|
153
|
+
.pyre/
|
|
154
|
+
|
|
155
|
+
# pytype static type analyzer
|
|
156
|
+
.pytype/
|
|
157
|
+
|
|
158
|
+
# Cython debug symbols
|
|
159
|
+
cython_debug/
|
|
160
|
+
|
|
161
|
+
# PyCharm
|
|
162
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
163
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
164
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
165
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
166
|
+
#.idea/
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
# Coding Rules
|
|
2
|
+
|
|
3
|
+
## 1. KISS First, Always
|
|
4
|
+
|
|
5
|
+
**Keep It Simple, Stupid.**
|
|
6
|
+
|
|
7
|
+
- Prefer straightforward logic over clever tricks or patterns.
|
|
8
|
+
- If a junior developer couldn’t explain the code in 2–3 sentences, it’s too complex.
|
|
9
|
+
- Avoid unnecessary indirection (e.g., “manager of managers”, nested factories, etc.).
|
|
10
|
+
|
|
11
|
+
**Agent behavior:**
|
|
12
|
+
|
|
13
|
+
- Default to the simplest solution that satisfies the requirements.
|
|
14
|
+
- Do not introduce abstractions or patterns unless they clearly simplify the codebase.
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## 2. Be Ruthlessly DRY (But Not Dogmatic)
|
|
19
|
+
|
|
20
|
+
**Don’t Repeat Yourself**, especially for logic and behavior.
|
|
21
|
+
|
|
22
|
+
- Extract shared logic into well-named functions or modules.
|
|
23
|
+
- Avoid copy-pasting the same behavior across files or components.
|
|
24
|
+
- However, don’t create convoluted abstractions just to deduplicate a few similar lines.
|
|
25
|
+
|
|
26
|
+
**Agent behavior:**
|
|
27
|
+
|
|
28
|
+
- Look for repeated logic; encapsulate it in reusable functions.
|
|
29
|
+
- Prefer small, meaningful helper functions over generic “doEverythingUtil” helpers.
|
|
30
|
+
- It’s okay to repeat a tiny bit of code if abstraction would obscure intent.
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## 3. Avoid Over-Abstraction
|
|
35
|
+
|
|
36
|
+
Abstractions must **earn their keep**.
|
|
37
|
+
|
|
38
|
+
- Only abstract when there are **real, repeated patterns** and they are stable.
|
|
39
|
+
- Don’t build meta-frameworks, super-generic base classes, or over-generic utilities.
|
|
40
|
+
- If an abstraction makes the mental model harder to understand, don’t add it.
|
|
41
|
+
|
|
42
|
+
**Agent behavior:**
|
|
43
|
+
|
|
44
|
+
- Prefer concrete, domain-specific functions over hyper-generic helpers.
|
|
45
|
+
- Do not introduce complex inheritance trees or deep hierarchies.
|
|
46
|
+
- Avoid “just in case” abstraction for hypothetical future use.
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## 4. Avoid Over-Engineering
|
|
51
|
+
|
|
52
|
+
Design for **today’s real requirements**, not every hypothetical tomorrow.
|
|
53
|
+
|
|
54
|
+
- Apply **YAGNI**: You Aren’t Gonna Need It.
|
|
55
|
+
- Don’t add features, flags, extension points, or layers until there is a proven need.
|
|
56
|
+
- Avoid gold-plating: extra complexity without clear value.
|
|
57
|
+
|
|
58
|
+
**Agent behavior:**
|
|
59
|
+
|
|
60
|
+
- Implement only what is explicitly required or what is obviously necessary to make it robust.
|
|
61
|
+
- Do not speculate about future requirements or build for imaginary extensibility.
|
|
62
|
+
|
|
63
|
+
---
|
|
64
|
+
|
|
65
|
+
## 5. Fail Fast, Don’t “Fallback Forever”
|
|
66
|
+
|
|
67
|
+
Too many fallbacks signal **low confidence** in the design.
|
|
68
|
+
|
|
69
|
+
- Each fallback should be **intentional**, **rare**, and **well-understood**.
|
|
70
|
+
- Prefer clear failure with good error messages over silently cascading through many fallbacks.
|
|
71
|
+
- “Try this, if not then this, then that, then that…” is a smell.
|
|
72
|
+
|
|
73
|
+
**Agent behavior:**
|
|
74
|
+
|
|
75
|
+
- Implement at most one or two clear, well-documented fallback paths where truly needed.
|
|
76
|
+
- When something is critical, fail fast with a clear error rather than guessing.
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## 6. No Blanket Try/Catch as a Safety Blanket
|
|
81
|
+
|
|
82
|
+
Defensive coding is good; paranoia everywhere is not.
|
|
83
|
+
|
|
84
|
+
- Catch exceptions **only where they can be handled meaningfully**.
|
|
85
|
+
- Avoid blanket `catch (Exception)` / `try/except` sprinkled around every function.
|
|
86
|
+
- Unhandled exceptions should bubble up with context and be handled at a clear boundary (e.g., top-level handler, API boundary).
|
|
87
|
+
|
|
88
|
+
**Agent behavior:**
|
|
89
|
+
|
|
90
|
+
- Place try/catch/try-except blocks around specific risky operations, not whole functions.
|
|
91
|
+
- When catching, either:
|
|
92
|
+
- recover in a well-defined way, or
|
|
93
|
+
- log and rethrow / propagate with context.
|
|
94
|
+
- Do not hide failures or swallow exceptions silently.
|
|
95
|
+
|
|
96
|
+
---
|
|
97
|
+
|
|
98
|
+
## 7. Prefer Functional, Side-Effect-Minimal Code
|
|
99
|
+
|
|
100
|
+
Predictable code is easier to test and reason about.
|
|
101
|
+
|
|
102
|
+
- Functions should have clear inputs and outputs.
|
|
103
|
+
- Minimize hidden state and unexpected side effects.
|
|
104
|
+
- Side-effectful functions should have names that make side effects obvious (e.g., `saveUser`, `sendEmail`, `logEvent`).
|
|
105
|
+
|
|
106
|
+
**Agent behavior:**
|
|
107
|
+
|
|
108
|
+
- Decompose complex procedures into small, purpose-focused functions.
|
|
109
|
+
- When possible, keep helpers pure (no I/O, no global state changes).
|
|
110
|
+
- Make side effects explicit and isolated.
|
|
111
|
+
|
|
112
|
+
---
|
|
113
|
+
|
|
114
|
+
## 8. Optimize for Human Readability Over Cleverness
|
|
115
|
+
|
|
116
|
+
Code is read far more than it’s written.
|
|
117
|
+
|
|
118
|
+
- Choose clarity over micro-optimizations unless profiling proves a real need.
|
|
119
|
+
- Use meaningful names; avoid abbreviations and cryptic naming.
|
|
120
|
+
- If the “clever” version needs a long comment to explain it, write the obvious version instead.
|
|
121
|
+
|
|
122
|
+
**Agent behavior:**
|
|
123
|
+
|
|
124
|
+
- Prefer explicit loops and conditionals over complex one-liners or deeply nested expressions.
|
|
125
|
+
- Add short, focused comments where intent is not obvious from the code itself.
|
|
126
|
+
- Respect existing naming and style conventions in the repo.
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## 9. Keep Modules Small, Cohesive, and Well-Bounded
|
|
131
|
+
|
|
132
|
+
Good structure reduces complexity.
|
|
133
|
+
|
|
134
|
+
- Each module/class/component should do **one thing well**.
|
|
135
|
+
- Avoid “god objects” and massive utility modules that know about everything.
|
|
136
|
+
- Boundaries between modules should be clear and logical.
|
|
137
|
+
|
|
138
|
+
**Agent behavior:**
|
|
139
|
+
|
|
140
|
+
- Group related code together; don’t scatter related behavior across many files without reason.
|
|
141
|
+
- When adding new functionality, consider whether it fits an existing module or deserves a small new one.
|
|
142
|
+
- Don’t introduce cross-cutting dependencies that tangle unrelated parts of the codebase.
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## 10. Build for Maintainability: Tests, Logs, and Contracts
|
|
147
|
+
|
|
148
|
+
Confidence comes from **design + verification**, not from piles of fallback logic.
|
|
149
|
+
|
|
150
|
+
- Add tests around critical and non-obvious logic.
|
|
151
|
+
- Validate inputs where appropriate and fail with clear messages.
|
|
152
|
+
- Log at meaningful boundaries with actionable, non-noisy messages.
|
|
153
|
+
|
|
154
|
+
**Agent behavior:**
|
|
155
|
+
|
|
156
|
+
- When adding complex logic, also add or update tests.
|
|
157
|
+
- Prefer simple, focused tests that check behavior over overly clever or brittle tests.
|
|
158
|
+
- Use logging thoughtfully: enough to help debug, not so much that it becomes noise.
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
## Summary for Agents
|
|
163
|
+
|
|
164
|
+
When generating or modifying code in this repository, ask:
|
|
165
|
+
|
|
166
|
+
1. **Is this the simplest solution that clearly solves the problem?**
|
|
167
|
+
2. **Am I repeating logic that should be shared?**
|
|
168
|
+
3. **Am I introducing abstractions or fallbacks just to feel “safe” rather than because they’re needed?**
|
|
169
|
+
4. **Will a human reading this code later quickly understand what it does and why?**
|
|
170
|
+
|
|
171
|
+
If the answer to any of these is “no” or “not really”, rewrite until it is.
|
|
172
|
+
|
|
173
|
+
Agents must prioritize:
|
|
174
|
+
**KISS → DRY → Readable → Maintainable**
|
|
175
|
+
over cleverness, over-engineering, and defensive complexity.
|