Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a pre-commit configuration to enable automatic linting with ruff #1105

Merged
merged 5 commits into from
Aug 20, 2024
Merged
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
9 changes: 9 additions & 0 deletions .github/workflows/dymos_tests_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,15 @@ jobs:
python -m pip install ruff
ruff check . --select NPY201

- name: Perform linting with Ruff
if: ${{ matrix.NAME == 'baseline' }}
run: |
echo "============================================================="
echo "Lint Dymos code per settings in pyproject.toml"
echo "============================================================="
python -m pip install ruff
ruff check . --config pyproject.toml

- name: Run tests
if: env.RUN_BUILD
env:
Expand Down
8 changes: 8 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version (update periodically by running 'pre-commit autoupdate')
rev: v0.6.1
hooks:
# Run the linter.
- id: ruff
types_or: [ python, pyi, jupyter ]
6 changes: 3 additions & 3 deletions docs/dymos_book/api/phase_api.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@
"# This cell is mandatory in all Dymos documentation notebooks.\n",
"missing_packages = []\n",
"try:\n",
" import openmdao.api as om\n",
" import openmdao.api as om # noqa: F401\n",
"except ImportError:\n",
" if 'google.colab' in str(get_ipython()):\n",
" !python -m pip install openmdao[notebooks]\n",
" else:\n",
" missing_packages.append('openmdao')\n",
"try:\n",
" import dymos as dm\n",
" import dymos as dm # noqa: F401\n",
"except ImportError:\n",
" if 'google.colab' in str(get_ipython()):\n",
" !python -m pip install dymos\n",
" else:\n",
" missing_packages.append('dymos')\n",
"try:\n",
" import pyoptsparse\n",
" import pyoptsparse # noqa: F401\n",
"except ImportError:\n",
" if 'google.colab' in str(get_ipython()):\n",
" !pip install -q condacolab\n",
Expand Down
6 changes: 3 additions & 3 deletions docs/dymos_book/api/run_problem_function.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@
"# This cell is mandatory in all Dymos documentation notebooks.\n",
"missing_packages = []\n",
"try:\n",
" import openmdao.api as om\n",
" import openmdao.api as om # noqa: F401\n",
"except ImportError:\n",
" if 'google.colab' in str(get_ipython()):\n",
" !python -m pip install openmdao[notebooks]\n",
" else:\n",
" missing_packages.append('openmdao')\n",
"try:\n",
" import dymos as dm\n",
" import dymos as dm # noqa: F401\n",
"except ImportError:\n",
" if 'google.colab' in str(get_ipython()):\n",
" !python -m pip install dymos\n",
" else:\n",
" missing_packages.append('dymos')\n",
"try:\n",
" import pyoptsparse\n",
" import pyoptsparse # noqa: F401\n",
"except ImportError:\n",
" if 'google.colab' in str(get_ipython()):\n",
" !pip install -q condacolab\n",
Expand Down
6 changes: 3 additions & 3 deletions docs/dymos_book/api/trajectory_api.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@
"# This cell is mandatory in all Dymos documentation notebooks.\n",
"missing_packages = []\n",
"try:\n",
" import openmdao.api as om\n",
" import openmdao.api as om # noqa: F401\n",
"except ImportError:\n",
" if 'google.colab' in str(get_ipython()):\n",
" !python -m pip install openmdao[notebooks]\n",
" else:\n",
" missing_packages.append('openmdao')\n",
"try:\n",
" import dymos as dm\n",
" import dymos as dm # noqa: F401\n",
"except ImportError:\n",
" if 'google.colab' in str(get_ipython()):\n",
" !python -m pip install dymos\n",
" else:\n",
" missing_packages.append('dymos')\n",
"try:\n",
" import pyoptsparse\n",
" import pyoptsparse # noqa: F401\n",
"except ImportError:\n",
" if 'google.colab' in str(get_ipython()):\n",
" !pip install -q condacolab\n",
Expand Down
6 changes: 3 additions & 3 deletions docs/dymos_book/api/transcriptions_api.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@
"# This cell is mandatory in all Dymos documentation notebooks.\n",
"missing_packages = []\n",
"try:\n",
" import openmdao.api as om\n",
" import openmdao.api as om # noqa: F401\n",
"except ImportError:\n",
" if 'google.colab' in str(get_ipython()):\n",
" !python -m pip install openmdao[notebooks]\n",
" else:\n",
" missing_packages.append('openmdao')\n",
"try:\n",
" import dymos as dm\n",
" import dymos as dm # noqa: F401\n",
"except ImportError:\n",
" if 'google.colab' in str(get_ipython()):\n",
" !python -m pip install dymos\n",
" else:\n",
" missing_packages.append('dymos')\n",
"try:\n",
" import pyoptsparse\n",
" import pyoptsparse # noqa: F401\n",
"except ImportError:\n",
" if 'google.colab' in str(get_ipython()):\n",
" !pip install -q condacolab\n",
Expand Down
14 changes: 7 additions & 7 deletions docs/dymos_book/contributing/contributing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@
"# This cell is mandatory in all Dymos documentation notebooks.\n",
"missing_packages = []\n",
"try:\n",
" import openmdao.api as om\n",
" import openmdao.api as om # noqa: F401\n",
"except ImportError:\n",
" if 'google.colab' in str(get_ipython()):\n",
" !python -m pip install openmdao[notebooks]\n",
" else:\n",
" missing_packages.append('openmdao')\n",
"try:\n",
" import dymos as dm\n",
" import dymos as dm # noqa: F401\n",
"except ImportError:\n",
" if 'google.colab' in str(get_ipython()):\n",
" !python -m pip install dymos\n",
" else:\n",
" missing_packages.append('dymos')\n",
"try:\n",
" import pyoptsparse\n",
" import pyoptsparse # noqa: F401\n",
"except ImportError:\n",
" if 'google.colab' in str(get_ipython()):\n",
" !pip install -q condacolab\n",
Expand Down Expand Up @@ -108,13 +108,13 @@
"outputs": [],
"source": [
"try:\n",
" import openmdao.api as om\n",
" import dymos as dm\n",
" import openmdao.api as om # noqa: F401\n",
" import dymos as dm # noqa: F401\n",
"except ModuleNotFoundError:\n",
" !python -m pip install openmdao[notebooks]\n",
" !python -m pip install dymos\n",
" import openmdao.api as om\n",
" import dymos as dm"
" import openmdao.api as om # noqa: F401\n",
" import dymos as dm # noqa: F401"
]
},
{
Expand Down
8 changes: 4 additions & 4 deletions docs/dymos_book/examples/balanced_field/balanced_field.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@
"# This cell is mandatory in all Dymos documentation notebooks.\n",
"missing_packages = []\n",
"try:\n",
" import openmdao.api as om\n",
" import openmdao.api as om # noqa: F401\n",
"except ImportError:\n",
" if 'google.colab' in str(get_ipython()):\n",
" !python -m pip install openmdao[notebooks]\n",
" else:\n",
" missing_packages.append('openmdao')\n",
"try:\n",
" import dymos as dm\n",
" import dymos as dm # noqa: F401\n",
"except ImportError:\n",
" if 'google.colab' in str(get_ipython()):\n",
" !python -m pip install dymos\n",
" else:\n",
" missing_packages.append('dymos')\n",
"try:\n",
" import pyoptsparse\n",
" import pyoptsparse # noqa: F401\n",
"except ImportError:\n",
" if 'google.colab' in str(get_ipython()):\n",
" !pip install -q condacolab\n",
Expand Down Expand Up @@ -747,7 +747,7 @@
" textcoords='axes fraction', arrowprops=dict(arrowstyle='->'),\n",
" horizontalalignment='center', verticalalignment='top')\n",
"\n",
"axes[0].annotate(f'', xy=(tf_rto, rf_rto),\n",
"axes[0].annotate('', xy=(tf_rto, rf_rto),\n",
" xycoords='data', xytext=(0.7, 0.5),\n",
" textcoords='axes fraction', arrowprops=dict(arrowstyle='->'),\n",
" horizontalalignment='center', verticalalignment='top')\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@
"# This cell is mandatory in all Dymos documentation notebooks.\n",
"missing_packages = []\n",
"try:\n",
" import openmdao.api as om\n",
" import openmdao.api as om # noqa: F401\n",
"except ImportError:\n",
" if 'google.colab' in str(get_ipython()):\n",
" !python -m pip install openmdao[notebooks]\n",
" else:\n",
" missing_packages.append('openmdao')\n",
"try:\n",
" import dymos as dm\n",
" import dymos as dm # noqa: F401\n",
"except ImportError:\n",
" if 'google.colab' in str(get_ipython()):\n",
" !python -m pip install dymos\n",
" else:\n",
" missing_packages.append('dymos')\n",
"try:\n",
" import pyoptsparse\n",
" import pyoptsparse # noqa: F401\n",
"except ImportError:\n",
" if 'google.colab' in str(get_ipython()):\n",
" !pip install -q condacolab\n",
Expand Down Expand Up @@ -274,7 +274,6 @@
"source": [
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"import openmdao.api as om\n",
"from openmdao.utils.general_utils import set_pyoptsparse_opt\n",
"import dymos as dm\n",
"\n",
Expand Down Expand Up @@ -486,7 +485,7 @@
" textcoords='axes fraction', arrowprops=dict(arrowstyle='->'),\n",
" horizontalalignment='center', verticalalignment='top')\n",
"\n",
"axes[0].annotate(f'', xy=(tf_rto, rf_rto),\n",
"axes[0].annotate('', xy=(tf_rto, rf_rto),\n",
" xycoords='data', xytext=(0.7, 0.5),\n",
" textcoords='axes fraction', arrowprops=dict(arrowstyle='->'),\n",
" horizontalalignment='center', verticalalignment='top')\n",
Expand Down
32 changes: 16 additions & 16 deletions docs/dymos_book/examples/brachistochrone/brachistochrone.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@
"# This cell is mandatory in all Dymos documentation notebooks.\n",
"missing_packages = []\n",
"try:\n",
" import openmdao.api as om\n",
" import openmdao.api as om # noqa: F401\n",
"except ImportError:\n",
" if 'google.colab' in str(get_ipython()):\n",
" !python -m pip install openmdao[notebooks]\n",
" else:\n",
" missing_packages.append('openmdao')\n",
"try:\n",
" import dymos as dm\n",
" import dymos as dm # noqa: F401\n",
"except ImportError:\n",
" if 'google.colab' in str(get_ipython()):\n",
" !python -m pip install dymos\n",
" else:\n",
" missing_packages.append('dymos')\n",
"try:\n",
" import pyoptsparse\n",
" import pyoptsparse # noqa: F401\n",
"except ImportError:\n",
" if 'google.colab' in str(get_ipython()):\n",
" !pip install -q condacolab\n",
Expand Down Expand Up @@ -75,19 +75,19 @@
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [
"active-ipynb",
"remove-input",
"remove-output"
]
},
"outputs": [],
"source": [
"%matplotlib inline"
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [
"active-ipynb",
"remove-input",
"remove-output"
]
},
"outputs": [],
"source": [
"%matplotlib inline"
]
},
{
"cell_type": "code",
Expand All @@ -102,7 +102,7 @@
"import numpy as np\n",
"\n",
"import matplotlib.pyplot as plt\n",
"from matplotlib.patches import FancyArrowPatch, Arc\n",
"from matplotlib.patches import FancyArrowPatch\n",
"\n",
"LW = 2\n",
"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@
"# This cell is mandatory in all Dymos documentation notebooks.\n",
"missing_packages = []\n",
"try:\n",
" import openmdao.api as om\n",
" import openmdao.api as om # noqa: F401\n",
"except ImportError:\n",
" if 'google.colab' in str(get_ipython()):\n",
" !python -m pip install openmdao[notebooks]\n",
" else:\n",
" missing_packages.append('openmdao')\n",
"try:\n",
" import dymos as dm\n",
" import dymos as dm # noqa: F401\n",
"except ImportError:\n",
" if 'google.colab' in str(get_ipython()):\n",
" !python -m pip install dymos\n",
" else:\n",
" missing_packages.append('dymos')\n",
"try:\n",
" import pyoptsparse\n",
" import pyoptsparse # noqa: F401\n",
"except ImportError:\n",
" if 'google.colab' in str(get_ipython()):\n",
" !pip install -q condacolab\n",
Expand Down Expand Up @@ -309,10 +309,9 @@
"source": [
"import pathlib\n",
"\n",
"from bokeh.plotting import figure, show, output_notebook, output_file, save\n",
"from bokeh.plotting import figure, output_file, save\n",
"\n",
"from bokeh.palettes import d3\n",
"from bokeh.resources import INLINE\n",
"from bokeh.models import Legend\n",
"\n",
"from IPython.display import HTML\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@
"# This cell is mandatory in all Dymos documentation notebooks.\n",
"missing_packages = []\n",
"try:\n",
" import openmdao.api as om\n",
" import openmdao.api as om # noqa: F401\n",
"except ImportError:\n",
" if 'google.colab' in str(get_ipython()):\n",
" !python -m pip install openmdao[notebooks]\n",
" else:\n",
" missing_packages.append('openmdao')\n",
"try:\n",
" import dymos as dm\n",
" import dymos as dm # noqa: F401\n",
"except ImportError:\n",
" if 'google.colab' in str(get_ipython()):\n",
" !python -m pip install dymos\n",
" else:\n",
" missing_packages.append('dymos')\n",
"try:\n",
" import pyoptsparse\n",
" import pyoptsparse # noqa: F401\n",
"except ImportError:\n",
" if 'google.colab' in str(get_ipython()):\n",
" !pip install -q condacolab\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,21 @@
"# This cell is mandatory in all Dymos documentation notebooks.\n",
"missing_packages = []\n",
"try:\n",
" import openmdao.api as om\n",
" import openmdao.api as om # noqa: F401\n",
"except ImportError:\n",
" if 'google.colab' in str(get_ipython()):\n",
" !python -m pip install openmdao[notebooks]\n",
" else:\n",
" missing_packages.append('openmdao')\n",
"try:\n",
" import dymos as dm\n",
" import dymos as dm # noqa: F401\n",
"except ImportError:\n",
" if 'google.colab' in str(get_ipython()):\n",
" !python -m pip install dymos\n",
" else:\n",
" missing_packages.append('dymos')\n",
"try:\n",
" import pyoptsparse\n",
" import pyoptsparse # noqa: F401\n",
"except ImportError:\n",
" if 'google.colab' in str(get_ipython()):\n",
" !pip install -q condacolab\n",
Expand Down
Loading
Loading