Skip to content

Commit

Permalink
Merge pull request #261 from bluesky/159-py310-and-py311
Browse files Browse the repository at this point in the history
expand to py310 & py311
  • Loading branch information
prjemian authored Oct 6, 2023
2 parents bb54aeb + 47eaeb7 commit a7ddc35
Show file tree
Hide file tree
Showing 14 changed files with 144 additions and 107 deletions.
3 changes: 2 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ exclude =
dist,
versioneer.py,
docs/source,
hkl/_version.py
hkl/_version.py,
dev_*
max-line-length = 115
ignore: E226,E402,E741,W503,W504
11 changes: 0 additions & 11 deletions .github/workflows/black.yml

This file was deleted.

60 changes: 56 additions & 4 deletions .github/workflows/conda_unit_test.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,76 @@
name: Unit Tests

on: [push, pull_request]
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch: # allow manual triggering

defaults:
run:
shell: bash -l {0}

jobs:

lint:
name: Code style
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v4
with:
python-version: '3.11'

- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install flake8
- name: Run flake8
run: |
flake8
- name: Run black
uses: rickstaa/action-black@v1
with:
black_args: ". --check"

build:

runs-on: ubuntu-latest
needs: lint
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
max-parallel: 5

steps:
- uses: actions/checkout@v2

- name: Create Python ${{ matrix.python-version }} environment
uses: mamba-org/provision-with-micromamba@main
uses: mamba-org/setup-micromamba@v1
with:
cache-environment: true
cache-environment-key: env-key-${{ matrix.python-version }}
condarc: |
channel-priority: flexible
environment-file: environment.yml
environment-name: hklpy-test-${{ matrix.python-version }}
environment-name: hklpy-test-py-${{ matrix.python-version }}
create-args: >-
coveralls
pytest
pytest-cov
python=${{ matrix.python-version }}
- name: conda environments
shell: bash -l {0}
Expand Down
21 changes: 0 additions & 21 deletions .github/workflows/flake8.yml

This file was deleted.

3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,6 @@ docs/source/generated

# Bluesky session logger
.logs/

# local developer files
dev_*
12 changes: 8 additions & 4 deletions RELEASE_NOTES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ Release History
Deprecations
Contributors
v1.1 (expected by 2022-07-24)
v1.1 (expected 2024)
======================================

User-requested changes

Maintenance
-----------
v1.0.4 (expected by 2023-10-06)
======================================

Maintenance release.

Fixes
-----
Expand All @@ -28,8 +30,10 @@ Maintenance
-----------

* ``util.list_orientation_runs()`` added progress bar.
* Support Py3.8, 3.9, 3.10, & 3.11
* Support libhkl v5.0.0.3001 (& v5.0.0.3357 when ready)

v1.0.3 (expected by 2022-06-24)
v1.0.3 (released 2022-06-22)
======================================

Maintenance release.
Expand Down
2 changes: 1 addition & 1 deletion env-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ channels:
- defaults

dependencies:
- python >=3.7,<3.10
- python >=3.8,<3.12
- black
- bluesky
- databroker =1.2
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ channels:
- defaults

dependencies:
- python >=3.7,<3.10
- python >=3.8,<3.12
- bluesky
- databroker =1.2
- hkl
Expand Down
10 changes: 4 additions & 6 deletions hkl/calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@
"""

import logging
import functools
import logging
from collections import OrderedDict
from threading import RLock

import numpy as np

from .engine import Engine, CalcParameter
from .sample import HklSample
from . import util
from .util import libhkl
from .context import UsingEngine
from .engine import CalcParameter, Engine
from .sample import HklSample
from .util import libhkl

__all__ = """
A_KEV
Expand Down Expand Up @@ -185,7 +185,6 @@ def __init__(
lock_engine=False,
inverted_axes=None,
):

self._engine = None # set below with property
self._detector = util.new_detector()
self._degrees = bool(degrees)
Expand Down Expand Up @@ -683,7 +682,6 @@ def __call__(
**kwargs,
# fmt: on
):

with UsingEngine(self, engine):
for pos in self.get_path(start, end=end, n=n, path_type=path_type, **kwargs):
yield self.forward(pos, engine=None, **kwargs)
Expand Down
107 changes: 54 additions & 53 deletions hkl/tests/test_fourc.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
from bluesky import plans as bp
from bluesky.simulators import check_limits
from hkl import SimulatedE4CV
from ophyd.positioner import LimitError
import numpy as np
import numpy.testing
import pytest
from bluesky import plans as bp
from bluesky.run_engine import RunEngine
from ophyd.positioner import LimitError

from .. import SimulatedE4CV
from ..calc import UnreachableError


class Fourc(SimulatedE4CV):
...


def check_hkl(diffractometer, h, k, l):
try:
diffractometer.check_value({"h": h, "k": k, "l": l})
except UnreachableError as exc:
assert False, f"({h}, {k}, {l}) : {exc}"


@pytest.fixture(scope="function")
def fourc():
fourc = Fourc("", name="fourc")
Expand Down Expand Up @@ -69,69 +78,61 @@ def test_move(fourc):
numpy.testing.assert_almost_equal(tuple(fourc.real_position), rpos)


def test_hl_scan(fourc):
fourc.move((1.2, 1.2, 0.001))
assert check_limits(bp.scan([fourc], fourc.h, 0.9, 1.1, fourc.l, 0, 0, 11)) is None


