Advise on requirements for version control of Qt UI XML files

Here's the place for discussion related to coding in FreeCAD, C++ or Python. Design, interfaces and structures.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
uwestoehr
Veteran
Posts: 4961
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany
Contact:

Re: Advise on requirements for version control of Qt UI XML files

Post by uwestoehr »

wmayer wrote: Thu Jan 21, 2021 4:57 pm And that's exactly the point that is hard to achieve if the diff of a ui file is a big mess. Because then it's hard to see if e.g. the minimum or maximum size of a widget has changed. In the recent months we had several PRs where this has been changed and it probably looked good on the author's machine but often was unusable on other machines.
Yes, I ran into this too. Thus I am not against a better diff. Since it turned out to become quickly comlicted to achieve, my proposal is to use David's script on the GitHub side. Maybe you know if there is a way to lrt a script run over PRs automatically? Then our problem would be solved, no matter who made the PR on what OS.
uwestoehr wrote:Some time ago I googled around and found an argument that for example the row ordering is irrelevant since the tab order should be set using the corresponding <tabstops> XML tag and the Qt Designer provides a UI to set the tab order.
wmayer wrote: In the vast majority of PR where the order of widgets has been changed the tab order was not set.
Yes, but the argument in this forum thread (cannot find it anymore :oops:) that if one needs to preserve the tab order, one should specify it explicitly instead of counting on the order in the XML.
However, for most of our dialogs the tab order is simply to jump from left to right row by row. Only for some special ones this is not the case and I will in future take care of this and set the tab order explicitly.
wmayer wrote: Feel free to just do not run the script. It can also be done by the reviewer who merges a PR.
But this gives me a guilty conscience. We are all spending our spare time here and I don't want to force other to do my work. My goal is therefore to become more effective for repeating tasks. So there must be a way to automate such a script run.
wmayer wrote: Why not just writing a batch file? Inside the batch file you can set all needed environment variables to find the Python interpreter and its libs. Then you drag and drop the ui file on the batch file.
Good idea. My intention was however to offer a ready-to-use tool so that one does not need to have a Python installation and fiddle around with modules. For example it cost me a lot of time just to be able to execute David's script. At first a module was dissing, but just installing it did not work. Then I had to google around to find that another module is used too and I had to upgrade it via pip. -> A lot of special knowledge is necessary.
davidosterberg
Posts: 529
Joined: Fri Sep 18, 2020 5:40 pm

Re: Advise on requirements for version control of Qt UI XML files

Post by davidosterberg »

uwestoehr wrote: Fri Jan 22, 2021 2:26 am For example it cost me a lot of time just to be able to execute David's script. At first a module was dissing, but just installing it did not work. Then I had to google around to find that another module is used too and I had to upgrade it via pip. -> A lot of special knowledge is necessary.
Sorry about that. Python is known to be difficult to package an distribute. This is a good example of that. The script does work if you have a general purpose python3 installed (like you have on all linux distros). I recognize that not everyone has that on windows ( I don’t know how you can live without it though :-o). Chennes mentions that he is working on a c++ version. A single exe file certainly would simplify things for the windows folks. So keep posted for that.
wmayer
Founder
Posts: 20324
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Advise on requirements for version control of Qt UI XML files

Post by wmayer »

uwestoehr wrote: Fri Jan 22, 2021 2:26 am Yes, but the argument in this forum thread (cannot find it anymore :oops:) that if one needs to preserve the tab order, one should specify it explicitly instead of counting on the order in the XML.
Yes, that's what I meant. If the author of a PR edited a dialog then in most cases he did not explicitly set the tab order.
uwestoehr wrote: Fri Jan 22, 2021 2:26 am But this gives me a guilty conscience. We are all spending our spare time here and I don't want to force other to do my work. My goal is therefore to become more effective for repeating tasks. So there must be a way to automate such a script run.
There so called hook scripts that can be executed each time you commit something but I don't know either how exactly that works.
Good idea. My intention was however to offer a ready-to-use tool so that one does not need to have a Python installation and fiddle around with modules.
You don't need a separate Python installation therefore because you already have everything you need in the LibPack. I can't remember when I have installed Python on Windows but it's for sure 10 years or more when I did that last time.
User avatar
chennes
Veteran
Posts: 3915
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Advise on requirements for version control of Qt UI XML files

Post by chennes »

davidosterberg wrote: Fri Jan 22, 2021 6:48 am Chennes mentions that he is working on a c++ version.
I had it working... almost! It's a little Qt dialog with a few checkboxes, etc. So of course I used Qt's XML parser. Hah! You can probably guess where this is going considering that Qt's XML handling is the issue we are trying to deal with in the first place. All of the attributes were getting rearranged, the parser does not keep track of what order they were in in the file. Even just reading and then writing the file, without doing anything in between, changed it. Not exactly what we are going for! So there is a slight delay while I rewrite the actual working part of the code to not parse the XML at all. Thanks @uwestoehr for the hint about preserving line endings, too, I would have forgotten to do that.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
User avatar
uwestoehr
Veteran
Posts: 4961
Joined: Sun Jan 27, 2019 3:21 am
Location: Germany
Contact:

