Skip to content

Commit

Permalink
Merge branch 'main' into 247-howto-busy-taxi-fly
Browse files Browse the repository at this point in the history
  • Loading branch information
prjemian committed Mar 4, 2024
2 parents f58f575 + c9d31ce commit 77d66dc
Show file tree
Hide file tree
Showing 46 changed files with 276 additions and 194 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
17 changes: 13 additions & 4 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,37 @@ describe future plans.
1.0.3
******
release expected by 2024-04-01
release expected by 2024-04-02

1.0.2
******

release expected by 2024-03-01
released 2024-02-26

New Features
------------

* Add options to instrument configuration (iconfig.yml):

* After every run, verify that files were saved, print a confirmation message.
* Debugging and message options.

* Add package(s) to environment:

* ophyd-registry

* Build ``registry`` of all ophyd objects.
* Build ``oregistry`` of all ophyd objects.
* Post a warning if at APS but not on controls subnet.

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
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ beamlines to use the [Bluesky](https://blueskyproject.io) framework.

- [HowTo guides, tutorials, & references](https://bcda-aps.github.io/bluesky_training/)
demonstrating use of the Bluesky framework at a typical beamline.
- a [template](./bluesky/) for beamlines to configure their instrument
- a [list of APS instrument](https://github.com/BCDA-APS/bluesky_training/wiki/)
- A [template](./bluesky/) for beamlines to configure their instrument.
- A [checklist](https://bcda-aps.github.io/bluesky_training/instrument/_install_new_instrument.html#installation-checklist) to install a new instrument.
- A [list of APS instrument](https://github.com/BCDA-APS/bluesky_training/wiki/)
repositories

Unit Tests | License | GH tag
--- | --- | ---
[![Unit Tests](https://github.com/BCDA-APS/bluesky_training/workflows/Unit%20Tests/badge.svg)](https://github.com/BCDA-APS/bluesky_training/actions/workflows/unit_tests.yml) | [![license: ANL](https://img.shields.io/badge/license-ANL-brightgreen)](/LICENSE.txt) | [![tag](https://img.shields.io/github/tag/BCDA-APS/bluesky_training.svg)](https://github.com/BCDA-APS/bluesky_training/tags)
Unit Tests | License | GH tag | Code Coverage
--- | --- | --- | ---
[![Unit Tests](https://github.com/BCDA-APS/bluesky_training/workflows/Unit%20Tests/badge.svg)](https://github.com/BCDA-APS/bluesky_training/actions/workflows/unit_tests.yml) | [![license: ANL](https://img.shields.io/badge/license-ANL-brightgreen)](/LICENSE.txt) | [![tag](https://img.shields.io/github/tag/BCDA-APS/bluesky_training.svg)](https://github.com/BCDA-APS/bluesky_training/tags) | [![Coverage Status](https://coveralls.io/repos/github/BCDA-APS/bluesky_training/badge.svg?branch=main)](https://coveralls.io/github/BCDA-APS/bluesky_training?branch=main)

<!-- take note of
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
19 changes: 13 additions & 6 deletions bluesky/instrument/epics_signal_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@

import logging

from ophyd.signal import EpicsSignalBase

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

from . import iconfig
from ophyd.signal import EpicsSignal
from ophyd.signal import EpicsSignalBase
from . import iconfig # noqa


# set default timeout for all EpicsSignal connections & communications
# always first, before ANY ophyd EPICS-based signals are created
# Set default timeout for all EpicsSignal connections & communications.
# Always call first, before ANY ophyd EPICS-based signals are created.
TIMEOUT = 60
if not EpicsSignalBase._EpicsSignalBase__any_instantiated:
EpicsSignalBase.set_defaults(
Expand All @@ -33,25 +33,32 @@
logger.info("Using RunEngine metadata for scan_id")
scan_id_epics = None
else:
from ophyd.signal import EpicsSignal

logger.info("Using EPICS PV %s for scan_id", pvname)
# Must not call _before_ default timeouts are set.
scan_id_epics = EpicsSignal(pvname, name="scan_id_epics")


def epics_scan_id_source(*args, **kwargs):
"""
Callback function for RunEngine. Returns *next* scan_id to be used.
* Ignore args and kwargs.
* Get current scan_id from PV.
* Apply lower limit of zero.
* Increment.
* Set PV with new value.
* Return new value.
Exception will be raised if PV is not connected when next
``bluesky.plan_stubs.open_run()`` is called.
"""
if scan_id_epics is None:
raise RuntimeError(
"epics_scan_id_source() called when"
" 'RUN_ENGINE_SCAN_ID_PV' is"
"undefined in 'iconfig.yml' file."
" undefined in 'iconfig.yml' file."
)
new_scan_id = max(scan_id_epics.get(), 0) + 1
scan_id_epics.put(new_scan_id)
Expand Down
Loading

0 comments on commit 77d66dc

Please sign in to comment.