Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
40 changes: 28 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,31 @@
FORCE_COLOR: 3

jobs:
pre-commit:
name: Pre-commit
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- uses: actions/setup-python@v5
with:
python-version: "3.12"

- uses: astral-sh/setup-uv@v7

- name: Run pre-commit hooks
run: uv run --locked --only-group dev pre-commit run --all-files

checks:

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}
name: Check Python ${{ matrix.python-version }} on ${{ matrix.runs-on }}
runs-on: ${{ matrix.runs-on }}
strategy:
fail-fast: false
matrix:
python-version: ["3.10", "3.11", "3.12"]
python-version: ["3.11", "3.12"]
runs-on: [ubuntu-latest]

steps:
Expand All @@ -34,25 +52,23 @@
python-version: ${{ matrix.python-version }}
allow-prereleases: true

- uses: astral-sh/setup-uv@v7

- name: Test regular installation
run: |
python -m pip install --upgrade pip
python -m pip install .
python -c "import hxntools; print(f'✓ hxntools imported successfully (editable): {hxntools.__file__}')"
python -c "from importlib.metadata import version; print(f'✓ Version: {version(\"hxntools\")}')"
python -m pip list | grep hxntools
python -m pip uninstall -y hxntools
uv sync --locked --no-dev --no-editable --python "${{ matrix.python-version }}"
uv run --no-sync python -c "import hxntools; print(f'✓ hxntools imported successfully (regular): {hxntools.__file__}')"
uv run --no-sync python -c "from importlib.metadata import version; print(f'✓ Version: {version(\"hxntools\")}')"

- name: Test editable installation
run: |
python -m pip install -e .
python -c "import hxntools; print(f'✓ hxntools imported successfully (editable): {hxntools.__file__}')"
python -c "from importlib.metadata import version; print(f'✓ Version: {version(\"hxntools\")} (editable)')"
python -m pip list | grep hxntools
uv sync --locked --no-dev --python "${{ matrix.python-version }}"
uv run --no-sync python -c "import hxntools; print(f'✓ hxntools imported successfully (editable): {hxntools.__file__}')"
uv run --no-sync python -c "from importlib.metadata import version; print(f'✓ Version: {version(\"hxntools\")} (editable)')"

- name: Test package modules import
run: |
python -c "
uv run --no-sync python -c "
import hxntools
Comment thread
thopkins32 marked this conversation as resolved.
import pkgutil
modules = [name for _, name, _ in pkgutil.iter_modules(hxntools.__path__, hxntools.__name__ + '.')]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
with:
fetch-depth: 0

- uses: hynek/build-and-inspect-python-package@v2
- uses: hynek/build-and-inspect-python-package@v3.0.1

publish:
needs: [dist]
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ __pycache__/

# Distribution / packaging
.Python
.venv/
env/
bin/
build/
Expand Down Expand Up @@ -94,5 +95,5 @@ __enamlcache__/
# PyBuilder
target/

# setuptools_scm
# Generated version metadata
src/hxntools/_version.py
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.16.8
hooks:
- id: ruff-check
args: [--fix]
- id: ruff-format
11 changes: 0 additions & 11 deletions MANIFEST.in

This file was deleted.

17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
hxntools
========
Python library of tools used at NSLS-II's Hard X-ray Nanoprobe (HXN, 03id) beamline

Development
-----------

Install the repository hooks:

```console
uv run --locked --only-group dev pre-commit install
```

Run every hook without making a commit:

```console
uv run --locked --only-group dev pre-commit run --all-files
```

Ruff formatting runs on every commit. The legacy `src/` tree is temporarily excluded from both Ruff checks and formatting; narrow or remove that exclusion as files are adopted.
32 changes: 21 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[build-system]
requires = ["setuptools>=64", "setuptools_scm[toml]>=7"]
build-backend = "setuptools.build_meta"
requires = ["hatchling", "hatch-vcs"]
build-backend = "hatchling.build"