Re: Advise on requirements for version control of Qt UI XML files

Post by uwestoehr »

wmayer wrote: Fri Jan 22, 2021 11:02 am There so called hook scripts that can be executed each time you commit something but I don't know either how exactly that works.
That would be THE solution. Who of the FC team has access to FC's GitHub account or is firm with GitHub to have a look that I can ask him/them?
You don't need a separate Python installation therefore because you already have everything you need in the LibPack.
That was what I tried at first, but the LibPack does of course not have all Python packages. In this case David's script uses the module "lxml" that was not in the Python of my LibPack.
User avatar
chennes
Veteran
Posts: 3915
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Advise on requirements for version control of Qt UI XML files

Post by chennes »

uwestoehr wrote: Fri Jan 22, 2021 3:32 pm That would be THE solution. Who of the FC team has access to FC's GitHub account or is firm with GitHub to have a look that I can ask him/them?
If you actually want it to modify the commit, I think you need a client-side pre-commit hook. I think the server-side hooks are accept/reject type things, they don't edit the commit.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Advise on requirements for version control of Qt UI XML files

Post by openBrain »

chennes wrote: Fri Jan 22, 2021 3:46 pm If you actually want it to modify the commit, I think you need a client-side pre-commit hook. I think the server-side hooks are accept/reject type things, they don't edit the commit.
I don't know in which extent a server side hook can modify a commit (I also think it can't, and in any case would be a very very bad idea).
Problem with the client-side hooks is that they have to be manually deployed locally by the contributor. AFAIK there is no way to deploy it downstream automatically to the local working copies.
So the good combination would IMO be a client-side hook that modifies and stamps the files, and a server-side hook that checks the stamp and rejects the commit with a nice message (prompting to install the client-side hook). Eventually the server-side hook can directly verify the files.
Anyway, the point is that GitHub doesn't allow to run server-side hook scripts. They only allow this feature through their "webhooks" which AFAIK are only part of their "Enterprise" subscription.
User avatar
chennes
Veteran
Posts: 3915
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Advise on requirements for version control of Qt UI XML files

Post by chennes »

openBrain wrote: Fri Jan 22, 2021 4:21 pm I don't know in which extent a server side hook can modify a commit (I also think it can't, and in any case would be a very very bad idea).
Right - to be honest I wouldn't trust a fully automated process to do this anyway. Personally, I want to look at the diffs myself before even making the local commit. So I am going to stick with a local, manually run solution for my own use. Obviously opinions differ about this, though: it may be that for @uwestoehr it is worth the manual one-time installation of an automatic pre-commit script. The git manual is quite clear that those aren't cloned as part of a repo, but it would only be a one-time step that only those people who want to edit the UI would want to undertake.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
wmayer
Founder
Posts: 20324
Joined: Thu Feb 19, 2009 10:32 am
Contact:

Re: Advise on requirements for version control of Qt UI XML files

Post by wmayer »

So, here is a convenient way to run the Python script without using a hook script.
  1. Create the file sort_ui.bat with this content

    Code: Select all

    set PATH=C:\Projects\FreeCADLibs_12.1.3_x64_VC15\bin;%PATH%
    
    cd C:\Projects\sort_ui
    python.exe sort_ui "%~f1"
    
    Adjust the paths to your setup.
  2. The lxml module can be fetched from here: https://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml
    whl is a compressed format (probably zip) that can be opened with 7-zip. Drag and drop the content to the directory of sort_ui.bat
  3. Get the file sort_ui from https://github.com/davidosterberg/Qt-UI-file-sorter and save it to the same directory
  4. Ready. That's it!
Now just drag and drop a ui file to the sort_ui.bat file.
openBrain
Veteran
Posts: 9041
Joined: Fri Nov 09, 2018 5:38 pm
Contact:

Re: Advise on requirements for version control of Qt UI XML files

Post by openBrain »

chennes wrote: Fri Jan 22, 2021 4:44 pm Right - to be honest I wouldn't trust a fully automated process to do this anyway. Personally, I want to look at the diffs myself before even making the local commit. So I am going to stick with a local, manually run solution for my own use. Obviously opinions differ about this, though: it may be that for @uwestoehr it is worth the manual one-time installation of an automatic pre-commit script. The git manual is quite clear that those aren't cloned as part of a repo, but it would only be a one-time step that only those people who want to edit the UI would want to undertake.
Totally agree. Pre-commit hook would have more sense if it comes with a server-side counterpart. But when commit final acceptance is assigned to PR mergers, better provide the contributors something like a Python script that they can manually run on the UI files.
Post Reply