From 4b6ca28fe1ae9665234515a53345deb893773749 Mon Sep 17 00:00:00 2001 From: John Vouvakis Manousakis Date: Sat, 17 Aug 2024 04:05:37 -0700 Subject: [PATCH 1/5] Update Ruff workflows. Update GitHub actions workflows to use `chartboost/ruff-action@v1` to speed up the workflows. --- .github/workflows/format_check.yml | 27 ++++++--------------------- .github/workflows/lint.yml | 25 ++++--------------------- 2 files changed, 10 insertions(+), 42 deletions(-) diff --git a/.github/workflows/format_check.yml b/.github/workflows/format_check.yml index 9225af459..dca19a00f 100644 --- a/.github/workflows/format_check.yml +++ b/.github/workflows/format_check.yml @@ -1,25 +1,10 @@ -name: Format Check - +name: Ruff format on: [push, pull_request] - jobs: - format-check: + ruff: runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: '3.10' - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install ruff - - - name: Check code formatting - run: | - ruff check . --diff + - uses: actions/checkout@v4 + - uses: chartboost/ruff-action@v1 + with: + args: 'format --check' diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index c4fd6475b..744b4e642 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,25 +1,8 @@ -name: Lint - +name: Ruff check on: [push, pull_request] - jobs: - lint: + ruff: runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Set up Python - uses: actions/setup-python@v2 - with: - python-version: '3.10' - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install ruff - - - name: Run linter - run: | - ruff check . + - uses: actions/checkout@v4 + - uses: chartboost/ruff-action@v1 From 5f73e74e64912902995a1c43eee3d3f9eed0d5f5 Mon Sep 17 00:00:00 2001 From: John Vouvakis Manousakis Date: Sat, 17 Aug 2024 04:11:05 -0700 Subject: [PATCH 2/5] `ruff format` --- .../CleanBeamSectionDatabase.ipynb | 148 +++++++++--------- modules/performREC/pyrecodes/run_pyrecodes.py | 1 - 2 files changed, 74 insertions(+), 75 deletions(-) diff --git a/modules/createSAM/AutoSDA/Preprocessing/CleanBeamSectionDatabase.ipynb b/modules/createSAM/AutoSDA/Preprocessing/CleanBeamSectionDatabase.ipynb index 5e1cc9ae2..036c75a4b 100644 --- a/modules/createSAM/AutoSDA/Preprocessing/CleanBeamSectionDatabase.ipynb +++ b/modules/createSAM/AutoSDA/Preprocessing/CleanBeamSectionDatabase.ipynb @@ -1,74 +1,74 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Clean Beam Section Database" - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [ - { - "ename": "FileNotFoundError", - "evalue": "[Errno 2] No such file or directory: 'BeamDatabase.csv'", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mFileNotFoundError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mpandas\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0mpd\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[1;32mwith\u001b[0m \u001b[0mopen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'BeamDatabase.csv'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'r'\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0mfile\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 4\u001b[0m \u001b[0mbeam_section_database\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mpd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mread_csv\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfile\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mheader\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: 'BeamDatabase.csv'" - ] - } - ], - "source": [ - "import pandas as pd\n", - "\n", - "with open('BeamDatabase1.csv', 'r') as file:\n", - " beam_section_database = pd.read_csv(file, header=0)\n", - "\n", - "# Beam section weight shall be less than 300 lb/ft\n", - "# Beam flange thickness shall be less than 1.75 inch.\n", - "target_index = []\n", - "for indx in beam_section_database['index']:\n", - " if (beam_section_database.loc[indx, 'weight'] >= 300):\n", - " target_index.append(indx)\n", - " elif (beam_section_database.loc[indx, 'tf'] >= 1.75):\n", - " target_index.append(indx)\n", - "clean_beam_section = beam_section_database.drop(index=target_index)\n", - "clean_beam_section.to_csv('BeamDatabase2.csv', sep=',', index=False)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.6.5" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Clean Beam Section Database" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "ename": "FileNotFoundError", + "evalue": "[Errno 2] No such file or directory: 'BeamDatabase.csv'", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mFileNotFoundError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mpandas\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0mpd\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[1;32mwith\u001b[0m \u001b[0mopen\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'BeamDatabase.csv'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'r'\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0mfile\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 4\u001b[0m \u001b[0mbeam_section_database\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mpd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mread_csv\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfile\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mheader\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;36m0\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: 'BeamDatabase.csv'" + ] + } + ], + "source": [ + "import pandas as pd\n", + "\n", + "with open('BeamDatabase1.csv', 'r') as file:\n", + " beam_section_database = pd.read_csv(file, header=0)\n", + "\n", + "# Beam section weight shall be less than 300 lb/ft\n", + "# Beam flange thickness shall be less than 1.75 inch.\n", + "target_index = []\n", + "for indx in beam_section_database['index']:\n", + " if beam_section_database.loc[indx, 'weight'] >= 300:\n", + " target_index.append(indx)\n", + " elif beam_section_database.loc[indx, 'tf'] >= 1.75:\n", + " target_index.append(indx)\n", + "clean_beam_section = beam_section_database.drop(index=target_index)\n", + "clean_beam_section.to_csv('BeamDatabase2.csv', sep=',', index=False)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.6.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/modules/performREC/pyrecodes/run_pyrecodes.py b/modules/performREC/pyrecodes/run_pyrecodes.py index 7998e0aa6..ccd9783c2 100644 --- a/modules/performREC/pyrecodes/run_pyrecodes.py +++ b/modules/performREC/pyrecodes/run_pyrecodes.py @@ -504,4 +504,3 @@ def select_realizations_to_run(damage_input, inputRWHALE): # noqa: N803, D103 mpiExec=wfArgs.mpiexec, numPROC=numPROC, ) - From 4258790c346f35d01417bc7fd31cdfb82894196a Mon Sep 17 00:00:00 2001 From: John Vouvakis Manousakis Date: Sat, 17 Aug 2024 04:11:26 -0700 Subject: [PATCH 3/5] `ruff check --fix` --- .../AutoSDA/Preprocessing/CleanBeamSectionDatabase.ipynb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/modules/createSAM/AutoSDA/Preprocessing/CleanBeamSectionDatabase.ipynb b/modules/createSAM/AutoSDA/Preprocessing/CleanBeamSectionDatabase.ipynb index 036c75a4b..892ec8a1e 100644 --- a/modules/createSAM/AutoSDA/Preprocessing/CleanBeamSectionDatabase.ipynb +++ b/modules/createSAM/AutoSDA/Preprocessing/CleanBeamSectionDatabase.ipynb @@ -27,16 +27,14 @@ "source": [ "import pandas as pd\n", "\n", - "with open('BeamDatabase1.csv', 'r') as file:\n", + "with open('BeamDatabase1.csv') as file:\n", " beam_section_database = pd.read_csv(file, header=0)\n", "\n", "# Beam section weight shall be less than 300 lb/ft\n", "# Beam flange thickness shall be less than 1.75 inch.\n", "target_index = []\n", "for indx in beam_section_database['index']:\n", - " if beam_section_database.loc[indx, 'weight'] >= 300:\n", - " target_index.append(indx)\n", - " elif beam_section_database.loc[indx, 'tf'] >= 1.75:\n", + " if beam_section_database.loc[indx, 'weight'] >= 300 or beam_section_database.loc[indx, 'tf'] >= 1.75:\n", " target_index.append(indx)\n", "clean_beam_section = beam_section_database.drop(index=target_index)\n", "clean_beam_section.to_csv('BeamDatabase2.csv', sep=',', index=False)" From 4675b6779fcbbdaef36c805d6659a5b773433d0b Mon Sep 17 00:00:00 2001 From: John Vouvakis Manousakis Date: Sat, 17 Aug 2024 04:20:32 -0700 Subject: [PATCH 4/5] Add # noqa manually ruff check --add-noqa doesn't modify `.ipynb` files. --- .../AutoSDA/Preprocessing/CleanBeamSectionDatabase.ipynb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/modules/createSAM/AutoSDA/Preprocessing/CleanBeamSectionDatabase.ipynb b/modules/createSAM/AutoSDA/Preprocessing/CleanBeamSectionDatabase.ipynb index 892ec8a1e..abbe355f2 100644 --- a/modules/createSAM/AutoSDA/Preprocessing/CleanBeamSectionDatabase.ipynb +++ b/modules/createSAM/AutoSDA/Preprocessing/CleanBeamSectionDatabase.ipynb @@ -27,15 +27,18 @@ "source": [ "import pandas as pd\n", "\n", - "with open('BeamDatabase1.csv') as file:\n", + "with open('BeamDatabase1.csv') as file: # noqa: PTH123\n", " beam_section_database = pd.read_csv(file, header=0)\n", "\n", "# Beam section weight shall be less than 300 lb/ft\n", "# Beam flange thickness shall be less than 1.75 inch.\n", "target_index = []\n", "for indx in beam_section_database['index']:\n", - " if beam_section_database.loc[indx, 'weight'] >= 300 or beam_section_database.loc[indx, 'tf'] >= 1.75:\n", - " target_index.append(indx)\n", + " if (\n", + " beam_section_database.loc[indx, 'weight'] >= 300 # noqa: PLR2004\n", + " or beam_section_database.loc[indx, 'tf'] >= 1.75 # noqa: PLR2004\n", + " ):\n", + " target_index.append(indx) # noqa: PERF401\n", "clean_beam_section = beam_section_database.drop(index=target_index)\n", "clean_beam_section.to_csv('BeamDatabase2.csv', sep=',', index=False)" ] From 905704d48020441e6d6ee4457398fa5e02592e05 Mon Sep 17 00:00:00 2001 From: John Vouvakis Manousakis Date: Sat, 17 Aug 2024 04:35:20 -0700 Subject: [PATCH 5/5] Add syntax to ignore folders. --- pyproject.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 43fede178..29ad35b40 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,6 +7,9 @@ select = ["ALL"] ignore = ["ANN", "D211", "D212", "Q000", "Q003", "COM812", "D203", "ISC001", "E501", "ERA001", "PGH003", "FIX002", "TD003", "S101", "N801", "S311", "G004", "SIM102", "SIM108", "NPY002", "F401"] preview = false +[tool.ruff.lint.per-file-ignores] +"path/to/folder/*" = ["ALL"] + [tool.ruff.lint.pydocstyle] convention = "numpy"