[Solved] (Bug) Problem running the dependency checker

A subforum specific to the development of the OpenFoam-based workbenches ( Cfd https://github.com/qingfengxia/Cfd and CfdOF https://github.com/jaheyns/CfdOF )

Moderator: oliveroxtoby

vocx
Posts: 736
Joined: Thu Oct 18, 2018 9:18 pm

[Solved] (Bug) Problem running the dependency checker

Postby vocx » Tue Apr 16, 2019 7:17 pm

I installed OpenFoam as indicated here https://openfoam.org/download/6-ubuntu/ The installation seemed to go well, as I could run the example and visualize the result in paraview. However, in FreeCAD, the CfdOF dependency checker seems to not detect the components correctly.

If I use FreeCAD 0.18.1, with Python 3, installed from the freecad-stable PPA, I get this error.

Code: Select all

import CfdTools
CfdTools.checkCfdDependencies()

Code: Select all

Checking CFD workbench dependencies...
Checking FreeCAD version
Traceback (most recent call last):
  File "/home/ecc/.FreeCAD/Mod/CfdOF/CfdPreferencePage.py", line 159, in runDependencyChecker
    msg = CfdTools.checkCfdDependencies()
  File "/home/ecc/.FreeCAD/Mod/CfdOF/CfdTools.py", line 685, in checkCfdDependencies
    gitver = ver[2].split()[0]
IndexError: list index out of range
The error is due to the way CfdOF checks for the version of FreeCAD.

Code: Select all

ver = FreeCAD.Version()

print(ver)
['0', '18.1', '', 'https://code.launchpad.net/~vcs-imports/freecad/trunk', '2019/04/06 19:19:55']
The checkCfdDependencies() function tries to parse the git version number, that is, the third element in the list, but since this string is empty, it fails.

On the other hand, if I use a development release of FreeCAD 0.18, which has a git number, it works.

Code: Select all

ver = FreeCAD.Version()

print(ver)
['0', '18', '16093 (Git)', 'git://github.com/FreeCAD/FreeCAD.git releases/FreeCAD-0-18', '2019/03/12 13:38:07', 'releases/FreeCAD-0-18', '690774c0effe4fd7b8d2b5e2fb2b8c8d145e21ce']
This is the version that is currently in the freecad-daily repository, which hasn't been updated in a while. As you can see, the "stable" release produces a shorter list of strings than the development version, and doesn't include the git revision.

I think the checkCfdDependencies() function also does something like int(ver[1]). This also fails because the second element of the list is not an integer, but a float. That is, it tries to convert the string "18.1" to an integer and it fails. It works correctly if the string is "18", as in the development version.

So, I think these checks need some try: except: blocks to check for different styles of the version returned by FreeCAD.Version(). In particular, the check shouldn't fail with the "stable" version; it is disconcerting if a check seems to fail with software that is supposed to be "stable".

Code: Select all

try:
    check if version is "18" with git commit "1246"
except:
    parse another way to get "18.1" with no git commit
else:
    assume the version is correct
---------------

Another issue. If I use the checkCfdDependencies() in the development version, 0.18, 16093 (Git), with Python 2, the output looks fine. The end of line characters are correctly recognized so the output is correctly spaced.

Code: Select all

Checking FreeCAD version
Checking for OpenFOAM:
Running  echo $WM_PROJECT_VERSION
Raw command:  ['bash', '-c', 'source "/opt/openfoam6/etc/bashrc" && echo $WM_PROJECT_VERSION']
6
Running  cartesianMesh -help
Raw command:  ['bash', '-c', 'source "/opt/openfoam6/etc/bashrc" && cartesianMesh -help']

Usage: cartesianMesh [OPTIONS]
options:
  -case <dir>       specify alternate case directory, default is the cwd
  -fileHandler <handler>
...
However, if I use the "stable" version 0.18.1, with Python 3, the output is not parsed correctly. It seems that the output of the external commands is not interpreted as text, but as binary data. In this case, the end of line characters '\n' are shown in the returned string, and the entire output looks badly formated.

Code: Select all

Checking FreeCAD version
Checking for OpenFOAM:
Running  echo $WM_PROJECT_VERSION
Raw command:  ['bash', '-c', 'source "/opt/openfoam6/etc/bashrc" && echo $WM_PROJECT_VERSION']
b'6\n'Error parsing OpenFOAM version string b'6\n'
Running  cartesianMesh -help
Raw command:  ['bash', '-c', 'source "/opt/openfoam6/etc/bashrc" && cartesianMesh -help']
b'\n'b'Usage: cartesianMesh [OPTIONS]\n'b'options:\n'b'  -case <dir>       specify alternate case directory, default is the cwd\n'b'  -fileHandler <handler>\n'b'                    override the fileHandler\n'b'  -hostRoots <(((host1 dir1) .. (hostN dirN))>\n'

...
The output strings appear as b'something\n'; the newline is not actually used in the console.

I believe checkCfdDependencies() internally uses subprocess to run the tools in the command line, but maybe some options aren't correctly set up, so the output isn't being displayed correctly when run in Python 3.

---------

And finally. Paraview is not detected by checkCfdDependencies(). Not with the 0.18 development (16093) nor with the 0.18.1 stable version.

It was correctly installed. As I said, I can run the examples.

Code: Select all

which -a paraview

/opt/paraviewopenfoam56/bin/paraview
It seems checkCfdDependencies() internally uses distutils to check for the presence of paraview, but it's not being found.

Code: Select all

        paraview_cmd = "paraview"

        # Otherwise, the command 'paraview' must be in the path - test to see if it exists
        import distutils.spawn
        if distutils.spawn.find_executable(paraview_cmd) is None:
The other external commands seem to be found by running the name of the executable through runFoamCommand(), which internally uses subprocess. It seems runFoamCommand() first sources the OpenFoam resource file that sets up the environmental variables, and then runs the program, for example:

Code: Select all

Running  cartesianMesh -help
Raw command:  ['bash', '-c', 'source "/opt/openfoam6/etc/bashrc" && cartesianMesh -help']
So, again, maybe there should be a try: except: block. If the distutil.spawn check fails, it should try loading the resource file and running the paraview executable inside /opt.

Code: Select all

Running  paraview
Raw command:  ['bash', '-c', 'source "/opt/openfoam6/etc/bashrc" && paraview']
Something like this

Code: Select all

try:
    distutils.spawn.find_executable(paraview_cmd)
except:
    runFoamCommand(paraview_cmd)
---------

In this thread I'm only talking about the dependency check in the CfdOF preferences window (Edit -> Preferences -> CFD); I haven't checked if the actual operation of CfdOF fails because of this. Everything, OpenFoam, Paraview, cfMesh, and HiSA seem to be correctly installed. So, it is a case that the everything is installed but the software still reports problems. I think the dependency check should be more robust so as to not confuse new users that want to start using CfdOF.
Last edited by vocx on Sun Apr 21, 2019 10:44 pm, edited 1 time in total.
Syres
Posts: 297
Joined: Thu Aug 09, 2018 11:14 am

Re: (Bug) Problem running the dependency checker

Postby Syres » Wed Apr 17, 2019 12:41 pm

I believe the packaging team have been changing at the very least the Windows 0.18.1 version (I'm sure all OS will be brought into line) so now the version output is as follows:

Code: Select all

ver = FreeCAD.Version()
print(ver)
['0', '18', '16110 (Git)', 'git://github.com/FreeCAD/FreeCAD.git', '2019/04/04 13:42:43', '(HEAD detached at upstream/releases/FreeCAD-0-18)', 'f7dccfaa909e5b9da26bf50c4a22ccca9bb10c40']
Therefore my Dependencies check passes with No Missing Dependencies as expected.

OS: Windows 7
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.16110 (Git)
Build type: Release
Branch: (HEAD detached at upstream/releases/FreeCAD-0-18)
Hash: f7dccfaa909e5b9da26bf50c4a22ccca9bb10c40
Python version: 3.6.6
Qt version: 5.6.2
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/UnitedKingdom (en_GB)
vocx
Posts: 736
Joined: Thu Oct 18, 2018 9:18 pm

Re: (Bug) Problem running the dependency checker

Postby vocx » Wed Apr 17, 2019 3:51 pm

Syres wrote:
Wed Apr 17, 2019 12:41 pm
I believe the packaging team have been changing at the very least the Windows 0.18.1 version (I'm sure all OS will be brought into line) so now the version output is as follows:

Code: Select all

ver = FreeCAD.Version()
print(ver)
['0', '18', '16110 (Git)', 'git://github.com/FreeCAD/FreeCAD.git', '2019/04/04 13:42:43', '(HEAD detached at upstream/releases/FreeCAD-0-18)', 'f7dccfaa909e5b9da26bf50c4a22ccca9bb10c40']
Is this the daily image or is it the stable ("final") build? Because as I said, the daily build seems to show the information "correctly" (or as usual). It was only the stable build the one that had this problem.

Also, kkremitzki has noticed this and would like to discuss the best approach Patching to display 0.18.1 & the topic of git commits/patch versions.
Syres
Posts: 297
Joined: Thu Aug 09, 2018 11:14 am

Re: (Bug) Problem running the dependency checker

Postby Syres » Wed Apr 17, 2019 4:08 pm

vocx wrote:
Wed Apr 17, 2019 3:51 pm
Is this the daily image or is it the stable ("final") build? Because as I said, the daily build seems to show the information "correctly" (or as usual). It was only the stable build the one that had this problem.

Also, kkremitzki has noticed this and would like to discuss the best approach Patching to display 0.18.1 & the topic of git commits/patch versions.
I wasn't aware there was a 'daily' 0.18.1, I was always under the impression that the 'daily' applied to cutting edge 0.19.16475 etc.
vocx
Posts: 736
Joined: Thu Oct 18, 2018 9:18 pm

Re: (Bug) Problem running the dependency checker

Postby vocx » Wed Apr 17, 2019 4:23 pm

Syres wrote:
Wed Apr 17, 2019 4:08 pm
I wasn't aware there was a 'daily' 0.18.1, I was always under the impression that the 'daily' applied to cutting edge 0.19.16475 etc.
Yes, maybe we are misunderstanding each other. What I meant to say was, that version that you shown, is that the stable Windows 0.18.1 release?

Because if it is, it is reporting the version just like the daily releases do (which before they were 0.18, but now they should be 0.19).
Syres
Posts: 297
Joined: Thu Aug 09, 2018 11:14 am

Re: (Bug) Problem running the dependency checker

Postby Syres » Wed Apr 17, 2019 4:39 pm

The installer 'ellipsed' in red is the one I quoted above:
Attachments
0_18_1_Install.jpg
0_18_1_Install.jpg (120.98 KiB) Viewed 248 times
User avatar
oliveroxtoby
Posts: 281
Joined: Fri Dec 23, 2016 9:43 am
Location: South Africa

Re: (Bug) Problem running the dependency checker

Postby oliveroxtoby » Wed Apr 17, 2019 8:45 pm

vocx wrote:
Tue Apr 16, 2019 7:17 pm
I installed OpenFoam as indicated here https://openfoam.org/download/6-ubuntu/ The installation seemed to go well, as I could run the example and visualize the result in paraview. However, in FreeCAD, the CfdOF dependency checker seems to not detect the components correctly.

If I use FreeCAD 0.18.1, with Python 3, installed from the freecad-stable PPA, I get this error.

Code: Select all

Checking CFD workbench dependencies...
Checking FreeCAD version
Traceback (most recent call last):
  File "/home/ecc/.FreeCAD/Mod/CfdOF/CfdPreferencePage.py", line 159, in runDependencyChecker
    msg = CfdTools.checkCfdDependencies()
  File "/home/ecc/.FreeCAD/Mod/CfdOF/CfdTools.py", line 685, in checkCfdDependencies
    gitver = ver[2].split()[0]
IndexError: list index out of range
Thanks, should be fixed. Could you check if it works for you?
However, if I use the "stable" version 0.18.1, with Python 3, the output is not parsed correctly. It seems that the output of the external commands is not interpreted as text, but as binary data. In this case, the end of line characters '\n' are shown in the returned string, and the entire output looks badly formated.

Code: Select all

Checking FreeCAD version
Checking for OpenFOAM:
Running  echo $WM_PROJECT_VERSION
Raw command:  ['bash', '-c', 'source "/opt/openfoam6/etc/bashrc" && echo $WM_PROJECT_VERSION']
b'6\n'Error parsing OpenFOAM version string b'6\n'
Running  cartesianMesh -help
Raw command:  ['bash', '-c', 'source "/opt/openfoam6/etc/bashrc" && cartesianMesh -help']
b'\n'b'Usage: cartesianMesh [OPTIONS]\n'b'options:\n'b'  -case <dir>       specify alternate case directory, default is the cwd\n'b'  -fileHandler <handler>\n'b'                    override the fileHandler\n'b'  -hostRoots <(((host1 dir1) .. (hostN dirN))>\n'

...
I think I have corrected the character decoding, but I was not able to reproduce this issue so could you confirm whether this has sorted it out for you?
And finally. Paraview is not detected by checkCfdDependencies(). Not with the 0.18 development (16093) nor with the 0.18.1 stable version.

It was correctly installed. As I said, I can run the examples.

Code: Select all

which -a paraview

/opt/paraviewopenfoam56/bin/paraview
Should be sorted.
vocx
Posts: 736
Joined: Thu Oct 18, 2018 9:18 pm

Re: (Bug) Problem running the dependency checker

Postby vocx » Sat Apr 20, 2019 5:39 pm

oliveroxtoby wrote:
Wed Apr 17, 2019 8:45 pm
Thanks, should be fixed. Could you check if it works for you?
All three issues seem to be resolved now. The FreeCAD version is parsed correctly; the output of CfdTools.checkCfdDependencies() is displayed fine in Python 3; and the paraview executable is found.