def test_h00_scan(fourc):
fourc.move(1, 0, 0)
assert check_limits(bp.scan([fourc], fourc.h, 0.9, 1.1, fourc.l, 0, 0, 11)) is None


def test_hkl_scan(fourc):
fourc.move(1, 1, 1)
assert (
check_limits(
# fmt: off
bp.scan(
[fourc],
fourc.h, 0.9, 1.1,
fourc.k, 0.9, 1.1,
fourc.l, 0.9, 1.1,
33,
)
# fmt: on
)
is None
)
@pytest.mark.parametrize("start", [[1.2, 1.2, 0.001], [1, 0, 0], [1, 1, 1]])
@pytest.mark.parametrize("h", np.arange(0.9, 1.1, 0.1))
@pytest.mark.parametrize("k", np.arange(0.0, 1.2, 0.6))
@pytest.mark.parametrize("l", np.arange(0, 1, 0.5))
def test_hkl_scan(start, h, k, l, fourc):
assert len(start) == 3
fourc.move(start)
check_hkl(fourc, h, k, l)


def test_hkl_range_error(fourc):
with pytest.raises(ValueError) as exinfo:
assert (
check_limits(
# fmt: off
bp.scan(
[fourc],
fourc.h, 0.9, 1.1,
fourc.k, 0.9, 1.1,
fourc.l, 0.09, 123.1,
33,
)
# fmt: on
)
is None
)
with pytest.raises(UnreachableError) as exinfo:
fourc.check_value({"h": 0.9, "k": 0.9, "l": 123})
assert "Unable to solve." in str(exinfo.value)


def test_real_axis(fourc):
assert check_limits(bp.scan([fourc], fourc.tth, 10, 20, 3)) is None
@pytest.mark.parametrize("start", [[1, 1, 1]])
@pytest.mark.parametrize("tth", np.arange(10, 20, 4))
def test_real_axis(start, tth, fourc):
assert len(start) == 3
fourc.move(start)
try:
fourc.check_value({"tth": tth})
except UnreachableError as exc:
assert False, f"{exc}"


@pytest.mark.parametrize("start", [[1, 1, 1]])
@pytest.mark.parametrize(
"target",
[
{"tth": 10},
{"tth": 20},
{"tth": 20, "chi": 7},
],
)
def test_moves(start, target, fourc):
assert len(start) == 3
assert isinstance(target, dict)
fourc.move(start)
try:
fourc.inverse(target)
except UnreachableError as exc:
assert False, f"{target=} : {exc}"


def test_axis_contention(fourc):
RE = RunEngine()
# contention if move pseudo and real positioners together
with pytest.raises(ValueError) as exinfo:
check_limits(bp.scan([fourc], fourc.tth, 10, 20, fourc.k, 0, 0, 3))
RE(bp.scan([fourc], fourc.tth, 10, 20, fourc.k, 0, 0, 3))
assert "mix of real and pseudo" in str(exinfo.value)


def test_real_axis_range_multi(fourc):
assert check_limits(bp.scan([fourc], fourc.tth, 10, 20, fourc.chi, 5, 7, 3)) is None


def test_real_axis_range_error(fourc):
with pytest.raises(LimitError) as exinfo:
check_limits(bp.scan([fourc], fourc.tth, 10, 20000, 3))
fourc.check_value({"tth": 10_000})
assert "not within limits" in str(exinfo.value)
8 changes: 4 additions & 4 deletions hkl/tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ def test__package_info_states():
("hkl", "5.0.0"),
("hklpy", "0"), # minimum test for unversioned use
(NO_SUCH_PACKAGE_NAME, "---"),
("ophyd", "1.6"),
# ("ophyd", "1.6"), conda has right version but pip has 0.0.0
],
)
def test_get_package_info(package_name, minimum_version):
v = hkl.util.get_package_info(package_name)
if v is None:
assert package_name == NO_SUCH_PACKAGE_NAME
assert package_name in ("hklpy", NO_SUCH_PACKAGE_NAME)
else:
assert "version" in v
v_string = v.get("version", "unknown")
Expand Down Expand Up @@ -63,7 +63,7 @@ def test_software_versions_default_list(case):
("hkl", "5.0.0"),
("hklpy", "0"), # minimum test for unversioned use
(NO_SUCH_PACKAGE_NAME, "---"),
("ophyd", "1.6"),
# ("ophyd", "1.6"), conda has right version but pip has 0.0.0
],
)
def test_software_versions_items(package_name, minimum_version):
Expand All @@ -73,4 +73,4 @@ def test_software_versions_items(package_name, minimum_version):
v_package = version.parse(v_string)
assert v_package >= version.parse(minimum_version)
else:
assert package_name == NO_SUCH_PACKAGE_NAME
assert package_name in ("hklpy", NO_SUCH_PACKAGE_NAME)
2 changes: 1 addition & 1 deletion hkl/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@


# when getting software package versions
DEFAULT_PACKAGE_LIST = "hkl hklpy pygobject".split()
DEFAULT_PACKAGE_LIST = "hkl pygobject".split()

# 2018 CODATA recommended lattice parameter of silicon, Angstrom.
# see: https://physics.nist.gov/cgi-bin/cuu/Value?asil
Expand Down
Loading

0 comments on commit a7ddc35

Please sign in to comment.