diff --git a/.github/workflows/rocprofiler-compute-formatting.yml b/.github/workflows/rocprofiler-compute-formatting.yml index a586977bb0..da9ebcc28a 100644 --- a/.github/workflows/rocprofiler-compute-formatting.yml +++ b/.github/workflows/rocprofiler-compute-formatting.yml @@ -30,14 +30,26 @@ jobs: working-directory: projects/rocprofiler-compute run: | python -m pip install --upgrade pip - python -m pip install black isort + python -m pip install ruff if [ -f requirements.txt ]; then python -m pip install -r requirements.txt; fi - - name: Run black formatter - working-directory: projects/rocprofiler-compute - run: black . - - name: Run isort formatter - working-directory: projects/rocprofiler-compute - run: isort . + - name: Run Ruff Linter and Import Sorter + run: | + ruff check . --fix --exit-zero + - name: Run Ruff Formatter + run: | + ruff format . + - name: Check for formatting/linting changes + run: | + git config --global user.name 'github-actions' + git config --global user.email 'github-actions@github.com' + git add -A . + if ! git diff --cached --quiet; then + echo "::error::Files were modified by ruff. Please run 'ruff check . --fix && ruff format .' locally and commit the changes." + git diff --cached --patch # Show the diff in the logs + exit 1 + else + echo "Ruff found no issues or all issues were fixed and files are clean." + fi cmake: runs-on: ubuntu-22.04 diff --git a/projects/rocprofiler-compute/CONTRIBUTING.md b/projects/rocprofiler-compute/CONTRIBUTING.md index c733522505..c75c75c46b 100644 --- a/projects/rocprofiler-compute/CONTRIBUTING.md +++ b/projects/rocprofiler-compute/CONTRIBUTING.md @@ -52,6 +52,45 @@ Now, when you commit code to the repository you should see something like this: Please see the [pre-commit documentation](https://pre-commit.com/#quick-start) for additional information. +## Contribution Guidelines + +To ensure code quality and consistency, we use **Ruff**, a fast Python linter and formatter. Before submitting a pull request, please ensure your code is formatted and linted correctly. This is the manual alternative to running ruff pre-commit hooks. + +----- + +## Installing and Running Ruff + +Ruff is available on PyPI and can be installed using `pip`: + +```bash +pip install ruff +``` + +Once installed, you can run Ruff from the command line. To check for linting errors and formatting issues, navigate to the project root and run: + +```bash +ruff check . +ruff format --check . +``` + +To automatically fix most of the issues detected, you can use the `--fix` flag with the `check` command and run the `format` command without the `--check` flag: + +```bash +ruff check --fix . +ruff format . +``` + +----- + +## Disabling Formatting for Specific Sections + +There may be instances where you need to disable Ruff's formatting on a specific block of code. You can do this using special comments: + + * **`# fmt: off`** and **`# fmt: on`**: These comments can be used to disable and re-enable formatting for a block of code. + * **`# fmt: skip`**: This comment, placed at the end of a line, will prevent Ruff from formatting that specific statement. + +You can also disable specific linting rules for a line by using `# noqa: `. + ## Coding guidelines Below are some repository specific guidelines which are followed througout the repository. diff --git a/projects/rocprofiler-compute/README.md b/projects/rocprofiler-compute/README.md index 24d8744506..7f02ef397e 100644 --- a/projects/rocprofiler-compute/README.md +++ b/projects/rocprofiler-compute/README.md @@ -75,7 +75,7 @@ To build the binary we follow these steps: NOTE: Since RHEL 8 ships with glibc version 2.28, this standalone binary can only be run on environment with glibc version greater than 2.28. glibc version can be checked using `ldd --version` command. -NOTE: libnss3.so shared library is required when using --roof-only option which generates roofline data in PDF format +NOTE: libnss3.so shared library is required when using --roof-only option which generates roofline data in PDF format To test the standalone binary provide the `--call-binary` option to pytest. @@ -104,42 +104,3 @@ style reference is provided below for convenience: url = {https://doi.org/10.5281/zenodo.7314631} } ``` - -### Contribution Guidelines - -To ensure code quality and consistency, we use **Ruff**, a fast Python linter and formatter. Before submitting a pull request, please ensure your code is formatted and linted correctly. - ------ - -### Installing and Running Ruff - -Ruff is available on PyPI and can be installed using `pip`: - -```bash -pip install ruff -``` - -Once installed, you can run Ruff from the command line. To check for linting errors and formatting issues, navigate to the project root and run: - -```bash -ruff check . -ruff format --check . -``` - -To automatically fix most of the issues detected, you can use the `--fix` flag with the `check` command and run the `format` command without the `--check` flag: - -```bash -ruff check --fix . -ruff format . -``` - ------ - -### Disabling Formatting for Specific Sections - -There may be instances where you need to disable Ruff's formatting on a specific block of code. You can do this using special comments: - - * **`# fmt: off`** and **`# fmt: on`**: These comments can be used to disable and re-enable formatting for a block of code. - * **`# fmt: skip`**: This comment, placed at the end of a line, will prevent Ruff from formatting that specific statement. - -You can also disable specific linting rules for a line by using `# noqa: `. diff --git a/projects/rocprofiler-compute/docs/data/contributing/pre-commit-hook.png b/projects/rocprofiler-compute/docs/data/contributing/pre-commit-hook.png index d7af49d978..eb33431bde 100644 Binary files a/projects/rocprofiler-compute/docs/data/contributing/pre-commit-hook.png and b/projects/rocprofiler-compute/docs/data/contributing/pre-commit-hook.png differ diff --git a/projects/rocprofiler-compute/requirements.txt b/projects/rocprofiler-compute/requirements.txt index f5c699ea6e..ef0de785a2 100644 --- a/projects/rocprofiler-compute/requirements.txt +++ b/projects/rocprofiler-compute/requirements.txt @@ -16,4 +16,4 @@ tabulate textual textual_plotext textual-fspicker -tqdm \ No newline at end of file +tqdm