Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update cython bindings for python 3.6 and 2.7. Updated Tests. #23

Merged
merged 5 commits into from
May 9, 2018

Conversation

ezietsman
Copy link
Contributor

No description provided.

@seanmcleod
Copy link
Member

Thanks @ezietsman. Do these changes mean both python 2.x and 3.x are now supported or just python 3.x?

In terms of the AppVeyor build for Windows at the moment our AppVeyor build uses the Visual Studio project file and not CMake which means the python API wrapper isn't built and the python tests aren't run.

Copy link
Member

@bcoconni bcoconni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ezietsman for the patch.

I noticed that you disabled fpectl, I guess this is due to the problem you reported in #20. However I would prefer very much that we fix the build of fpectl on Mac OSX rather than disabling it altogether.

from JSBSim_utils import JSBSimTestCase, CreateFDM, RunTest, ExecuteUntil


class CheckScripts(JSBSimTestCase):
def testScripts(self):
fpectl.turnon_sigfpe()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The module fpectl is there to check that JSBSim does not raise floating point exceptions. There has been such issues in the past and this check is there to make sure there are no regressions. As such fpectl must not be disabled.

gear = grndreact.get_gear_unit(i)
self.assertEqual(gear.get_steer_norm(), 0.0)

fpectl.turnoff_sigfpe()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as for CheckScripts.py, the module fpectl is used for regression tests. It must not be disabled.

# sources=[os.path.join('${CMAKE_SOURCE_DIR}',
# 'tests',
# 'fpectlmodule.cpp')],
# language='c++')])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as previously, the module fpectl is used for regression tests and must not be disabled.

Copy link
Member

@bcoconni bcoconni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ezietsman
When I tested your code, I discovered that TestInputSocket was failing while it did not before on my system. After some investigations, I found that some of your modifications were incorrect. I have submitted some proposals to fix that. Could you please review and include them to your patch ?

['get', 'help', 'hold', 'info', 'iterate', 'quit', 'resume', 'set'])
self.assertEqual(sorted(map(lambda x: x.split('{').strip()[0]),
_tn.sendCommand("help").split('\n')[2:-2]),
['get', 'help', 'hold', 'info', 'iterate', 'quit', 'resume', 'set'])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to my tests, this code has been incorrectly modified. It should rather be

       self.assertEqual(sorted(map(lambda x: x.split('{')[0].strip(),
                                   _tn.sendCommand("help").split('\n')[2:-2])),
                               ['get', 'help', 'hold', 'info', 'iterate', 'quit', 'resume', 'set'])

Otherwise the test fails.

self.assertEqual(msg[2].split(':')[1],
root.attrib['name'].strip())
self.assertEqual(msg[1].split(':')[1],
root.attrib['version'].strip())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to my tests, this code has been incorrectly modified. It should rather be

       self.assertEqual(msg[2].split(':')[1].strip(),
                        root.attrib['name'].strip())
       self.assertEqual(msg[1].split(':')[1].strip(),
                        root.attrib['version'].strip())

Otherwise the test fails.

@bcoconni
Copy link
Member

bcoconni commented May 8, 2018

@seanmcleod I have tested successfully this pull request with Python 2.7 but I had to make some changes that I have documented above. I will merge this PR as soon as the requested changes will be reviewed and included by @ezietsman

@ezietsman
Copy link
Contributor Author

Yes, I disabled fpectl completely. That module is not available in python 3 so I'll have to look at that in some more detail.

The build worked in python 2.7 and 3.6, besides for that one test. I'll have a look and fix the issues.

@seanmcleod
Copy link
Member

@ezietsman are you sure that fpectl isn't available in python 3? This documentation for python 3 states that it isn't built by default and discourages the use of it, as opposed to it not being available at all.

https://docs.python.org/3/library/fpectl.html

And anyway aren't we building the fpectl module ourselves anyway via fpectlmodule.cpp in the tests directory?

@ezietsman
Copy link
Contributor Author

I'll have a look at that source code and try to make it work.

@seanmcleod
Copy link
Member

Ah, forgot about the Mac OSX issue with building fpectl. It may be as simple as adding some Mac OSX ifdef to call feraiseexcept instead feenableexcept etc.

@ezietsman
Copy link
Contributor Author

I've added the fpect module back in, it seems to compile now using clang on macos but only for python 2.7. The problem here is that the way modules are wrapped in python 3 has changed. So this part:

