From 07885985a0c439a7fea718f85ab9e5810d5bec6e Mon Sep 17 00:00:00 2001 From: Pete R Jemian Date: Tue, 3 Oct 2023 19:24:50 -0500 Subject: [PATCH 01/14] PKG #159 --- env-dev.yml | 2 +- environment.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/env-dev.yml b/env-dev.yml index e44145fc..c462f449 100644 --- a/env-dev.yml +++ b/env-dev.yml @@ -12,7 +12,7 @@ channels: - defaults dependencies: - - python >=3.7,<3.10 + - python >=3.8,<3.12 - black - bluesky - databroker =1.2 diff --git a/environment.yml b/environment.yml index 40fdc8c8..1959e922 100644 --- a/environment.yml +++ b/environment.yml @@ -12,7 +12,7 @@ channels: - defaults dependencies: - - python >=3.7,<3.10 + - python >=3.8,<3.12 - bluesky - databroker =1.2 - hkl From ba7c85ad40ebe7a4efd4dd897544fbb7f8f295f8 Mon Sep 17 00:00:00 2001 From: Pete R Jemian Date: Tue, 3 Oct 2023 19:31:46 -0500 Subject: [PATCH 02/14] GIT #189 --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index b9f3a7d5..df9e301f 100644 --- a/.gitignore +++ b/.gitignore @@ -81,3 +81,6 @@ docs/source/generated # Bluesky session logger .logs/ + +# local developer files +dev_* From cbbfb21a47d4185d616b3bf4b8afc794613d58bf Mon Sep 17 00:00:00 2001 From: Pete R Jemian Date: Wed, 4 Oct 2023 00:07:36 -0500 Subject: [PATCH 03/14] STY #159 black & isort for workflow --- hkl/calc.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/hkl/calc.py b/hkl/calc.py index d491c2cc..2f43e965 100644 --- a/hkl/calc.py +++ b/hkl/calc.py @@ -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 @@ -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) @@ -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) From 3d6039a068a032706c8d8772828007ac85dfdb2c Mon Sep 17 00:00:00 2001 From: Pete R Jemian Date: Wed, 4 Oct 2023 00:08:06 -0500 Subject: [PATCH 04/14] STY #159 config --- .flake8 | 3 ++- pyproject.toml | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.flake8 b/.flake8 index 46411781..3818ab18 100644 --- a/.flake8 +++ b/.flake8 @@ -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 diff --git a/pyproject.toml b/pyproject.toml index 12c815cd..110a7287 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,7 @@ [tool.black] line-length = 115 # matches the value of 'max-line-length' in .flake8 target-version = ['py38'] +include = '\.pyi?$' exclude = ''' ( @@ -20,3 +21,10 @@ exclude = ''' # the root of the project ) ''' + +[tool.isort] +profile = "black" +force_single_line = "True" +multi_line_output = "NOQA" +src_paths = ["hkl"] + From 4dfa313d6cb096b516fd680303883dc15c354e89 Mon Sep 17 00:00:00 2001 From: Pete R Jemian Date: Wed, 4 Oct 2023 01:07:15 -0500 Subject: [PATCH 05/14] TST #159 ignore test deprecation warning --- pytest.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/pytest.ini b/pytest.ini index 44c3994a..0fe4a061 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,3 +1,4 @@ [pytest] filterwarnings = ignore:.*imp module is deprecated in favour of importlib:DeprecationWarning + ignore:.*pkg_resources is deprecated as an API.*:DeprecationWarning From 053a9c5fbbc6e0ea20337c5e27713407564567c3 Mon Sep 17 00:00:00 2001 From: Pete R Jemian Date: Wed, 4 Oct 2023 01:52:48 -0500 Subject: [PATCH 06/14] TST #159 another deprecation warning --- pytest.ini | 1 + 1 file changed, 1 insertion(+) diff --git a/pytest.ini b/pytest.ini index 0fe4a061..bafc9665 100644 --- a/pytest.ini +++ b/pytest.ini @@ -2,3 +2,4 @@ filterwarnings = ignore:.*imp module is deprecated in favour of importlib:DeprecationWarning ignore:.*pkg_resources is deprecated as an API.*:DeprecationWarning + ignore:.*Broker.insert may be removed.*:PendingDeprecationWarning From b6bff32d0eda772a71fcdf6eef77e428ac151d2f Mon Sep 17 00:00:00 2001 From: Pete R Jemian Date: Wed, 4 Oct 2023 01:53:24 -0500 Subject: [PATCH 07/14] MNT #159 remove, no such package --- hkl/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hkl/util.py b/hkl/util.py index 310cb89b..91611012 100644 --- a/hkl/util.py +++ b/hkl/util.py @@ -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 From a33e2d7af379b797992c20299c8728cbd4bd2be5 Mon Sep 17 00:00:00 2001 From: Pete R Jemian Date: Wed, 4 Oct 2023 01:53:48 -0500 Subject: [PATCH 08/14] TST #159 refactor --- hkl/tests/test_fourc.py | 107 ++++++++++++++++++++-------------------- hkl/tests/test_util.py | 8 +-- 2 files changed, 58 insertions(+), 57 deletions(-) diff --git a/hkl/tests/test_fourc.py b/hkl/tests/test_fourc.py index 272fa829..1351c158 100644 --- a/hkl/tests/test_fourc.py +++ b/hkl/tests/test_fourc.py @@ -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") @@ -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) diff --git a/hkl/tests/test_util.py b/hkl/tests/test_util.py index 2494a7d7..ede3554c 100644 --- a/hkl/tests/test_util.py +++ b/hkl/tests/test_util.py @@ -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") @@ -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): @@ -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) From 1da9641c2bbbb5840c8a9a99821bb7295ccc7047 Mon Sep 17 00:00:00 2001 From: Pete R Jemian Date: Wed, 4 Oct 2023 01:57:50 -0500 Subject: [PATCH 09/14] CI #159 test on py38 - py311 --- .github/workflows/conda_unit_test.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/conda_unit_test.yml b/.github/workflows/conda_unit_test.yml index 91a13cbc..90f92d03 100644 --- a/.github/workflows/conda_unit_test.yml +++ b/.github/workflows/conda_unit_test.yml @@ -9,7 +9,11 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.7, 3.8, 3.9] + python-version: + - 3.8 + - 3.9 + - 3.10 + - 3.11 steps: - uses: actions/checkout@v2 From 6d1db13ba09cedae180e3779d912f44ca5330681 Mon Sep 17 00:00:00 2001 From: Pete R Jemian Date: Wed, 4 Oct 2023 01:58:57 -0500 Subject: [PATCH 10/14] CI #159 Py "3.10" --- .github/workflows/conda_unit_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/conda_unit_test.yml b/.github/workflows/conda_unit_test.yml index 90f92d03..9feb4898 100644 --- a/.github/workflows/conda_unit_test.yml +++ b/.github/workflows/conda_unit_test.yml @@ -12,7 +12,7 @@ jobs: python-version: - 3.8 - 3.9 - - 3.10 + - "3.10" - 3.11 steps: From 0411e9f065ddadb1bdf0a432af38d902edf1ccb7 Mon Sep 17 00:00:00 2001 From: Pete R Jemian Date: Wed, 4 Oct 2023 02:07:55 -0500 Subject: [PATCH 11/14] CI #159 combine & update --- .github/workflows/black.yml | 11 ------ .github/workflows/conda_unit_test.yml | 54 +++++++++++++++++++++++++-- .github/workflows/flake8.yml | 21 ----------- 3 files changed, 51 insertions(+), 35 deletions(-) delete mode 100644 .github/workflows/black.yml delete mode 100644 .github/workflows/flake8.yml diff --git a/.github/workflows/black.yml b/.github/workflows/black.yml deleted file mode 100644 index f58e4c63..00000000 --- a/.github/workflows/black.yml +++ /dev/null @@ -1,11 +0,0 @@ -name: Lint - -on: [push, pull_request] - -jobs: - lint: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v2 - - uses: actions/setup-python@v2 - - uses: psf/black@stable diff --git a/.github/workflows/conda_unit_test.yml b/.github/workflows/conda_unit_test.yml index 9feb4898..f339dde1 100644 --- a/.github/workflows/conda_unit_test.yml +++ b/.github/workflows/conda_unit_test.yml @@ -1,12 +1,50 @@ 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@v3 + + - 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: @@ -14,15 +52,25 @@ jobs: - 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} diff --git a/.github/workflows/flake8.yml b/.github/workflows/flake8.yml deleted file mode 100644 index 27684e79..00000000 --- a/.github/workflows/flake8.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: Code Style - -on: [push, pull_request] - -jobs: - lint: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - uses: actions/setup-python@v2 - - - name: Install Dependencies - run: | - python -m pip install --upgrade pip - pip install flake8 - - - name: Run flake8 - run: | - flake8 From 50b66a8f66e3186aa2e1cf26b23664ec6792dbf1 Mon Sep 17 00:00:00 2001 From: Pete R Jemian Date: Wed, 4 Oct 2023 02:25:39 -0500 Subject: [PATCH 12/14] DOC #159 --- RELEASE_NOTES.rst | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/RELEASE_NOTES.rst b/RELEASE_NOTES.rst index 937a8090..f8f5638e 100644 --- a/RELEASE_NOTES.rst +++ b/RELEASE_NOTES.rst @@ -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 ----- @@ -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. From 85815b1715b789818388d01d3002632c6b08bb5f Mon Sep 17 00:00:00 2001 From: Pete R Jemian Date: Fri, 6 Oct 2023 12:52:55 -0500 Subject: [PATCH 13/14] Update .github/workflows/conda_unit_test.yml Co-authored-by: Max Rakitin --- .github/workflows/conda_unit_test.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/conda_unit_test.yml b/.github/workflows/conda_unit_test.yml index f339dde1..e33028bc 100644 --- a/.github/workflows/conda_unit_test.yml +++ b/.github/workflows/conda_unit_test.yml @@ -48,10 +48,10 @@ jobs: strategy: matrix: python-version: - - 3.8 - - 3.9 + - "3.8" + - "3.9" - "3.10" - - 3.11 + - "3.11" max-parallel: 5 steps: From 47eaeb7a926afdf8d220f50bce53016240245070 Mon Sep 17 00:00:00 2001 From: Pete R Jemian Date: Fri, 6 Oct 2023 12:53:11 -0500 Subject: [PATCH 14/14] Update .github/workflows/conda_unit_test.yml Co-authored-by: Max Rakitin --- .github/workflows/conda_unit_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/conda_unit_test.yml b/.github/workflows/conda_unit_test.yml index e33028bc..2940d55e 100644 --- a/.github/workflows/conda_unit_test.yml +++ b/.github/workflows/conda_unit_test.yml @@ -21,7 +21,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: actions/setup-python@v4 with: