-
Notifications
You must be signed in to change notification settings - Fork 51
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
Code quality improvements to the TangoShutter Class #847
Conversation
Co-authored-by: fabcor <fabien.coronis@maxiv.lu.se>
This reverts commit 557ff3c. Going back to pre - git hooks.
…mport gevent, changing import order
Updating local repo
Update pre commit
Co-authored-by: fabcor <fabien.coronis@maxiv.lu.se>
Merging the latest TangoShutter changes : adding logging and some coments
Just pushed the latest updates. I added logging as well. |
I don't know how relevant this is but, if somene needs to use a list in the xml config file , make sure to use double quotes ("). I copy-pasted the configuration from the comment to the xml file for a test and it had replaced the double quotes (") with simple quotes (') resulting in a json parsing error. No (') are allowed in the json inside the xml ! Only ("). :) |
Just updated the comment section with the example provided by @beteva as well as a warning about using only double quotes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am sorry, but I really, really hate this. I can see that this particular PR is not making the difference; the main point is already merged in, so it is too late. But really:
Putting JSON strings inside XML is bad in itself. But worse, we have here a major change to the configuration system, that has not been discussed as such, and that is only valid for TangoShutters and only implemented inside TangoShutter.py. How are we to keep track of what is happening, if every class uses its own custom configuration system? What happens when someone has to make a new class and looks for examples on how to configure it? What happens if someone else reads inside those XML properties (you are allowed to) and tries to untangle this on his own, maybe to figure out (from the configuration files) what the applicable states for a TangoShutter are?
Supposedly, you can store any data structure you need with XML. It is not very practical, which is why moving to another format seems such a good idea, but while we are agreed on using XML surely the correct procedure is to take the trouble and use XML, not to put in your own hacks.
What I would like to see at this point is either
- a proposal for how we are to use JSON-inside-XML as the overall configuration system for MXCuBE in the future, complete with rules for how it is applied and a rationale for why it is a good idea.
or
- An explanation for why this is a temporary aberration, and how we can make sure that it will go away again without serving as a pattern for future implementations.
@HilbertCorsair, what was the issue with XML here again? If this can be expressed with XML, this should be expressed with XML. I looked again at the previous pull request, but could not find the rationale why this does not use XML all the way. Did I miss it? Is there a reasoning written down somewhere? [It might be my fault that we focused on the " |
As a side effect for testing this code, we wrote some unit tests for this implementation of TangoShutter: Fell free to include this into this PR. If that complicates thing to much, I'll make a separate PR in the future. |
I don't like the current configuartion solution either. I'm allready looking into configuration by yaml but this will take some time. I can try a different configuration using only XML. I will test this Monday. Bottom line is that we need a way to mapp any unconventional local tango shutter value : state pare to the conventional states definded in the class. I's not always necesarry and the code doesn't change anything in the configuration of Tango shutters that have conventional values. This is why the values tag in the xml file is optional, as a solution for any shuters with unconventional local tango values (CLOSE instead of CLOSED for example). I don't think there is an issue using just XML for this however if we want to have a general Tango shutter class I don't see an easy way arround have to use 2 configuration sysems (one for shutters with conventional values and one for shutters with unconventional values). The current version does this by importing the json dictionary whenever a shutter has nonconvetional values. I saw this in an example somwhere but I guess we don't neceserly need json. |
Oh! But I see now, that this is already done with mxcubecore/mxcubecore/HardwareObjects/abstract/AbstractNState.py Lines 80 to 88 in e4b2434
Then we should definitely have stuck to this! Can we see concrete examples of what we want to write in the XML file that can not be handled by |
If one of the parent classes already uses |
TangoShutter class: dropping json for literal_eval and other changes
@fabcor-maxiv Done! |
@HilbertCorsair Thanks for your work :) We plan on testing this latest version tomorrow. Have you considered adding the basic unit test to this PR? |
Import all changes from this PR: mxcube#847 TODO: drop this commit once the PR have been merged, or if rejected, deal with it
Some unit tests for checking mxcubecore.HardwareObjects.TangoShutter shutter hardware object.
I just added the basic unit test proposed by @elmjag : elmjag/mxcubecore@6076956 . Thanks @fabcor-maxiv |
""" | ||
|
||
|
||
VALUES_JSON = """ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rename this variable to for example VALUES_LITERAL
. The VALUES_JSON
is now confusing, as technically speaking we are not supporting JSON strings but pythong literal expressions. Event if it so happens in this case that text is identical.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @elmjag, I am a bit puzzled that we need a special test for the TangoShutter and not using the generic shutter test. Do we miss something in the generic shutter test or the ShutterMockup. If such is the case, maybe it is worth adding your work to the generic shutter test, so it would serve other shutter types, not just the Tango ones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are tests to test code in TangoShutter.py. The generic shutter test code does not cover it, as it is using ShutterMockup hardware object.
More specifically these tests set-up an actual tango device and instantiate a TangoShutter hardware object that talks to that device. This way you check that opening/closing shutter work, with TangoShutter hwo, using real tango stack.
They way I read the code in test/pytest/test_shutter.py
, it is testing the code in the abstract classes starting with AbstractShutter.
The tests in test_shutter.py
and test_hwo_tango_shutter.py
are testing related, but separate aspects of the code base.
I have tested this PR, it works fine! Just one addition nitpick comment. Can we please squash all commits in this PR? 20+ commits feels a bit, ahum, noisy in the git history. |
Thank you everybody for the efforts to make the perfect TangoShutter Hardware Object. I think this has been a very useful not only for the TangoShutter, bur also to serve as a model not only for similar hardware objects, which would inherit from AbstractNState, but also for hardware objects, using Tango commands and properties. |
I'm happy to merge this but there is a conflict, could you have a look @HilbertCorsair ? |
Import all changes from this PR: mxcube#847 TODO: drop this commit once the PR have been merged, or if rejected, deal with it
Import all changes from this PR: mxcube#847 TODO: drop this commit once the PR have been merged, or if rejected, deal with it
Import all changes from this PR: mxcube#847 TODO: drop this commit once the PR have been merged, or if rejected, deal with it
Import all changes from this PR: mxcube#847 TODO: drop this commit once the PR have been merged, or if rejected, deal with it
Import all changes from this PR: mxcube#847 TODO: drop this commit once the PR have been merged, or if rejected, deal with it
Import all changes from this PR: mxcube#847 TODO: drop this commit once the PR have been merged, or if rejected, deal with it
Import all changes from this PR: mxcube#847 TODO: drop this commit once the PR have been merged, or if rejected, deal with it
Import all changes from this PR: mxcube#847 TODO: drop this commit once the PR have been merged, or if rejected, deal with it
Import all changes from this PR: mxcube#847 TODO: drop this commit once the PR have been merged, or if rejected, deal with it
Import all changes from this PR: mxcube#847 TODO: drop this commit once the PR have been merged, or if rejected, deal with it
Import all changes from this PR: mxcube#847 TODO: drop this commit once the PR have been merged, or if rejected, deal with it
Import all changes from this PR: mxcube#847 TODO: drop this commit once the PR have been merged, or if rejected, deal with it
Import all changes from this PR: mxcube#847 TODO: drop this commit once the PR have been merged, or if rejected, deal with it
A more formal way to retreve unconventional shutter states from the xml configuration file and add them to the class standard values dictionary with conventional names.