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
35 changes: 35 additions & 0 deletions .github/workflows/rocprofiler-sdk-formatting.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

name: rocprofiler-sdk Formatting

permissions:
contents: read

on:
workflow_dispatch:
pull_request:
Expand Down Expand Up @@ -175,3 +178,35 @@ jobs:
cat ${OUTFILE}
exit 1
fi

config_yaml:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v4
with:
sparse-checkout: projects/rocprofiler-sdk

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.10'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install ruamel.yaml

- name: Ensure config.yaml is formatted
working-directory: projects/rocprofiler-sdk
run: |
python source/scripts/format-deps.py --counter-config
if [ $(git diff -- source/share/rocprofiler-sdk/config.yaml | wc -l) -ne 0 ]; then
echo ""
echo "::error::YAML file is not properly formatted. Run the following command to fix:"
echo ""
echo " cd projects/rocprofiler-sdk && python source/scripts/format-deps.py --counter-config"
echo ""
git diff -- source/share/rocprofiler-sdk/config.yaml
exit 1
fi
1 change: 1 addition & 0 deletions projects/rocprofiler-sdk/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ pycobertura
pytest
pyyaml
reportlab
ruamel.yaml
31 changes: 30 additions & 1 deletion projects/rocprofiler-sdk/source/scripts/format-deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@


import argparse
import io
import os
import sys
from pathlib import Path

from ruamel.yaml import YAML


class FormatSource(argparse.Action):
Expand Down Expand Up @@ -64,6 +68,23 @@ def __call__(self, parser, namespace, values, option_string=None):
exit(0)


class FormatYAML(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
yaml = YAML()
yaml.preserve_quotes = True
yaml.width = 120
yaml.indent(mapping=2, sequence=4, offset=2)
config = (
Path(os.path.dirname(__file__))
/ "../../source/share/rocprofiler-sdk/config.yaml"
).resolve()
data = yaml.load(config.read_text())
stream = io.StringIO()
yaml.dump(data, stream)
config.write_text(stream.getvalue())
exit(0)


class FormatAll(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
os.system(
Expand All @@ -87,6 +108,7 @@ def __call__(self, parser, namespace, values, option_string=None):
+ "/../../external/*\" | egrep 'CMakeLists.txt|\.cmake$')"
)
os.system("black " + os.path.dirname(__file__) + "/../..")
FormatYAML.__call__(FormatYAML, parser, namespace, values, option_string)
exit(0)


Expand Down Expand Up @@ -118,6 +140,13 @@ def __call__(self, parser, namespace, values, option_string=None):
"-p", "--python", nargs=0, help="format python files", action=FormatPython
)
parser.add_argument(
"-a", "--all", nargs=0, help="format cmake, source and python files", action=FormatAll
"-cc", "--counter-config", nargs=0, help="format config.yaml", action=FormatYAML
)
parser.add_argument(
"-a",
"--all",
nargs=0,
help="format cmake, source, python, and yaml files",
action=FormatAll,
)
parser.parse_args()
Loading
Loading