Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demo instrument separation for Sync template #58

Open
wants to merge 45 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
01d880a
set up is in 2 steps so RE no longer crashes stuff
MDecarabas Mar 6, 2025
1a0c9e9
fixed issue with error logging magics
MDecarabas Mar 6, 2025
fd9eb39
make devices works no error
MDecarabas Mar 6, 2025
107f5c1
organizing factory device
MDecarabas Mar 7, 2025
28d7d71
Merge branch 'main' into switch_case_organization
ravescovi Mar 8, 2025
eff48dd
fix tests
ravescovi Mar 8, 2025
cf85fe6
Merge branch 'switch_case_organization' of https://github.com/BCDA-AP…
ravescovi Mar 8, 2025
4c54b5c
Update README.md
prjemian Mar 8, 2025
edd1f7c
Merge branch 'main' into switch_case_organization
prjemian Mar 9, 2025
9fd1744
added features to iconfig
MDecarabas Mar 10, 2025
dfbf7f2
rebase
MDecarabas Mar 10, 2025
ab38d00
make devices works no error
MDecarabas Mar 6, 2025
e125b66
rebase
MDecarabas Mar 10, 2025
232c542
MNT #37 following repo rename
prjemian Feb 10, 2025
8e584ee
always enabled
ravescovi Mar 8, 2025
4da36b9
Merge branch 'main' into switch_case_organization
MDecarabas Mar 10, 2025
2b8789c
new instrument
ravescovi Mar 10, 2025
954fb1f
readded file
MDecarabas Mar 10, 2025
b25ba14
demo_instrument
ravescovi Mar 10, 2025
edf614b
fix relative imports
ravescovi Mar 10, 2025
07711e8
precommit
ravescovi Mar 10, 2025
9e80a8d
fix tests
ravescovi Mar 10, 2025
5362261
fix actions
ravescovi Mar 10, 2025
aaef8c2
add README
ravescovi Mar 10, 2025
cfac9ef
fix??
ravescovi Mar 10, 2025
26fea41
add create_instrument to init_repo
ravescovi Mar 10, 2025
cfdd34a
add templatesyncignore
ravescovi Mar 10, 2025
54230fb
eof
ravescovi Mar 10, 2025
e9b84d7
Update .github/workflows/init_repo.yml
ravescovi Mar 11, 2025
ac3e7f0
Update docs/source/demo.ipynb
ravescovi Mar 11, 2025
e639a94
finished iconfig cleanup ...for nbow
MDecarabas Mar 11, 2025
dfb0118
pre-commited
MDecarabas Mar 11, 2025
f800268
will not fix but interesting to observe
MDecarabas Mar 11, 2025
9b47a7a
Merge remote-tracking branch 'origin/switch_case_organization' into d…
ravescovi Mar 11, 2025
36177a3
hot fix since startup is being imported at top of test and we are tes…
MDecarabas Mar 11, 2025
29e9d31
sync
ravescovi Mar 11, 2025
8b38e51
Merge remote-tracking branch 'origin/switch_case_organization' into d…
ravescovi Mar 11, 2025
b6546d0
WIP test
MDecarabas Mar 11, 2025
b5900e7
WIP test
MDecarabas Mar 11, 2025
f414b1e
test wip
MDecarabas Mar 11, 2025
b3f7df3
IS_ON = Enable
MDecarabas Mar 11, 2025
3b00fcc
cleaned up readme due to suggestions
MDecarabas Mar 11, 2025
6e57afd
Merge remote-tracking branch 'origin/switch_case_organization' into d…
ravescovi Mar 11, 2025
80c7200
hide init_repo placeholders
ravescovi Mar 11, 2025
8f392ed
add metadata
ravescovi Mar 11, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/code.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ jobs:
shell: bash -l {0}
run: |
set -vxeuo pipefail
ipython -c "from instrument.startup import *; RE(make_devices())"
ipython -c "from bits.demo_instrument.startup import *; RE(make_devices())"

# https://coveralls-python.readthedocs.io/en/latest/usage/configuration.html#github-actions-support
coveralls:
Expand Down
10 changes: 7 additions & 3 deletions .github/workflows/init_repo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,18 @@ echo $full_name

repo=$(echo $full_name | awk -F '/' '{print $2}')

original_repo="BITS"
# Sanitize the repo name to be a valid Python package name
sanitized_repo=$(echo "$repo" | sed 's/[^a-zA-Z0-9_-]/_/g')

original_repo="BITS"

echo $repo
echo $sanitized_repo
echo $original_repo

sed -i "s/$original_repo/$repo/g" README.md
sed -i "s/$original_repo/$sanitized_repo/g" README.md

# Call the create_new_instrument function
python3 -c "from bits.utils import create_new_instrument; create_new_instrument('$sanitized_repo')"

rm -rf .github/workflows/init_repo.sh
rm -rf .github/workflows/init_repo.yml
16 changes: 13 additions & 3 deletions .github/workflows/init_repo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,19 @@ jobs:
fetch-depth: 0
ref: ${{ github.head_ref }}

