Closed waltonereed closed 6 years ago
This is something I haven't considered, but is a bug. Wooey would need to represent the types as a widget element, but what element it should be is ambiguous if it is a function. My instinct is to declare it as a charfield and let the user manually update the widget to their specs. I'd appreciate any other opinions on this.
I'm facing the same issue (I have a custom type - to allow for both hex and decimal values as input). Is there any plan to add this support in near future?
This is actually a problem with the parser in clinto. It's pretty straight forward to just handle this like a CharField, so I did that. You will need to install from master to use that version of clinto -- I'd love to know if it works as intended for you.
Thanks Chris. I did not really pull the master - but manually merged in your changes, and it does seem to work. Just to understand this better (I'm fairly new to Python itself) - this change of handling this as "CharField" will automatically call the respective function, or would the user still need to process the arguments in the script? I think it happens automatically based on my trial - but wanted to make sure.
Secondly, there is a related issue: I had another script which uses type = str.lower() in order for the command line to accept both upper case and lower case representations of the string input. However, importing that script throws error: Exception Type: | TypeError 'NoneType' object is not subscriptable
That is correct -- CharField
means it will pass a string to your function, that then processes it.
For the second, the type is not a function. If you set it like: type=lambda x: x.lower()
, it would work.
Sorry - I think I made a typo above. The actual usage was: type = str.lower e.g. parser.add_argument('--magic', dest='magic', default=hex(0xcd), type = str.lower, choices = [hex(0xab), hex(0xcd)]) This works in the script (will allow any of the two values regardless of case - e.g. 0xAB, 0xaB, 0xAb, 0xab when using the command line) - but causes problem with Wooey import.
The alternate you suggested does work though.
This is interesting. That is because str.lower
is a method_descriptor
and not actually a FunctionType
. Calling str.lower('ABC')
, you are passing 'ABC' as self to the lower
method of the str
object. It works, but it definitely isn't standard :)
A follow up PR fixed the use of str.lower
and any other generally callable action type, https://github.com/wooey/clinto/pull/33
I created a custom type for
parser.add_argument
, and this works fine when I run the my script directly through the console. However, when I try to upload the script through the command linemanage.py addscript
, I get a bunch of error messages, like below:Here's my script--
aacomm
is a custom package I wrote that basically accepts a YYYYMMDD input and reads a .csv file through Pandas. The remaining part of the script exports 10 records to a .csv file.When I change the
type=int
, the script uploads fine to Wooey. Is there something I'm missing?