bluesky / hklpy

Diffractometer computation library with ophyd pseudopositioner support
https://blueskyproject.io/hklpy
BSD 3-Clause "New" or "Revised" License
2 stars 11 forks source link

refactor configuration to use typing and apischema #280

Closed prjemian closed 9 months ago

prjemian commented 9 months ago

docs: https://github.com/bluesky/hklpy/blob/279-refactor-and-use-typing-and-apischema/docs/source/configuration.rst

Also this new feature: https://github.com/bluesky/hklpy/blob/e3d04e631d68cc33b722c3d9c4d8cb4c52ef93c7/hkl/util.py#L230-L240

To try this branch locally, these Linux bash commands might help you install it:

conda activate your-environment
pip install apischema

cd ~/Documents/or/wherever
git clone https://github.com/bluesky/hklpy
cd hklpy
git checkout 279-refactor-and-use-typing-and-apischema
pip install --no-deps -e . 
prjemian commented 9 months ago

I believe these changes will help set the groundwork for (parts of) the common diffractometer API needed for v2.0, including reflections.

prjemian commented 9 months ago

Most Unit tests pass locally for all Python versions using nektos/act, won't run on GHA due to CI choices.

These Py3.9 tests failed due to missing conda command:

| /root/micromamba/envs/hklpy-test-py-3.9/lib/python3.9/subprocess.py:1837: FileNotFoundError
| =========================== short test summary info ============================
| FAILED hkl/tests/test_util.py::test__package_info_states - FileNotFoundError: [Errno 2] No such file or directory: 'conda'
| FAILED hkl/tests/test_util.py::test_get_package_info[bluesky-1.6] - FileNotFoundError: [Errno 2] No such file or directory: 'conda'
| FAILED hkl/tests/test_util.py::test_get_package_info[pygobject-3.40] - FileNotFoundError: [Errno 2] No such file or directory: 'conda'
| FAILED hkl/tests/test_util.py::test_get_package_info[hkl-5.0.0] - FileNotFoundError: [Errno 2] No such file or directory: 'conda'
| FAILED hkl/tests/test_util.py::test_get_package_info[hklpy-0] - FileNotFoundError: [Errno 2] No such file or directory: 'conda'
| FAILED hkl/tests/test_util.py::test_get_package_info[no-such-package----] - FileNotFoundError: [Errno 2] No such file or directory: 'conda'
| FAILED hkl/tests/test_util.py::test_software_versions_default_list[None] - FileNotFoundError: [Errno 2] No such file or directory: 'conda'
| FAILED hkl/tests/test_util.py::test_software_versions_default_list[case1] - FileNotFoundError: [Errno 2] No such file or directory: 'conda'
| FAILED hkl/tests/test_util.py::test_software_versions_default_list[] - FileNotFoundError: [Errno 2] No such file or directory: 'conda'
| FAILED hkl/tests/test_util.py::test_software_versions_items[bluesky-1.6] - FileNotFoundError: [Errno 2] No such file or directory: 'conda'
| FAILED hkl/tests/test_util.py::test_software_versions_items[pygobject-3.40] - FileNotFoundError: [Errno 2] No such file or directory: 'conda'
| FAILED hkl/tests/test_util.py::test_software_versions_items[hkl-5.0.0] - FileNotFoundError: [Errno 2] No such file or directory: 'conda'
| FAILED hkl/tests/test_util.py::test_software_versions_items[hklpy-0] - FileNotFoundError: [Errno 2] No such file or directory: 'conda'
| FAILED hkl/tests/test_util.py::test_software_versions_items[no-such-package----] - FileNotFoundError: [Errno 2] No such file or directory: 'conda'
| ======================= 14 failed, 174 passed in 20.74s ========================

Not concerned since local tests run with nektos/act fail in odd ways, usually due to cache access.

prjemian commented 9 months ago

Since this is a side-branch PR, I'm inclined to merge it myself. But this PR shows the code that was refactored from the original PR branch. A documentation table was added to util.py: new_lattice() to show how to use it.

For some reason, no docs are generated for new_lattice() or the new classes and functions in configuration.py. Dunno why but can live with it now.

prjemian commented 9 months ago

@strempfer please comment

padraic-shafer commented 9 months ago

It looks like apischema has a mechanism for reporting multiple invalid values at a time.

This could be useful when someone is validating a new source of configuration data (perhaps while setting up a sample/orientation db?)...rather than iterating one error at a time. Then again, it could be pretty annoying to get 20+ error messages from a simple typo or misassigned variable.

prjemian commented 9 months ago

It looks like apischema has a mechanism for reporting multiple invalid values at a time.

This could be useful when someone is validating a new source of configuration data (perhaps while setting up a sample/orientation db?)...rather than iterating one error at a time. Then again, it could be pretty annoying to get 20+ error messages from a simple typo or misassigned variable.

Let's keep this in mind, if it becomes a requested feature. I like the premise keeping an error dump brief and focused.

prjemian commented 9 months ago

Addition, JSON and Python dict structures do not allow for comments. I can imagine situations where either comments or unanticipated terms may be added to a configuration file. The nature of apischema and explicit typing annotations might fail with such ad hoc additions. Add an additional dictionary (default is {}, so it is optional).

prjemian commented 9 months ago

I'm ready to merge this into the 256-orientation-dict branch. We can continue to comment there. But at least the CI testing will happen since that branch would merge to main.

prjemian commented 9 months ago

The testing workflow can be run manually on this branch. Running that now.

prjemian commented 9 months ago

CI unit tests pass for Py3.8-Py3.11!

strempfer commented 9 months ago

Some error with 6-circe diffractometer:

In [9]: config=DiffractometerConfiguration(diffract) In [10]: settings=config.export() AttributeError: 'gi.repository.Hkl' object has no attribute 'VERSION'

prjemian commented 9 months ago

You need to upgrade your environment. It is using an old version of the conda package called hkl

conda update hkl

On Tue, Oct 31, 2023, 3:18 PM Jörg Strempfer @.***> wrote:

Some error with 6-circe diffractometer:

In [9]: config=DiffractometerConfiguration(diffract) In [10]: settings=config.export() AttributeError: 'gi.repository.Hkl' object has no attribute 'VERSION'

— Reply to this email directly, view it on GitHub https://github.com/bluesky/hklpy/pull/280#issuecomment-1787972108, or unsubscribe https://github.com/notifications/unsubscribe-auth/AARMUMAAAQL6PG4B6MV3XU3YCFMJXAVCNFSM6AAAAAA6UGDN3GVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTOOBXHE3TEMJQHA . You are receiving this because you modified the open/close state.Message ID: @.***>