- name: Run init_repo.sh
run: |
bash .github/workflows/init_repo.sh ${{ github.repository }}
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'

# - name: Install dependencies
# run: |
# python -m pip install --upgrade pip
# pip install -e .

# - name: Run init_repo.sh
# run: |
# bash .github/workflows/init_repo.sh ${{ github.repository }}

- uses: stefanzweifel/git-auto-commit-action@v5
with:
Expand Down
70 changes: 35 additions & 35 deletions .github/workflows/template-sync.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
name: template_sync
# see: https://github.com/AndreasAugustin/actions-template-sync
on:
# cronjob trigger
schedule:
# 12:10 AM GMT on the first day of every month
- cron: "10 0 1 * *"
# manual trigger
workflow_dispatch:
env:
TEMPLATE_REPO: BCDA-APS/BITS
jobs:
repo-sync:
if: ${{ github.repository != 'bcda-aps/bits' }}
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
# To use this repository's private action, you must check out the repository
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.GH_PAT }} # `GH_PAT` is a secret that contains your PAT
- name: actions-template-sync
uses: AndreasAugustin/actions-template-sync@v2
with:
source_repo_path: ${{ env.TEMPLATE_REPO }}
upstream_branch: main
name: template_sync

# see: https://github.com/AndreasAugustin/actions-template-sync

on:
# cronjob trigger
schedule:
# 12:10 AM GMT on the first day of every month
- cron: "10 0 1 * *"
# manual trigger
workflow_dispatch:

env:
TEMPLATE_REPO: BCDA-APS/BITS

jobs:
repo-sync:
if: ${{ github.repository != 'bcda-aps/bits' }}
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write

steps:
# To use this repository's private action, you must check out the repository
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.GH_PAT }} # `GH_PAT` is a secret that contains your PAT

- name: actions-template-sync
uses: AndreasAugustin/actions-template-sync@v2
with:
source_repo_path: ${{ env.TEMPLATE_REPO }}
upstream_branch: main
35 changes: 35 additions & 0 deletions .github/workflows/template_sync.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: template_sync

# see: https://github.com/AndreasAugustin/actions-template-sync

on:
# cronjob trigger
schedule:
# 12:10 AM GMT on the first day of every month
- cron: "10 0 1 * *"
# manual trigger
workflow_dispatch:

env:
TEMPLATE_REPO: BCDA-APS/BITS

jobs:
repo-sync:
if: ${{ github.repository != 'bcda-aps/bits' }}
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write

steps:
# To use this repository's private action, you must check out the repository
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.GH_PAT }} # `GH_PAT` is a secret that contains your PAT

- name: actions-template-sync
uses: AndreasAugustin/actions-template-sync@v2
with:
source_repo_path: ${{ env.TEMPLATE_REPO }}
upstream_branch: main
6 changes: 6 additions & 0 deletions .templatesyncignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.all-contributorsrc
.github/dependabot.yml
README.md
Dockerfile
SECURITY.md
src/new_instrument
19 changes: 7 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,37 +17,32 @@ cd BITS
Set up the development environment.

```bash
export ENV_NAME=bits
export ENV_NAME=BITS_env

conda create -y -n $ENV_NAME python=3.11 pyepics
conda activate $ENV_NAME
pip install -e ."[all]"
```

## IPython console
## IPython console Start

To start the bluesky instrument session in a ipython execute the next command in a terminal:

```bash
ipython
```

Inside the ipython console execute:

```py
from instrument.startup import *
```

## Jupyter notebook

## Jupyter Notebook Start
Start JupyterLab, a Jupyter notebook server, or a notebook, VSCode.

Start the data acquisition:
## Starting the BITS Package

```py
from instrument.startup import *
RE(make_devices()) # create all the ophyd-style control devices
```

## Sim Plan Demo
## Run Sim Plan Demo

To run some simulated plans that ensure the installation worked as expected
please run the next commands inside an ipython session or a jupyter notebook
Expand Down
6 changes: 3 additions & 3 deletions docs/source/api/configs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ section.

Various constants and terms used to configure the instrument package.

.. literalinclude:: ../../../src/instrument/configs/iconfig.yml
.. literalinclude:: ../../../src/bits/demo_instrument/configs/iconfig.yml
:language: yaml
:linenos:

Expand All @@ -27,7 +27,7 @@ Declarations of the ophyd (and ophyd-like) devices and signals used by the
instrument package. Configuration is used by the guarneri package to create the
objects.

.. literalinclude:: ../../../src/instrument/configs/devices.yml
.. literalinclude:: ../../../src/bits/demo_instrument/configs/devices.yml
:language: yaml
:linenos:

Expand All @@ -39,6 +39,6 @@ objects.
Declarations of the ophyd (and ophyd-like) devices and signals
only available when Bluesky is used at the APS.

