Skip to content

Commit

Permalink
Switch CI to use 'ruff' package for linting (#273)
Browse files Browse the repository at this point in the history
* DOC #258

* CI #258

* STY #258 changes to comply with 'ruff check'

* CFG #258 ruff configuration

* MNT #258 restore these two imports, they start the instrument

* MNT #258 per 'ruff check'
  • Loading branch information
prjemian authored Feb 26, 2024
1 parent f0991ab commit 78b6738
Show file tree
Hide file tree
Showing 13 changed files with 118 additions and 36 deletions.
16 changes: 4 additions & 12 deletions .github/workflows/code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,11 @@ jobs:
run: |
set -vxeuo pipefail
python -m pip install --upgrade pip
pip install ruff flake8
- name: Run flake8
run: flake8
# # TODO: will replace flake8
# - name: Run ruff
# uses: davidslusser/actions_python_ruff@v1.0.0
# with:
# # src: "."
# # options: "--cov=src"
# pip_install_command: "pip install -e .[dev]"
# python_version: "3.11"
- name: Run ruff
uses: davidslusser/actions_python_ruff@v1.0.0
with:
python_version: "3.11"

tests:
name: CI py${{ matrix.python-version }}
Expand Down
86 changes: 86 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Exclude a variety of commonly ignored directories.
exclude = [
".bzr",
".direnv",
".eggs",
".git",
".git-rewrite",
".hg",
".ipynb_checkpoints",
".mypy_cache",
".nox",
".pants.d",
".pyenv",
".pytest_cache",
".pytype",
".ruff_cache",
".svn",
".tox",
".venv",
".vscode",
"__pypackages__",
"_build",
"buck-out",
"build",
"dist",
"node_modules",
"site-packages",
"venv",
]

# Same as Black.
line-length = 115
indent-width = 4

# Assume Python 3.8
target-version = "py38"

[lint]
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`) codes by default.
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
# McCabe complexity (`C901`) by default.
select = ["E4", "E7", "E9", "F"]
ignore = ["E402", "F405"]

# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
unfixable = []

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

[lint.per-file-ignores]
"__init__.py" = ["F403"]
"bluesky/console/__start_bluesky_instrument__.py" = ["F403"]
"bluesky/instrument/collection.py" = ["F403"]
"bluesky/instrument/qstarter.py" = ["F401", "F403"]
"bluesky/instrument/queueserver.py" = ["F401", "F403"]
"bluesky/qstarter.py" = ["F401"]
"**/{tests,docs,tools}/*" = ["E402"]

[format]
# Like Black, use double quotes for strings.
quote-style = "double"

# Like Black, indent with spaces, rather than tabs.
indent-style = "space"

# Like Black, respect magic trailing commas.
skip-magic-trailing-comma = false

# Like Black, automatically detect the appropriate line ending.
line-ending = "auto"

# Enable auto-formatting of code examples in docstrings. Markdown,
# reStructuredText code/literal blocks and doctests are all supported.
#
# This is currently disabled by default, but it is planned for this
# to be opt-out in the future.
docstring-code-format = false

# Set the line length limit used when formatting code snippets in
# docstrings.
#
# This only has an effect when the `docstring-code-format` setting is
# enabled.
docstring-code-line-length = "dynamic"
13 changes: 7 additions & 6 deletions .wip/pack_unpack/export_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
see: https://github.com/APS-3ID-IXN/ipython-s3blue/issues/2
"""

from databroker import Broker
import datetime, os, shutil, time
import datetime
import os
import shutil

import pyRestTable
from dask.bag import text
from databroker import Broker


def main():
Expand Down Expand Up @@ -101,6 +103,7 @@ def main():


import re

ACCEPTABLE_PATTERN = r"[A-Za-z_][\w_]*"


Expand All @@ -127,9 +130,7 @@ def tester():
'mca_elapsed_real_time', 'mca_preset_real_time', 'mca_spectrum',
'neat_stage_x', 'neat_stage_x_user_setpoint', 'neat_stage_y',
'neat_stage_y_user_setpoint', 'scaler_time']
safe_keys = make_safe(keys)
keymap = {k:v for k, v in zip(keys, safe_keys)}
for old_key, new_key in zip(keys, safe_keys):
for old_key, new_key in zip(keys, make_safe(keys)):
tbl.addRow((old_key, new_key))
print(tbl)

Expand Down
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ Maintenance
* Add 'Hello, World!' test to installation checklist.
* Drop the (unused now) *stdlogpj* package for configuring Python's *logging*.
* Environment for bluesky_2024_1.
* Lint the code (for style and syntax errors) using the 'ruff' package.
* Updates (learned from 2-ID) for new installations.
* Various documentation updates.


v1.0.1
******

Expand Down
2 changes: 1 addition & 1 deletion bluesky/instrument/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# instrument configuration
from ._iconfig import iconfig
from ._iconfig import iconfig # noqa
2 changes: 1 addition & 1 deletion bluesky/instrument/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
logger.info("xmode exception level: '%s'", _xmode_level)
del _ip

from . import mpl
from . import mpl # noqa

logger.info("#### Bluesky Framework ####")
from .framework import *
Expand Down
14 changes: 7 additions & 7 deletions bluesky/instrument/framework/initialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,21 @@
from bluesky import SupplementalData
from bluesky.callbacks.best_effort import BestEffortCallback
from bluesky.magics import BlueskyMagics
from bluesky.simulators import summarize_plan
from bluesky.simulators import summarize_plan # noqa
from bluesky.utils import PersistentDict
from bluesky.utils import ProgressBarManager
from bluesky.utils import ts_msg_hook
from bluesky.utils import ts_msg_hook # noqa
from IPython import get_ipython
from ophydregistry import Registry
import databroker
import ophyd
import warnings
import warnings # noqa

# convenience imports
import bluesky.plans as bp
import bluesky.plan_stubs as bps
import bluesky.preprocessors as bpp
import numpy as np
import bluesky.plans as bp # noqa
import bluesky.plan_stubs as bps # noqa
import bluesky.preprocessors as bpp # noqa
import numpy as np # noqa


def get_md_path():
Expand Down
1 change: 0 additions & 1 deletion bluesky/instrument/framework/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import getpass
import os
import socket
from datetime import datetime

import apstools
import databroker
Expand Down
1 change: 0 additions & 1 deletion bluesky/instrument/utils/image_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import numpy as np
import pyRestTable
from scipy.ndimage import center_of_mass
from scipy.integrate import trapz


def analyze_peak(y_arr, x_arr=None):
Expand Down
2 changes: 1 addition & 1 deletion bluesky/qstarter.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
)

from instrument import iconfig
from instrument.queueserver import *
from instrument.queueserver import * # noqa


print_instrument_configuration()
Expand Down
3 changes: 2 additions & 1 deletion bluesky/tests/test_ipython_startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@


def test_startup(capsys):
from instrument.collection import iconfig
# start the instrument package for IPython console session
from instrument.collection import iconfig # noqa

out, err = capsys.readouterr()

Expand Down
3 changes: 2 additions & 1 deletion bluesky/tests/test_queueserver_startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@


def test_startup(capsys):
from qstarter import iconfig
# start the instrument package for queueserver session
from qstarter import iconfig # noqa

out, err = capsys.readouterr()

Expand Down
9 changes: 6 additions & 3 deletions bluesky/user/quick_hello.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@

import logging

from ophyd import Component
from ophyd import Device
from ophyd import Signal

from bluesky import plans as bp

logger = logging.getLogger(__name__)
logger.info(__file__)

from ophyd import Component, Device, Signal

from bluesky import plans as bp

print("Loading 'Hello, World!' example.")

Expand Down

0 comments on commit 78b6738

Please sign in to comment.