[project]
name = "hxntools"
dynamic = ["version"]
description = "NSLS-II Hard X-ray Nanoprobe data acquisition tools"
readme = "README.md"
requires-python = ">=3.10"
requires-python = ">=3.11"
license = "BSD-3-Clause"
authors = [
{name = "Brookhaven National Laboratory", email = "DAMA@bnl.gov"}
Expand All @@ -21,7 +21,6 @@ classifiers = [
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Scientific/Engineering",
Expand All @@ -47,12 +46,23 @@ Homepage = "https://github.com/NSLS-II-HXN/hxntools"
Discussions = "https://github.com/NSLS-II-HXN/hxntools/discussions"
Changelog = "https://github.com/NSLS-II-HXN/hxntools/releases"

[tool.setuptools]
include-package-data = true
[dependency-groups]
dev = [
"pre-commit>=4.3",
]

[tool.hatch.version]
source = "vcs"

[tool.hatch.build.targets.wheel]
packages = ["src/hxntools"]

[tool.hatch.build.hooks.vcs]
version-file = "src/hxntools/_version.py"

[tool.setuptools.packages.find]
where = ["src"]
include = ["hxntools*"]
[tool.ruff]
target-version = "py311"
extend-exclude = ["src"]

[tool.setuptools_scm]
write_to = "src/hxntools/_version.py"
[tool.ruff.lint]
select = ["F"]
13 changes: 2 additions & 11 deletions src/hxntools/CompositeBroker.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
from databroker.v0 import Broker
from databroker.headersource.mongo import MDS
from databroker.assets.mongo import Registry
from databroker.headersource.core import doc_or_uid_to_uid
from databroker.headersource.core import BAD_KEYS_FMT, doc_or_uid_to_uid
from databroker.assets.handlers import HandlerBase
from jsonschema import validate as js_validate
from collections import deque

import numpy as np
import pandas as pd
import warnings
import uuid
import certifi
import os
import six
import pymongo
import h5py
Expand Down Expand Up @@ -317,7 +310,6 @@ def insert(self, name, doc):
if f_benchmark:
f_benchmark.write("\n scan_id: {} \n".format(doc['scan_id']))
f_benchmark.flush()
datum_counts = {}

ts = str(datetime.now().timestamp())

Expand All @@ -335,7 +327,7 @@ def insert(self, name, doc):
logger = logging.getLogger(__name__)

FMT_ROI_KEY = 'entry/instrument/detector/NDAttributes/CHAN{}ROI{}'
from databroker.assets.handlers import HandlerBase, ImageStack
from databroker.assets.handlers import ImageStack


class HDF5DatasetSliceHandler(HandlerBase):
Expand Down Expand Up @@ -378,7 +370,6 @@ def __call__(self, point_number):
return self._data_objects[point_number]

def open(self):
import h5py
if self._file:
return

Expand Down
12 changes: 12 additions & 0 deletions src/hxntools/detectors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,15 @@
from .trigger_mixins import (HxnModalBase, )
from .mercury import (HxnMercuryDetector, )
from .dexela import (HxnDexelaDetector, )

__all__ = [
"TimepixDetector",
"HxnTimepixDetector",
"HxnZebra",
"Zebra",
"HxnMerlinDetector",
"BeamStatusDetector",
"HxnModalBase",
"HxnMercuryDetector",
"HxnDexelaDetector",
]
4 changes: 1 addition & 3 deletions src/hxntools/detectors/dexela.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from __future__ import print_function
import itertools
import logging

from ophyd import (AreaDetector, CamBase, TIFFPlugin, Component as Cpt,
Expand All @@ -10,10 +9,9 @@
from ophyd.areadetector.filestore_mixins import (FileStoreTIFF,
FileStorePluginBase)

from .utils import (makedirs, make_filename_add_subdirectory)
from .utils import (makedirs)
from .trigger_mixins import (HxnModalTrigger, FileStoreBulkReadable)

from pathlib import PurePath

logger = logging.getLogger(__name__)

Expand Down
6 changes: 2 additions & 4 deletions src/hxntools/detectors/hxn_xspress3.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from collections import OrderedDict, namedtuple
import uuid
import itertools
import logging
import time
import numpy as np
Expand All @@ -10,8 +8,8 @@
from ophyd.status import DeviceStatus
from ophyd.device import (BlueskyInterface, Staged)

from nslsii.detectors.xspress3 import (XspressTrigger, Xspress3Detector,
Xspress3FileStore, Xspress3ROI)
from nslsii.detectors.xspress3 import (Xspress3Detector,
Xspress3FileStore)
from .trigger_mixins import HxnModalBase

import pandas as pd
Expand Down
1 change: 0 additions & 1 deletion src/hxntools/detectors/merlin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import print_function
import logging
from pathlib import PurePath
from ophyd import (AreaDetector, CamBase, TIFFPlugin, Component as Cpt,
HDF5Plugin, Device, StatsPlugin, ProcessPlugin,
ROIPlugin, TransformPlugin, EpicsSignal)
Expand Down
1 change: 0 additions & 1 deletion src/hxntools/detectors/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import print_function
import os
from ophyd import Signal


def makedirs(path, mode=0o777):
Expand Down
1 change: 0 additions & 1 deletion src/hxntools/detectors/zebra.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,6 @@ class HxnZebra(Zebra):
def mode_internal(self):
super().mode_internal()

scan_type = self.mode_settings.scan_type.get()
# no concept of internal triggering for now
# raise ValueError('Unknown scan type for internal triggering: '
# '{}'.format(scan_type))
Expand Down
2 changes: 2 additions & 0 deletions src/hxntools/handlers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# imports to expose out to world
from .timepix import TimepixHDF5Handler

__all__ = ["TimepixHDF5Handler"]


def register(db):
from .xspress3 import register
Expand Down
2 changes: 0 additions & 2 deletions src/hxntools/handlers/bulkdata.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from .hxn_handler import HXNHandlerBase
from databroker.assets.handlers import HandlerBase
import h5py


class BulkMerlin(HXNHandlerBase):
Expand Down
2 changes: 0 additions & 2 deletions src/hxntools/handlers/rasmi2.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
from .hxn_handler import HXNHandlerBase
from databroker.assets.handlers import HandlerBase
import h5py

class SISHDF5Handler(HXNHandlerBase):
HANDLER_NAME = "SIS_HDF51_FLY_STREAM_V1"
Expand Down
1 change: 0 additions & 1 deletion src/hxntools/scans.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import asyncio
import functools
import logging

Expand Down
Loading
Loading