PyMODINIT_FUNC initfpectl(void)
{
  PyObject *m = Py_InitModule("fpectl", fpectl_methods);
  if (m == NULL)
    return;
  PyObject *d = PyModule_GetDict(m);
  fpe_error = PyErr_NewException((char*)"fpectl.FloatingPointError",
                                 PyExc_FloatingPointError, NULL);
  if (fpe_error != NULL)
    PyDict_SetItemString(d, "FloatingPointError", fpe_error);
}

needs to change when it is compiled using python 3.0. The new way well work in 2.7 too. I'll investigate further.

@ezietsman
Copy link
Contributor Author

https://docs.python.org/3/howto/cporting.html I think explains it. I'll look at it later at home.

@bcoconni
Copy link
Member

bcoconni commented May 9, 2018

@ezietsman thanks for your work, this is progressing very well. On my side I'm working on adding a small test to the fpectlmodule to make sure that it transforms a FP exception to a Python exception when it is turned on and that FP exceptions are ignored otherwise. That test on fpectl will be part of the test suite.

Also for the record, our version of fpectl is designed to halt the tests when a FP exception is raised. We won't try to recover from such an exception and continue execution. This should simplify the design as all we need is to make sure is that the Python interpreter is capable to quit safely. I'll document that as well.

@bcoconni
Copy link
Member

bcoconni commented May 9, 2018

@ezietsman I saw that you modified the port number of the Telnet session from 1137 to 2222 in TestInputSocket. Was that the reason why the test was failing on Mac OSX ? Is the port number 1137 already used/reserved on this platform ?

@ezietsman
Copy link
Contributor Author

ezietsman commented May 9, 2018

1137 worked and did not produce an Exception (which the test was looking for), so I changed it to one that raised an Exception. If that was wrong then the test is probably flawed. The test tested for an OSError exception.

@bcoconni bcoconni merged commit 67f2541 into JSBSim-Team:master May 9, 2018
@bcoconni
Copy link
Member

bcoconni commented May 9, 2018

PR merged. Thank you very much @ezietsman.

This was referenced May 9, 2018
@kkz003
Copy link

kkz003 commented Nov 20, 2020

I cannot build the above code

I've added the fpect module back in, it seems to compile now using clang on macos but only for python 2.7. The problem here is that the way modules are wrapped in python 3 has changed. So this part:

PyMODINIT_FUNC initfpectl(void)
{
  PyObject *m = Py_InitModule("fpectl", fpectl_methods);
  if (m == NULL)
    return;
  PyObject *d = PyModule_GetDict(m);
  fpe_error = PyErr_NewException((char*)"fpectl.FloatingPointError",
                                 PyExc_FloatingPointError, NULL);
  if (fpe_error != NULL)
    PyDict_SetItemString(d, "FloatingPointError", fpe_error);
}

needs to change when it is compiled using python 3.0. The new way well work in 2.7 too. I'll investigate further.

I cannot build this part on python3.7 and ubuntu 18.04.
I am very beginner. Please give me any advice to solve this issue and build jsbsm.

cc1plus: warning: command line option ‘-Wstrict-prototypes’ is valid for C/ObjC but not for C++
/3rd-party/src/jsbsim/tests/fpectlmodule.cpp: In function ‘PyObject* initfpectl()’:
/3rd-party/src/jsbsim/tests/fpectlmodule.cpp:130:17: error: ‘Py_InitModule’ was not declared in this scope
PyObject m = Py_InitModule("fpectl", fpectl_methods);
^~~~~~~~~~~~~
/3rd-party/src/jsbsim/tests/fpectlmodule.cpp:130:17: note: suggested alternative: ‘Py_Initialize’
PyObject m = Py_InitModule("fpectl", fpectl_methods);
^~~~~~~~~~~~~
Py_Initialize
/3rd-party/src/jsbsim/tests/fpectlmodule.cpp:132:5: error: return-statement with no value, in function returning ‘PyObject
{aka _object
}’ [-fpermissive]
return;
^~~~~~
error: command 'gcc' failed with exit status 1

@bcoconni
Copy link
Member

@kkz003
Please open a new issue in https://github.com/JSBSim-Team/jsbsim/issues for that topic.

@JSBSim-Team JSBSim-Team locked as off-topic and limited conversation to collaborators Nov 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants