diff --git a/.github/workflows/flake8.yml b/.github/workflows/flake8.yml deleted file mode 100644 index ea5f54c..0000000 --- a/.github/workflows/flake8.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: Python ruff check - -on: [push, pull_request] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - name: Set up Python 3.8 - uses: actions/setup-python@v4 - with: - python-version: "3.11" - - name: Lint with ruff - run: | - python -m pip install --upgrade pip - pip install ruff - - # Include `--format=github` to enable automatic inline annotations. - - name: Run Ruff - run: ruff --format=github . diff --git a/.github/workflows/black.yml b/.github/workflows/python-linting.yml similarity index 59% rename from .github/workflows/black.yml rename to .github/workflows/python-linting.yml index 6f47e98..078e674 100644 --- a/.github/workflows/black.yml +++ b/.github/workflows/python-linting.yml @@ -1,4 +1,4 @@ -name: Check black formatting +name: Check Python formatting using Black and Ruff on: [push] @@ -8,3 +8,4 @@ jobs: steps: - uses: actions/checkout@v3 - uses: psf/black@stable + - uses: chartboost/ruff-action@v1 \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 23dec33..665e324 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,12 +1,17 @@ +ci: + autoupdate_schedule: monthly + + repos: - repo: https://github.com/psf/black - rev: 23.3.0 + rev: 23.7.0 hooks: - id: black - language_version: python3.11 + language_version: python3.10 -- repo: https://github.com/pycqa/isort - rev: 5.12.0 +- repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.0.282 hooks: - - id: isort - name: isort (python) + - id: ruff + args: ["--fix", "--format=github"] + language_version: python3.10 diff --git a/acis_thermal_check/main.py b/acis_thermal_check/main.py index 2ea2b3e..a2da336 100644 --- a/acis_thermal_check/main.py +++ b/acis_thermal_check/main.py @@ -382,13 +382,13 @@ def make_week_predict(self, tstart, tstop, tlm, T_init, model_spec, outdir): # write_temps writes the temperatures to temperatures.dat self.write_temps(outdir, model.times, temps) - return dict( - states=states, - times=model.times, - temps=temps, - plots=plots, - viols=viols, - ) + return { + "states": states, + "times": model.times, + "temps": temps, + "plots": plots, + "viols": viols, + } def _calc_model_supp(self, model, state_times, states, ephem, state0): pass @@ -1426,14 +1426,14 @@ def _setup_proc_and_logger(self, args): config_logging(args.outdir, args.verbose) # Store info relevant to processing for use in outputs - proc = dict( - run_user=getpass.getuser(), - run_time=time.ctime(), - errors=[], - msid=self.msid.upper(), - name=self.name.upper(), - hist_limit=self.hist_limit, - ) + proc = { + "run_user": getpass.getuser(), + "run_time": time.ctime(), + "errors": [], + "msid": self.msid.upper(), + "name": self.name.upper(), + "hist_limit": self.hist_limit, + } mylog.info( "# %s_check run at %s by %s" diff --git a/pyproject.toml b/pyproject.toml index 1f4a114..4fa940c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,53 +17,119 @@ exclude = ''' )/ ''' -[tool.isort] -profile = "black" - [tool.ruff] line-length = 88 -select = ["ALL"] +target-version = "py310" +# fix = true +select = [ + # isort + "I", + # pyflakes + "F", + # pycodestyle + "E", "W", + # flake8-2020 + "YTT", + # flake8-bugbear + "B", + # flake8-quotes + "Q", + # flake8-debugger + "T10", + # flake8-gettext + "INT", + # pylint + "PLC", "PLE", "PLR", "PLW", + # misc lints + "PIE", + # flake8-pyi + "PYI", + # tidy imports + "TID", + # implicit string concatenation + "ISC", + # type-checking imports + "TCH", + # comprehensions + "C4", + # pygrep-hooks + "PGH" +] + ignore = [ - "ANN", - "S101", - "D1", - "D400", - "D401", - "D404", - "D415", - "D203", - "SIM105", - "SIM108", - "PTH123", - "DTZ", - "D212", - "EM", - "ERA001", - "C", - "B905", - "BLE001", - "T", - "RET", - "D205", - "N802", - "N803", - "N806", - "S324", - "FBT002", - "FBT003", - "ARG002", - "B904", - "PLR2004", - "PLR0915", - "ICN001", - "TRY003", - "PLR0912", - "PLR0913", - "TRY200", + # space before : (needed for how black formats slicing) + # "E203", # not yet implemented + # module level import not at top of file + "E402", + # do not assign a lambda expression, use a def + "E731", + # line break before binary operator + # "W503", # not yet implemented + # line break after binary operator + # "W504", # not yet implemented + # controversial + "B006", + # controversial?: Loop control variable not used within loop body + # "B007", + # controversial + "B008", + # setattr is used to side-step mypy + "B009", + # getattr is used to side-step mypy + "B010", + # tests use assert False + "B011", + # tests use comparisons but not their returned value + "B015", + # false positives + "B019", + # Loop control variable overrides iterable it iterates + "B020", + # Function definition does not bind loop variable + "B023", + # Functions defined inside a loop must not use variables redefined in the loop + # "B301", # not yet implemented + # Only works with python >=3.10 + "B905", + # Too many arguments to function call + "PLR0913", + # Too many returns + "PLR0911", + # Too many branches + "PLR0912", + # Too many statements + "PLR0915", + # Redefined loop name + "PLW2901", + # Global statements are discouraged + "PLW0603", + # Docstrings should not be included in stubs + "PYI021", + # No builtin `eval()` allowed + "PGH001", + # compare-to-empty-string + "PLC1901", + # Use typing_extensions.TypeAlias for type aliases + # "PYI026", # not yet implemented + # Use "collections.abc.*" instead of "typing.*" (PEP 585 syntax) + # "PYI027", # not yet implemented + # while int | float can be shortened to float, the former is more explicit + # "PYI041", # not yet implemented + # Additional checks that don't pass yet + # Useless statement + "B018", + # Within an except clause, raise exceptions with ... + "B904", + # Magic number + "PLR2004", + # Consider `elif` instead of `else` then `if` to remove indentation level + "PLR5501", ] -extend-exclude = [ - "doc", + +exclude = [ + "docs", ] + [tool.ruff.per-file-ignores] "__init__.py" = ["E402", "F401", "F403"] diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..19f070a --- /dev/null +++ b/pytest.ini @@ -0,0 +1,15 @@ +[pytest] +filterwarnings = + # most probably, all these are stupid self-deprecation + ignore:Jupyter is migrating its paths + ignore:Importing clear_output from IPython.core.display is deprecated + ignore:Importing display from IPython.core.display is deprecated + ignore:\n\n `numpy.distutils` is deprecated:DeprecationWarning + + ignore:distutils Version classes are deprecated + + ignore: the imp module is deprecated + +# these are convenient to have around to configure logging from pytest +log_cli = False +log_cli_level = DEBUG \ No newline at end of file