That's a good idea! I'm expecting this initial proposal to mostly get the conversation started and iterate on it until all is well. Considering the source files are all automatically generated by another program, I'm expecting a finite set of edge cases. This does sound like one of them.
But, don't you feel working at the abstract tree-level is perhaps a tad premature? Spontaneously I'd first try splitting lines at file-open, via e.g. file.readlines(). Another reason for going with .replace() as opposed to jumping straight into regular expressions is readability and maintainability. I want to enable others to understand the conversion and make changes to it where necessary. Both re and AST carry the potential of making these options fairly limited. Thanks, and if you have any ui files (I know you generally don't work with them, neither do I) do let me know! > On 7 Sep 2016, at 22:38, Justin Israel <[email protected]> wrote: > > Hey Marcus, > > It's a cool goal that you are trying to make everyone's workflows more > compatible and consistent. Keep it up. > > Quick question about the approach to providing the convert functionality... > Do you think splitting the file on a '\n' and doing line-by-line string > replacements is a viable approach? Could it be possible to break the code if > someone has a '\n' in some text of their widget or the word 'PySide2"? I know > its pretty specific right now with the 2 replacements its doing, but you > might end up adding more changes once you get feedback. > Have you looked at a safe approach that parses and rewrites the AST? > Something like the rope project or even the ast stdlib module if you are > really against dependencies? At least you could be sure that you are only > refactoring, say, the renaming of an import. Or renaming a method of a class. > > Just throwing that out there to see if it helps. > > Justin > >> On Thu, Sep 8, 2016 at 9:00 AM Marcus Ottosson <[email protected]> >> wrote: >> Hi all, >> >> Many of you have been asking about working with ui files in a way maintains >> the cross-binding benefit of Qt.py. >> >> The problem has been that: >> >> a) PySide and PyQt implement the in-memory loading mechanism loadUi() >> differently and >> b) Files compiled via the command-line leave artifacts behind that make it >> difficult to run the result on another binding. >> One suggestion was to: >> >> Compile to Python via PySide2 >> Convert to cross-compatible Qt.py code afterwards. >> So that’s what is happening here. >> >> https://github.com/mottosso/Qt.py/pull/132 >> $ pyside2-uic my_ui.ui -o my_ui.py >> $ python -m Qt --convert my_ui.py >> $ cat my_ui_.py >> What we need now is: >> >> Loads of .ui files to test with (if you have a stash, now’s the time to >> share!) >> Your feedback on whether this approach is one worth pursuing >> Let me know what you think! >> >> Best, >> Marcus >> >> -- >> Marcus Ottosson >> [email protected] >> -- >> You received this message because you are subscribed to the Google Groups >> "Python Programming for Autodesk Maya" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/python_inside_maya/CAFRtmOAjdKbcXmfG1LNSyA514-HC9XC3UkxtXq0fNUb6Nj%2BAJg%40mail.gmail.com. >> For more options, visit https://groups.google.com/d/optout. > > -- > You received this message because you are subscribed to the Google Groups > "Python Programming for Autodesk Maya" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1oNG3qmkTXajcrfnTGLvoonZJ_PBmmnjSO3kqZYVEA9Q%40mail.gmail.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Python Programming for Autodesk Maya" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/python_inside_maya/2060697B-7EFD-436A-8CDD-6E18347070E5%40gmail.com. For more options, visit https://groups.google.com/d/optout.
