Skip to content

Commit

Permalink
Adopt ruff as the central tool for linting and formatting (#920)
Browse files Browse the repository at this point in the history
* Remove `setup.py` introduced accidentally by rebasing on `main`
* Fix `conda-forge` badge links to point to correct page
  • Loading branch information
tomvothecoder authored Jan 21, 2025
1 parent 5a1ac38 commit df39bf4
Show file tree
Hide file tree
Showing 125 changed files with 400 additions and 530 deletions.
32 changes: 13 additions & 19 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,27 @@ fail_fast: true

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml

- repo: https://github.com/psf/black
rev: 23.9.1
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.2
hooks:
- id: black

- repo: https://github.com/PyCQA/isort
rev: 5.12.0
hooks:
- id: isort

# Need to use flake8 GitHub mirror due to CentOS git issue with GitLab
# https://github.com/pre-commit/pre-commit/issues/1206
- repo: https://github.com/pycqa/flake8
rev: 6.1.0
hooks:
- id: flake8
args: [--config=setup.cfg]
additional_dependencies: [flake8-isort==6.1.0]
# Sort the imports
- id: ruff
name: ruff-sort-imports
args: [--select, I, --fix]
# Run the linter.
- id: ruff
args: [--fix]
# Run the formatter.
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.5.1
rev: v1.14.1
hooks:
- id: mypy
args: [--config=pyproject.toml]
Expand Down
6 changes: 2 additions & 4 deletions .vscode/e3sm_diags.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@
"editor.rulers": [80, 88, 120],
"editor.wordWrap": "wordWrapColumn",
"editor.wordWrapColumn": 120,
"editor.defaultFormatter": "ms-python.black-formatter"
"editor.defaultFormatter": "charliermarsh.ruff"
},
// Code Formatting and Linting
// ---------------------------
"flake8.args": ["--config=setup.cfg"],
"ruff.importStrategy": "fromEnvironment",
// Type checking
// ---------------------------
"mypy-type-checker.args": ["--config=pyproject.toml"],
Expand Down
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,12 @@ clean-test-int-data: # remove integration test data and images (expected) -- us
pre-commit: # run pre-commit quality assurance checks
pre-commit run --all-files

lint: ## check style with flake8
flake8 e3sm_diags tests
lint: ## check style ruff
ruff check --select I --fix
ruff check --fix

format: ## format code using ruff
ruff format

test: ## run tests quickly with the default Python and produces code coverage report
pytest
Expand Down
50 changes: 24 additions & 26 deletions README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import cdms2
from pathlib import Path

import cdms2
import MV2

datapath='/p/user_pub/e3sm/e3sm_diags_data/obs_for_e3sm_diags/climatology/TRMM-3B43v-7_3hr/'
Expand Down
11 changes: 6 additions & 5 deletions auxiliary_tools/LCF_mixed-phase_partition_diagram.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
"metadata": {},
"outputs": [],
"source": [
"import xarray as xr\n",
"import numpy\n",
"import json\n",
"import math\n",
"\n",
"import matplotlib.pyplot as plt\n",
"from scipy.stats import binned_statistic\n",
"import numpy\n",
"import scipy.io\n",
"import math\n",
"import json"
"import xarray as xr\n",
"from scipy.stats import binned_statistic"
]
},
{
Expand Down
12 changes: 6 additions & 6 deletions auxiliary_tools/aerosol_budget.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# NOTE: This module uses the deprecated e3sm_diags.driver.utils.dataset.Dataset
# class, which was replaced by e3sm_diags.driver.utils.dataset_xr.Dataset.
import e3sm_diags
from e3sm_diags.driver import utils
import csv
import json
import os

import cdms2
import cdutil
import numpy
import os
import json

import csv

import e3sm_diags
from e3sm_diags.driver import utils
from e3sm_diags.parameter.core_parameter import CoreParameter


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
}
],
"source": [
"from collections import defaultdict\n",
"import glob\n",
"from collections import defaultdict\n",
"\n",
"import numpy as np\n",
"import xarray as xr\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
"metadata": {},
"outputs": [],
"source": [
"from collections import defaultdict\n",
"import glob\n",
"from collections import defaultdict\n",
"\n",
"import numpy as np\n",
"import xarray as xr\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
"metadata": {},
"outputs": [],
"source": [
"from collections import defaultdict\n",
"import glob\n",
"from collections import defaultdict\n",
"\n",
"import numpy as np\n",
"import xarray as xr\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
"metadata": {},
"outputs": [],
"source": [
"from collections import defaultdict\n",
"import glob\n",
"from collections import defaultdict\n",
"\n",
"import numpy as np\n",
"import xarray as xr\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
"\n",
"import numpy as np\n",
"import xarray as xr\n",
"from e3sm_diags.derivations.derivations import DERIVED_VARIABLES\n",
"\n",
"from e3sm_diags.derivations.derivations import DERIVED_VARIABLES\n",
"\n",
"# TODO: Update SET_NAME and SET_DIR\n",
"SET_NAME = \"meridional_mean_2d\"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
"\n",
"import numpy as np\n",
"import xarray as xr\n",
"from e3sm_diags.derivations.derivations import DERIVED_VARIABLES\n",
"\n",
"from e3sm_diags.derivations.derivations import DERIVED_VARIABLES\n",
"\n",
"# TODO: Update SET_NAME and SET_DIR\n",
"SET_NAME = \"polar\"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
"metadata": {},
"outputs": [],
"source": [
"from collections import defaultdict\n",
"import glob\n",
"from collections import defaultdict\n",
"\n",
"import numpy as np\n",
"import xarray as xr\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
"from auxiliary_tools.cdat_regression_testing.utils import (\n",
" get_num_metrics_above_diff_thres,\n",
" get_rel_diffs,\n",
" update_diffs_to_pct,\n",
" highlight_large_diffs,\n",
" update_diffs_to_pct,\n",
")\n",
"\n",
"SET_NAME = \"area_mean_time_series\"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@
"metadata": {},
"outputs": [],
"source": [
"from collections import defaultdict\n",
"import glob\n",
"from collections import defaultdict\n",
"from typing import Tuple\n",
"\n",
"import numpy as np\n",
"import xarray as xr\n",
"from e3sm_diags.derivations.derivations import DERIVED_VARIABLES\n",
"\n",
"from e3sm_diags.derivations.derivations import DERIVED_VARIABLES\n",
"\n",
"# TODO: Update SET_NAME and SET_DIR\n",
"SET_NAME = \"area_mean_time_series\"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@
"from auxiliary_tools.cdat_regression_testing.utils import (\n",
" get_num_metrics_above_diff_thres,\n",
" get_rel_diffs,\n",
" update_diffs_to_pct,\n",
" highlight_large_diffs,\n",
" update_diffs_to_pct,\n",
")\n",
"\n",
"SET_NAME = \"area_mean_time_series\"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@
"metadata": {},
"outputs": [],
"source": [
"from collections import defaultdict\n",
"import glob\n",
"from collections import defaultdict\n",
"from typing import Tuple\n",
"\n",
"import numpy as np\n",
"import xarray as xr\n",
"from e3sm_diags.derivations.derivations import DERIVED_VARIABLES\n",
"\n",
"from e3sm_diags.derivations.derivations import DERIVED_VARIABLES\n",
"\n",
"# TODO: Update SET_NAME and SET_DIR\n",
"SET_NAME = \"area_mean_time_series\"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"\n",
"import numpy as np\n",
"import xarray as xr\n",
"\n",
"from e3sm_diags.derivations.derivations import DERIVED_VARIABLES\n",
"\n",
"SET_NAME = \"enso_diags\"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"\n",
"import numpy as np\n",
"import xarray as xr\n",
"\n",
"from e3sm_diags.derivations.derivations import DERIVED_VARIABLES\n",
"\n",
"SET_NAME = \"qbo\"\n",
Expand Down Expand Up @@ -332,8 +333,8 @@
"metadata": {},
"outputs": [],
"source": [
"import xcdat as xc\n",
"import xarray as xr\n",
"import xcdat as xc\n",
"\n",
"ds_xc = xc.open_dataset(\n",
" \"/global/cfs/cdirs/e3sm/www/cdat-migration-fy24/664-qbo/qbo/QBO-ERA-Interim/qbo_diags_qbo_ref.nc\"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
"\n",
"import numpy as np\n",
"import xarray as xr\n",
"from e3sm_diags.derivations.derivations import DERIVED_VARIABLES\n",
"\n",
"from e3sm_diags.derivations.derivations import DERIVED_VARIABLES\n",
"\n",
"# TODO: Update SET_NAME and SET_DIR\n",
"SET_NAME = \"diurnal_cycle\"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@
}
],
"source": [
"from collections import defaultdict\n",
"import glob\n",
"from collections import defaultdict\n",
"\n",
"import numpy as np\n",
"import xarray as xr\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,20 @@
}
],
"source": [
"from collections import defaultdict\n",
"import glob\n",
"from collections import defaultdict\n",
"\n",
"import pandas as pd\n",
"import numpy as np\n",
"import pandas as pd\n",
"import xarray as xr\n",
"\n",
"from auxiliary_tools.cdat_regression_testing.utils import (\n",
" get_metrics,\n",
" get_num_metrics_above_diff_thres,\n",
" get_rel_diffs,\n",
" highlight_large_diffs,\n",
" sort_columns,\n",
" update_diffs_to_pct,\n",
" highlight_large_diffs,\n",
")\n",
"\n",
"# TODO: Update SET_NAME and SET_DIR\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@
"\n",
"import numpy as np\n",
"import xarray as xr\n",
"from e3sm_diags.derivations.derivations import DERIVED_VARIABLES\n",
"\n",
"from e3sm_diags.derivations.derivations import DERIVED_VARIABLES\n",
"\n",
"# TODO: Update SET_NAME and SET_DIR\n",
"SET_NAME = \"lat_lon\"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@
"metadata": {},
"outputs": [],
"source": [
"import glob\n",
"\n",
"import pandas as pd\n",
"\n",
"import glob\n",
"from auxiliary_tools.cdat_regression_testing.utils import get_metrics, get_rel_diffs\n",
"\n",
"\n",
"# TODO: Update DEV_RESULTS and MAIN_RESULTS to your diagnostic sets.\n",
"DEV_PATH = \"/global/cfs/cdirs/e3sm/www/vo13/examples_658/ex1_modTS_vs_modTS_3years/lat_lon/model_vs_model\"\n",
"MAIN_PATH = \"/global/cfs/cdirs/e3sm/www/vo13/examples_main_w_slice/ex1_modTS_vs_modTS_3years/lat_lon/model_vs_model\"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,19 @@
"outputs": [],
"source": [
"import glob\n",
"\n",
"import pandas as pd\n",
"\n",
"from auxiliary_tools.cdat_regression_testing.utils import (\n",
" PERCENTAGE_COLUMNS,\n",
" get_metrics,\n",
" get_rel_diffs,\n",
" get_num_metrics_above_diff_thres,\n",
" get_rel_diffs,\n",
" highlight_large_diffs,\n",
" sort_columns,\n",
" update_diffs_to_pct,\n",
" PERCENTAGE_COLUMNS,\n",
")\n",
"\n",
"import pandas as pd\n",
"\n",
"# TODO: Update DEV_RESULTS and MAIN_RESULTS to your diagnostic sets.\n",
"DEV_PATH = \"/global/cfs/cdirs/e3sm/www/vo13/examples_658/ex1_modTS_vs_modTS_3years/lat_lon/model_vs_model\"\n",
"MAIN_PATH = \"/global/cfs/cdirs/e3sm/www/vo13/examples/ex1_modTS_vs_modTS_3years/lat_lon/model_vs_model\"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,20 @@
}
],
"source": [
"from typing import List\n",
"import glob\n",
"from typing import List\n",
"\n",
"import pandas as pd\n",
"\n",
"from auxiliary_tools.cdat_regression_testing.utils import (\n",
" get_rel_diffs,\n",
" PERCENTAGE_COLUMNS,\n",
" get_num_metrics_above_diff_thres,\n",
" get_rel_diffs,\n",
" highlight_large_diffs,\n",
" sort_columns,\n",
" update_diffs_to_pct,\n",
" PERCENTAGE_COLUMNS,\n",
")\n",
"\n",
"\n",
"SET_NAME = \"lat_lon\"\n",
"SET_DIR = \"759-slice-flag\"\n",
"\n",
Expand Down
Loading

0 comments on commit df39bf4

Please sign in to comment.