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

Build a proper Python package #755

Merged
merged 5 commits into from
Oct 31, 2022
Merged

Conversation

bcoconni
Copy link
Member

@bcoconni bcoconni commented Oct 31, 2022

This PR improves the structure of our Python module so that:

  • The C++ module and the data files (aircraft, engines, systems, etc.) will all be installed under a single folder lib/python3.*/site-packages/jsbsim (while currently the module is installed just below the folder lib/python3.*/site-packages/ and the data files are installed in the folder share/JSBSim).
  • The licenses files will be installed in the above mentioned folder jsbsim (so far they were not installed at all).
  • Addressing the issue Python type information for pylance autocompletion #750 needs that there exists a folder in which the C++ module is located so that the type hinting stubs *.pyi can be installed alongside. This last topic is actually what is motivating this PR.

There are a couple of design decisions that come with this PR. Below are their descriptions.

A proxy __init__.py now loads _jsbsim to mimic import jsbsim

Since the C++ module will now be located under jsbsim, it will no longer be possible to import it directly with the command import jsbsim. That's annoying because it breaks backward compatibility. However that problem has been solved following the example of the package contourpy: the C++ module is renamed _jsbsim and is loaded by the file __init__.py which serves as a simple proxy. So when the command import jsbsim is issued, __init__.py is called to load _jsbsim, read its symbols (FGFDMExec, etc.) and return them.

As a consequence, the content of __init__.py is trivial.

The file _jsbsim.pxd is installed

Incidentally, the file _jsbsim.pxd will be installed along with the package. This is due to the following constraints:

  • _jsbsim.pxd must be distributed with the Python source package *.tar.gz so that JSBSim can be built by pip on platforms for which no wheels are available.
  • Since the C++ module is now a "submodule" jsbsim._jsbsim, cython and/or setuptools require that _jsbsim.pxd also meet that structure and be located in the package i.e. in jsbsim/_jsbsim.pxd.
  • Wheels are basically duplicating the folder organization of the source packages they are built from so _jsbsim.pxd will be installed by our Python wheels even though the file is no longer needed at this stage.

The last topic can be addressed by programming setup.py to skip the installation of _jsbsim.pxd but the file is less than 100kb so I guess we can live with it for now.

The script JSBSim has been renamed JSBSim.py

This one breaks backward compatibility. It is requested because case insensitive OSes (Windows and MacOSX) cannot manage a script named JSBSim and a folder named jsbsim both located in the same directory.

It is most likely feasible to hack setup.py to rename JSBSim.py back to JSBSim (at least during the package installation) but I have not yet investigated that option.

@codecov
Copy link

codecov bot commented Oct 31, 2022

Codecov Report

Merging #755 (749faa9) into master (0172378) will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master     #755   +/-   ##
=======================================
  Coverage   22.48%   22.48%           
=======================================
  Files         167      167           
  Lines       19138    19138           
=======================================
  Hits         4304     4304           
  Misses      14834    14834           

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@bcoconni bcoconni merged commit 9a77151 into JSBSim-Team:master Oct 31, 2022
@bcoconni bcoconni deleted the python_package branch October 31, 2022 13:38
bcoconni added a commit to bcoconni/jsbsim that referenced this pull request Nov 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant