Skip to content

Commit

Permalink
feat: add yaml linting and formatting to pre-commit (#332)
Browse files Browse the repository at this point in the history
* feat: added yaml linting and formatting to pre-commit hook

* feat: added yaml linting and formatting to pre-commit hook

* fix: revert approval test files and ignore yaml formatting on them

* fix: revert approval test files and ignore yaml formatting on them

* fix: space reference
  • Loading branch information
nodegard authored Mar 19, 2024
1 parent 2230944 commit f9bd750
Show file tree
Hide file tree
Showing 174 changed files with 68,537 additions and 68,674 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
---
name: build

on:
Expand Down Expand Up @@ -34,8 +33,8 @@ jobs:
python-version:
- "3.9"
# Assume these are covered by 3.12
# - "3.10"
# - "3.11"
# - "3.10"
# - "3.11"
- "3.12"
steps:
- uses: actions/checkout@v4
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
---
name: release

on:
push:
branches: [main]

env:
PYTHON_VERSION: '3.9'
PYTHON_VERSION: "3.9"

jobs:
lint:
Expand Down Expand Up @@ -61,5 +60,4 @@ jobs:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
shell: bash
run:
twine upload --skip-existing --verbose dist/*
run: twine upload --skip-existing --verbose dist/*
97 changes: 54 additions & 43 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,43 +1,54 @@
---
repos:
- repo: https://github.com/psf/black
rev: 24.1.1
hooks:
- id: black

- repo: https://github.com/charliermarsh/ruff-pre-commit
# Ruff version.
rev: 'v0.0.292'
hooks:
- id: ruff
args:
- --fix
- --exit-non-zero-on-fix
- --config=pyproject.toml

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: debug-statements
- id: trailing-whitespace
- id: check-builtin-literals
- id: end-of-file-fixer
- id: check-ast
- id: check-docstring-first

- repo: https://github.com/frnhr/pre-commit-nocommit
rev: 0.0.1
hooks:
- id: check-nocommit

# Mypy must be run in the local system environment, not in the pre-commit environment.
- hooks:
- id: mypy
name: mypy
# Gradually, the entire codebase should be checked by mypy, plan is to gradually add mypy for each
# module as we refactor it.
entry: dmypy run -- cognite/powerops/resync cognite/powerops/utils
files: ^.*.(py|pyi)$
language: system
pass_filenames: false
repo: local
repos:
- repo: https://github.com/psf/black
rev: 24.1.1
hooks:
- id: black

- repo: https://github.com/charliermarsh/ruff-pre-commit
# Ruff version.
rev: "v0.0.292"
hooks:
- id: ruff
args:
- --fix
- --exit-non-zero-on-fix
- --config=pyproject.toml

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-ast
- id: check-builtin-literals
- id: check-docstring-first
- id: check-yaml
exclude: "mkdocs.yml|^test_apply/demo_.*.yml"
- id: debug-statements
- id: end-of-file-fixer
- id: name-tests-test
args:
- --pytest-test-first
exclude: "constants.py|mock_.*.py"
- id: no-commit-to-branch
- id: trailing-whitespace

- repo: https://github.com/google/yamlfmt
rev: v0.10.0
hooks:
- id: yamlfmt

- repo: https://github.com/frnhr/pre-commit-nocommit
rev: 0.0.1
hooks:
- id: check-nocommit

# Mypy must be run in the local system environment, not in the pre-commit environment.
- repo: local
hooks:
- id: mypy
name: mypy
# Gradually, the entire codebase should be checked by mypy, plan is to gradually add mypy for each
# module as we refactor it.
entry: dmypy run -- cognite/powerops/resync cognite/powerops/utils
files: ^.*.(py|pyi)$
language: system
pass_filenames: false
8 changes: 8 additions & 0 deletions .yamlfmt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
doublestar: true
exclude:
- "**/test_apply/demo_*.yml"
formatter:
type: basic
disallow_anchors: true
retain_line_breaks: true
retain_line_breaks_single: true
112 changes: 56 additions & 56 deletions cognite/powerops/config.dev.yaml
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
environment:
name: dev
project: power-ops-staging
type: dev
selected_modules_and_packages:
- power_model_v1

modules:
custom_modules:
power_model_v1:
powerops_type_space: 'sp_powerops_types'
powerops_instance_space: 'sp_powerops_instance'
powerops_models: 'sp_powerops_models'
version: '1'
power_model_v0:
# variables used for substitution in other files in this directory
afrr_model_space: 'power-ops-afrr-bid'
dayahead_model_space: 'power-ops-day-ahead-bid'
shared_model_space: 'power-ops-shared'
type_space: 'power-ops-types'
powerops_instance_space: 'power-ops-instance'
asset_space: 'power-ops-assets'

# Shared Model Views
base_BidDocument_version: '1'
base_Alert_version: '1'
base_BidMethod_version: '1'

# AFRR Bid Model Views
afrrbid_BidDocument_version: '1'
afrrbid_BidMethod_version: '1'
afrrbid_BidRow_version: '1'
afrrbid_PriceArea_version: '1'

# Day-Ahead Bid Model Views
dayaheadbid_BidDocument_version: '1'
dayaheadbid_BidMethod_version: '1'
dayaheadbid_BidMatrix_version: '1'
dayaheadbid_PriceArea_version: '1'
dayaheadbid_SHOPMultiScenarioMethod_version: '1'
dayaheadbid_MultiScenarioMatrix_version: '1'
dayaheadbid_CustomBidMethod_version: '1'
dayaheadbid_WaterValueBasedMethod_version: '1'
dayaheadbid_BasicBidMatrix_version: '1'
dayaheadbid_CustomBidMatrix_version: '1'
dayaheadbid_SHOPPriceScenario_version: '1'
dayaheadbid_SHOPPriceScenarioResult_version: '1'

# Asset Model Views
asset_PriceArea_version: '1'
asset_Watercourse_version: '1'
asset_Plant_version: '1'
asset_Generator_version: '1'
asset_Reservoir_version: '1'
asset_TurbineEfficiency_version: '1'
asset_GeneratorEfficiency_version: '1'
environment:
name: dev
project: power-ops-staging
type: dev
selected_modules_and_packages:
- power_model_v1

modules:
custom_modules:
power_model_v1:
powerops_type_space: 'sp_powerops_types'
powerops_instance_space: 'sp_powerops_instance'
powerops_models: 'sp_powerops_models'
version: '1'
power_model_v0:
# variables used for substitution in other files in this directory
afrr_model_space: 'power-ops-afrr-bid'
dayahead_model_space: 'power-ops-day-ahead-bid'
shared_model_space: 'power-ops-shared'
type_space: 'power-ops-types'
powerops_instance_space: 'power-ops-instance'
asset_space: 'power-ops-assets'

# Shared Model Views
base_BidDocument_version: '1'
base_Alert_version: '1'
base_BidMethod_version: '1'

# AFRR Bid Model Views
afrrbid_BidDocument_version: '1'
afrrbid_BidMethod_version: '1'
afrrbid_BidRow_version: '1'
afrrbid_PriceArea_version: '1'

# Day-Ahead Bid Model Views
dayaheadbid_BidDocument_version: '1'
dayaheadbid_BidMethod_version: '1'
dayaheadbid_BidMatrix_version: '1'
dayaheadbid_PriceArea_version: '1'
dayaheadbid_SHOPMultiScenarioMethod_version: '1'
dayaheadbid_MultiScenarioMatrix_version: '1'
dayaheadbid_CustomBidMethod_version: '1'
dayaheadbid_WaterValueBasedMethod_version: '1'
dayaheadbid_BasicBidMatrix_version: '1'
dayaheadbid_CustomBidMatrix_version: '1'
dayaheadbid_SHOPPriceScenario_version: '1'
dayaheadbid_SHOPPriceScenarioResult_version: '1'

# Asset Model Views
asset_PriceArea_version: '1'
asset_Watercourse_version: '1'
asset_Plant_version: '1'
asset_Generator_version: '1'
asset_Reservoir_version: '1'
asset_TurbineEfficiency_version: '1'
asset_GeneratorEfficiency_version: '1'
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
externalId: AFRRBid
space: '{{afrr_model_space}}'
version: '1'
space: "{{afrr_model_space}}"
version: "1"
name: AFRRBid
description: 'Stores results of AFRR bid calculations.'
description: "Stores results of AFRR bid calculations."
views:
- externalId: BidDocument
space: '{{afrr_model_space}}'
type: view
version: '{{afrrbid_BidDocument_version}}'
- externalId: BidRow
space: '{{afrr_model_space}}'
type: view
version: '{{afrrbid_BidRow_version}}'
- externalId: PriceArea
space: '{{afrr_model_space}}'
type: view
version: '{{afrrbid_PriceArea_version}}'
- externalId: BidMethod
space: '{{afrr_model_space}}'
type: view
version: '{{afrrbid_BidMethod_version}}'
- externalId: Alert
space: '{{shared_model_space}}'
type: view
version: '{{base_Alert_version}}'
- externalId: BidDocument
space: "{{afrr_model_space}}"
type: view
version: "{{afrrbid_BidDocument_version}}"
- externalId: BidRow
space: "{{afrr_model_space}}"
type: view
version: "{{afrrbid_BidRow_version}}"
- externalId: PriceArea
space: "{{afrr_model_space}}"
type: view
version: "{{afrrbid_PriceArea_version}}"
- externalId: BidMethod
space: "{{afrr_model_space}}"
type: view
version: "{{afrrbid_BidMethod_version}}"
- externalId: Alert
space: "{{shared_model_space}}"
type: view
version: "{{base_Alert_version}}"
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
externalId: PowerAsset
space: '{{asset_space}}'
version: '1'
space: "{{asset_space}}"
version: "1"
name: PowerAsset
description: 'Describes the power operations asset model'
description: "Describes the power operations asset model"
views:
- externalId: PriceArea
space: '{{asset_space}}'
type: view
version: '{{asset_PriceArea_version}}'
- externalId: Watercourse
space: '{{asset_space}}'
type: view
version: '{{asset_Watercourse_version}}'
- externalId: Plant
space: '{{asset_space}}'
type: view
version: '{{asset_Plant_version}}'
- externalId: Generator
space: '{{asset_space}}'
type: view
version: '{{asset_Generator_version}}'
- externalId: Reservoir
space: '{{asset_space}}'
type: view
version: '{{asset_Reservoir_version}}'
- externalId: TurbineEfficiencyCurve
space: '{{asset_space}}'
type: view
version: '{{asset_TurbineEfficiency_version}}'
- externalId: GeneratorEfficiencyCurve
space: '{{asset_space}}'
type: view
version: '{{asset_GeneratorEfficiency_version}}'
- externalId: BidMethod
space: '{{shared_model_space}}'
type: view
version: '{{base_BidMethod_version}}'
- externalId: PriceArea
space: "{{asset_space}}"
type: view
version: "{{asset_PriceArea_version}}"
- externalId: Watercourse
space: "{{asset_space}}"
type: view
version: "{{asset_Watercourse_version}}"
- externalId: Plant
space: "{{asset_space}}"
type: view
version: "{{asset_Plant_version}}"
- externalId: Generator
space: "{{asset_space}}"
type: view
version: "{{asset_Generator_version}}"
- externalId: Reservoir
space: "{{asset_space}}"
type: view
version: "{{asset_Reservoir_version}}"
- externalId: TurbineEfficiencyCurve
space: "{{asset_space}}"
type: view
version: "{{asset_TurbineEfficiency_version}}"
- externalId: GeneratorEfficiencyCurve
space: "{{asset_space}}"
type: view
version: "{{asset_GeneratorEfficiency_version}}"
- externalId: BidMethod
space: "{{shared_model_space}}"
type: view
version: "{{base_BidMethod_version}}"
Loading

0 comments on commit f9bd750

Please sign in to comment.