Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Element names can only contain certain characters (A-z, 0-9, and _ ) #1604

Open
TacHuynh opened this issue Jun 4, 2021 · 5 comments
Open
Labels
bug impact:low pool Affecting pool feature size:M spock spock related issues

Comments

@TacHuynh
Copy link

TacHuynh commented Jun 4, 2021

Follow the Sardana training on GitHub

I can insert "MacroPath" to _MACRO_SERVER
Door_lab-02_1 [20]: _MACRO_SERVER.put_property({"MacroPath": ['C:/Users/Rdlab/Desktop/SardanaDryWellTemperatureController/macro']})

Door_lab-02_1 [21]: _MACRO_SERVER.get_property("MacroPath")
Result [21]: {'MacroPath': ['C:/Users/Rdlab/Desktop/SardanaDryWellTemperatureController/macro']}

I have problem for the Pool "PoolPath" insert:
Door_lab-02_1 [26]: Pool_lab-02_1.put_property({"PoolPath":['C:/Users/Rdlab/Desktop/SardanaDryWellTemperatureController/ctrl']})
SyntaxError: invalid syntax (, line 1)
(For more detailed information type: python_error)

@reszelaz
Copy link
Collaborator

reszelaz commented Jun 5, 2021

Hi @TacHuynh,

Your case is quite special cause your Pool name contains a minus sign -.
When you try to use the object that the Spock returns you to interact with the Pool: Pool_lab-02_1 then the IPython parses the input string and interprets the minus sign and raises a SyntaxError since this subtraction operation is of course incorrect.
You can workaround it with a call like this:


Door_lab-02_1 [6]: Pool("Pool_lab-02_1").put_property({"PoolPath":["C:\\Users\\IEUser\\Desktop\\SardanaDryWellTemperatureController\\ctrl"]})

Here you create another PyTango.DeviceProxy object to the Pool by using a shortuct call provided by iTango.
I also confirm you can use the forward slashes as you do above. At least it works to load the controller classes to the Pool.

Hope this helps,
Cheers!

@TacHuynh
Copy link
Author

TacHuynh commented Jun 5, 2021

Thanks for the work around. Will try without the "-" in "lab-02".
Excellent work in Sardana!
Tac.

@reszelaz reszelaz added the bug label Jun 11, 2021
@reszelaz reszelaz changed the title Error in Pool put_property() Element names can only contain certain characters (A-z, 0-9, and _ ) Jun 11, 2021
@reszelaz
Copy link
Collaborator

Actually, this is a more general problem.
Spock exposes Sardana elements (motors, channels, measurement groups, etc) as variables in the IPython user namespace. Since in sardana we allow any character in the element names then this causes the problem reported in this issue.

Note, these names are not problematic when passing as macro parameters:

Door/zreszela/1 [26]: defelem mot-05 motctrl01 5
Created mot-05

Door/zreszela/1 [27]: lsm
       Name          Type   Controller   Axis
 ---------- ------------- ------------ ------
      gap01   PseudoMotor   slitctrl01      1
     mot-05         Motor    motctrl01      5
      mot01         Motor    motctrl01      1
      mot02         Motor    motctrl01      2
      mot03         Motor    motctrl01      3
      mot04         Motor    motctrl01      4
   offset01   PseudoMotor   slitctrl01      2

Door/zreszela/1 [28]: mot-05.velocity
SyntaxError: invalid syntax (<ipython-input-28-64cb0791c92b>, line 1)
(For more detailed information type: python_error)

It is still possible to access these elements in the following, not user friendly, mode:

Door/zreszela/1 [22]: get_ipython().user_ns['mot-01']
        Result [22]: Motor(motor/motctrl01/5)

Anyone knows an easier way to access these variables in IPython?

If there is no, then maybe we should think of restricting the element names to use only certain characters (A-z, 0-9, and _ ).

@reszelaz reszelaz removed the question label Jun 21, 2021
@johanfforsberg
Copy link

I guess this is a little shorter:

globals()["mot-01"]

But unless it's quite important to allow this, I would think it's less confusing to just not allow defining things in spock that can't also be (easily) accessed from there.

@reszelaz
Copy link
Collaborator

Thanks @johanfforsberg for the shorter way of accessing these elements.

I agree on restricting the character set for the element names. Are there any other opinions before we start working on it?

@johanfforsberg johanfforsberg added pool Affecting pool feature spock spock related issues impact:low size:M labels Jun 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug impact:low pool Affecting pool feature size:M spock spock related issues
Projects
None yet
Development

No branches or pull requests

3 participants