Skip to content

Commit

Permalink
Merge pull request #930 from BCDA-APS/909-ruff-linting
Browse files Browse the repository at this point in the history
Switch linting to use ruff
  • Loading branch information
prjemian authored Feb 28, 2024
2 parents 767640c + 596857c commit 6841c83
Show file tree
Hide file tree
Showing 12 changed files with 98 additions and 54 deletions.
19 changes: 7 additions & 12 deletions .github/workflows/code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
with:
black_args: ". --check"
python_version: "3.11"

install-catalogs:
name: Install & cache databroker catalogs
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
81 changes: 81 additions & 0 deletions .ruff.toml
Original file line number Diff line number Diff line change
@@ -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"
7 changes: 6 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,19 @@ describe future plans.
1.6.19
******

release expected by 2024-03-31
release expected by 2024-04-02

Fixes
-----

* lineup2() should work with low intensity peaks.
* lineup2() would raise ZeroDivideError in some cases.

Maintenance
-----------

* Code format conforms to 'ruff'.

1.6.18
******

Expand Down
1 change: 0 additions & 1 deletion apstools/devices/tests/test_SingleTrigger_V34.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion apstools/devices/tests/test_aps_data_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 0 additions & 2 deletions apstools/devices/tests/test_mc_tc32.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion apstools/plans/tests/test_issue606.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import dataclasses

import bluesky.plan_stubs as bps
import bluesky.preprocessors as bpp
import databroker
from bluesky import RunEngine
Expand Down
1 change: 0 additions & 1 deletion apstools/plans/tests/test_run_blocking_function_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 2 additions & 3 deletions apstools/plans/tests/test_sscan_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 0 additions & 29 deletions apstools/utils/apsu_controls_subnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
)
1 change: 0 additions & 1 deletion apstools/utils/tests/test_listdevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions apstools/utils/tests/test_listplans.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
test issue listplans() command
"""

import pandas as pd
import pyRestTable
import pytest
from bluesky import Msg
Expand All @@ -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()
Expand Down

0 comments on commit 6841c83

Please sign in to comment.