diff --git a/.github/workflows/code.yml b/.github/workflows/code.yml index ebca263d7..da6610d2e 100644 --- a/.github/workflows/code.yml +++ b/.github/workflows/code.yml @@ -26,20 +26,15 @@ jobs: with: python-version: "3.11" - - name: Install Dependencies + - name: Install package run: | set -vxeuo pipefail python -m pip install --upgrade pip - pip install flake8 - - - name: Run flake8 - run: | - flake8 - - - name: Run black - uses: rickstaa/action-black@v1 + + - name: Run ruff + uses: davidslusser/actions_python_ruff@v1.0.0 with: - black_args: ". --check" + python_version: "3.11" install-catalogs: name: Install & cache databroker catalogs @@ -91,7 +86,7 @@ jobs: mv /tmp/*_test ~/databroker_catalogs/ - name: Archive catalog artifacts - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: databroker_catalogs path: ~/databroker_catalogs @@ -181,7 +176,7 @@ jobs: python -c "${CMD}" - name: Download catalog artifacts - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: databroker_catalogs path: ~/databroker_catalogs diff --git a/.ruff.toml b/.ruff.toml new file mode 100644 index 000000000..b03f2a21a --- /dev/null +++ b/.ruff.toml @@ -0,0 +1,81 @@ +# 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", "E741", "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" = ["F401", "F403"] +"**/{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" diff --git a/CHANGES.rst b/CHANGES.rst index a4705d059..2bba42d1f 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -28,7 +28,7 @@ describe future plans. 1.6.19 ****** -release expected by 2024-03-31 +release expected by 2024-04-02 Fixes ----- @@ -36,6 +36,11 @@ Fixes * lineup2() should work with low intensity peaks. * lineup2() would raise ZeroDivideError in some cases. +Maintenance +----------- + +* Code format conforms to 'ruff'. + 1.6.18 ****** diff --git a/apstools/devices/tests/test_SingleTrigger_V34.py b/apstools/devices/tests/test_SingleTrigger_V34.py index dff7b2c0d..698da2950 100644 --- a/apstools/devices/tests/test_SingleTrigger_V34.py +++ b/apstools/devices/tests/test_SingleTrigger_V34.py @@ -3,7 +3,6 @@ import bluesky import bluesky.plans as bp import databroker -from ophyd import EpicsSignalWithRBV from ophyd import SingleTrigger from ophyd.areadetector import ADComponent from ophyd.areadetector import DetectorBase diff --git a/apstools/devices/tests/test_aps_data_management.py b/apstools/devices/tests/test_aps_data_management.py index 6bdb7dbc9..4d1859187 100644 --- a/apstools/devices/tests/test_aps_data_management.py +++ b/apstools/devices/tests/test_aps_data_management.py @@ -21,7 +21,8 @@ def test_object(wf_name): assert wf.owner.get() == DM_STATION_NAME try: - import dm + # Force a test that dm package can be imported. + import dm # noqa assert wf.api is not None diff --git a/apstools/devices/tests/test_mc_tc32.py b/apstools/devices/tests/test_mc_tc32.py index 0e4434b00..4a441c7a7 100644 --- a/apstools/devices/tests/test_mc_tc32.py +++ b/apstools/devices/tests/test_mc_tc32.py @@ -1,5 +1,3 @@ -import pytest - from ..measComp_tc32_support import BI_CHANNEL_LIST from ..measComp_tc32_support import BO_CHANNEL_LIST from ..measComp_tc32_support import TC_CHANNEL_LIST diff --git a/apstools/plans/tests/test_issue606.py b/apstools/plans/tests/test_issue606.py index d134c68a8..38405dde3 100644 --- a/apstools/plans/tests/test_issue606.py +++ b/apstools/plans/tests/test_issue606.py @@ -12,7 +12,6 @@ import dataclasses -import bluesky.plan_stubs as bps import bluesky.preprocessors as bpp import databroker from bluesky import RunEngine diff --git a/apstools/plans/tests/test_run_blocking_function_plan.py b/apstools/plans/tests/test_run_blocking_function_plan.py index abe96743a..402b0b44a 100644 --- a/apstools/plans/tests/test_run_blocking_function_plan.py +++ b/apstools/plans/tests/test_run_blocking_function_plan.py @@ -10,7 +10,6 @@ from ophyd import EpicsSignal from ...tests import IOC_GP -from ...utils import run_in_thread from .. import run_blocking_function PV = f"{IOC_GP}gp:float1" diff --git a/apstools/plans/tests/test_sscan_support.py b/apstools/plans/tests/test_sscan_support.py index 993353800..0157a155b 100644 --- a/apstools/plans/tests/test_sscan_support.py +++ b/apstools/plans/tests/test_sscan_support.py @@ -5,9 +5,8 @@ from ophyd import EpicsMotor from ophyd.scaler import ScalerCH -from apstools.plans import sscan_1D -from apstools.synApps import SscanDevice -from apstools.tests import IOC_GP +from ...synApps import SscanDevice +from ...tests import IOC_GP from ..sscan_support import _get_sscan_data_objects from ..sscan_support import sscan_1D diff --git a/apstools/utils/apsu_controls_subnet.py b/apstools/utils/apsu_controls_subnet.py index 80159f17b..1a9d19426 100644 --- a/apstools/utils/apsu_controls_subnet.py +++ b/apstools/utils/apsu_controls_subnet.py @@ -34,32 +34,3 @@ def warn_if_not_aps_controls_subnet(): " consider switching to a workstation on the controls subnet" f" which has an IP starting with {APSU_CONTROLS_SUBNET!r}" ) - - -def warn_if_not_aps_controls_subnet(): - """ - APS-U controls are on private subnets. Check and advise as applicable. - - Call this function early in the startup procedure. It could explain easily - the reason for subsequent EPICS PV connection failures. - - For workstations on subnets that do not match the criteria, this function - should not post any warnings. - """ - - import socket - import warnings - - xray_subnet = ".xray.aps.anl.gov" - controls_subnet = "10.54." - - host_name = socket.gethostname() - if host_name.endswith(xray_subnet): - host_ip_addr = socket.gethostbyname(host_name) - if not host_ip_addr.startswith(controls_subnet): - warnings.warn( - f"Your APS workstation ({host_name}) has IP {host_ip_addr!r}." - " If you experience EPICS connection timeouts," - " consider switching to a workstation on the controls subnet" - f" which has an IP starting with {controls_subnet!r}" - ) diff --git a/apstools/utils/tests/test_listdevice.py b/apstools/utils/tests/test_listdevice.py index cd53b52a8..cf9bf7825 100644 --- a/apstools/utils/tests/test_listdevice.py +++ b/apstools/utils/tests/test_listdevice.py @@ -13,7 +13,6 @@ from ...devices import SwaitRecord from ...tests import IOC_GP from .._core import TableStyle -from ..device_info import DEFAULT_COLUMN_WIDTH from ..device_info import NOT_CONNECTED_VALUE from ..device_info import _list_epics_signals from ..device_info import listdevice diff --git a/apstools/utils/tests/test_listplans.py b/apstools/utils/tests/test_listplans.py index fbc7b0f60..f1260c53e 100644 --- a/apstools/utils/tests/test_listplans.py +++ b/apstools/utils/tests/test_listplans.py @@ -2,7 +2,6 @@ test issue listplans() command """ -import pandas as pd import pyRestTable import pytest from bluesky import Msg @@ -17,7 +16,6 @@ def ns(): try: from IPython import get_ipython - # ns_dict = get_ipython().user_global_ns ns_dict = getattr(get_ipython(), "user_global_ns") except (ModuleNotFoundError, AttributeError): ns_dict = globals()