.. literalinclude:: ../../../src/instrument/configs/devices_aps_only.yml
.. literalinclude:: ../../../src/bits/demo_instrument/configs/devices_aps_only.yml
:language: yaml
:linenos:
6 changes: 3 additions & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

import instrument
import bits

project = "instrument"
project = "BITS"
copyright = "2023-2025, APS BCDA"
author = "APS BCDA"
version = instrument.__version__
version = bits.__version__
release = version.split("+")[0]
if "+" in version:
release += "..."
Expand Down
4 changes: 2 additions & 2 deletions docs/source/demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -65,7 +65,7 @@
}
],
"source": [
"from instrument.startup import * # noqa"
"from bits.demo_instrument.startup import * # noqa"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/source/guides/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ Guides show how to use certain features of this instrument.
:maxdepth: 2
:glob:

*dm*
dm
template_sync
15 changes: 8 additions & 7 deletions docs/source/guides/template_sync.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ Overview
--------

This document describes a method to synchronize the new instrument repo
with the template repo. The method relies on a GitHub workflow
with the template repo. The method relies on a GitHub
`workflow <https://docs.github.com/en/actions/writing-workflows/about-workflows>`__
to generate a new pull request whenever the template is updated. The
workflow can be run on demand or as a periodic task (default is once a
month). The workflow is installed in the new instrument's
Expand All @@ -25,16 +26,16 @@ When the workflow is run, it compares the new instrument's repo with the
template repo. If differences are identified, the workflow creates a new
branch in the new instrument's repo and then creates a new pull request
to merge that branch with ``main``. Additional configuration is
necessary to grant permission for the workflow to create a branch and PR.
necessary to grant permission for the workflow to create a branch and
PR.

Permission is provided through a GitHub Personal Access Token (PAT). [#]_
For this purpose, the PAT settings [#settings]_ should allow ``write`` permission
Permission is provided through a GitHub Personal Access Token
(`PAT <https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens>`__).
For this purpose, the PAT
`settings <https://github.com/settings/tokens>`__ should allow ``write``
(includes ``read``) permission for ``workflow``. It is possible to limit
a PAT to a single GitHub repo (a good idea for this use case).

.. [#] https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens
.. [#settings] https://github.com/settings/tokens

Example instrument repository
+++++++++++++++++++++++++++++

Expand Down
10 changes: 4 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"
copyright = "2014-2025, APS"

[project]
name = "instrument"
name = "bits"
dynamic = ["version"]
description = "Model of a Bluesky Data Acquisition Instrument in console, notebook, & queueserver."
authors = [
Expand Down Expand Up @@ -71,14 +71,12 @@ doc = [
"sphinx",
]

all = ["instrument[dev,doc]"]
all = ["bits[dev,doc]"]

[project.urls]
"Homepage" = "https://BCDA-APS.github.io/BITS/"
"Bug Tracker" = "https://github.com/BCDA-APS/BITS/issues"

# [project.scripts]
# instrument = "instrument.app:main"

[tool.black]
line-length = 115
Expand Down Expand Up @@ -221,10 +219,10 @@ skip-magic-trailing-comma = false
line-ending = "auto"

[tool.setuptools]
package-dir = {"instrument" = "src/instrument"}
package-dir = {"bits" = "src/bits"}

[tool.setuptools.package-data]
"*" = ["*.yml"]

[tool.setuptools_scm]
write_to = "src/instrument/_version.py"
write_to = "src/bits/_version.py"
2 changes: 1 addition & 1 deletion src/instrument/__init__.py → src/bits/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

configure_logging()

__package__ = "instrument"
__package__ = "bits"
try:
from setuptools_scm import get_version

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

import logging

from ..core.run_engine_init import RE
from ..utils.aps_functions import host_on_aps_subnet
from ..utils.config_loaders import iconfig
from bits.core.run_engine_init import RE
from bits.utils.aps_functions import host_on_aps_subnet
from bits.utils.config_loaders import iconfig

logger = logging.getLogger(__name__)
logger.bsdev(__file__)
Expand Down Expand Up @@ -48,9 +48,13 @@ def get_sample_title(self):
nxwriter = MyNXWriter() # create the callback instance
"""The NeXus file writer object."""

if "NEXUS_DATA_FILES" in iconfig:
if iconfig.get("NEXUS_DATA_FILES", {}).get("ENABLE", False):
RE.subscribe(nxwriter.receiver) # write data to NeXus files

nxwriter.file_extension = iconfig.get("FILE_EXTENSION", "hdf")
warn_missing = iconfig.get("WARN_MISSING", False)
nxwriter.file_extension = iconfig.get("NEXUS_DATA_FILES", {}).get(
"FILE_EXTENSION", "hdf"
)
print("\n\n\n")
print(nxwriter.file_extension)
warn_missing = iconfig.get("NEXUS_DATA_FILES", {}).get("WARN_MISSING", False)
nxwriter.warn_on_missing_content = warn_missing
Loading