Skip to content

Commit

Permalink
Supply aircraft data with the Python wheels (issue JSBSim-Team#337).
Browse files Browse the repository at this point in the history
Default JSBSim aircraft data (including its engine and systems data) and scripts are now included in the Python wheels.

The files are installed in the sys.prefix folder under share/JSBSim.
  • Loading branch information
bcoconni committed Nov 7, 2021
1 parent 13f7b74 commit bcb9c6c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
10 changes: 3 additions & 7 deletions .github/workflows/cpp-python-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -476,13 +476,9 @@ jobs:
uses: actions/checkout@v2
- name: Prepare the build
run: |
mkdir build
mkdir build/python
mv python/ExceptionManagement.h build/python/.
mv python/fpectl/fpectlmodule.h build/python/.
mv python/JSBSim.py build/python/JSBSim
mv src build/python/.
pip install -U numpy wheel
pip install -U numpy wheel cython
mkdir build && cd build
cmake -DINSTALL_PYTHON_MODULE=ON -DBUILD_JULIA_PACKAGE=OFF ..
- name: Download binary files
uses: actions/download-artifact@v2
with:
Expand Down
6 changes: 6 additions & 0 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ foreach(_FILE "MANIFEST.in" "jsbsim.pxd" "ExceptionManagement.h"
endforeach()
file(RENAME ${CMAKE_CURRENT_BINARY_DIR}/JSBSim.py ${CMAKE_CURRENT_BINARY_DIR}/JSBSim)

# Duplicate data files (i.e. aircraft, engines, etc.)
file(COPY ${CMAKE_SOURCE_DIR}/aircraft DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/data)
file(COPY ${CMAKE_SOURCE_DIR}/engine DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/data)
file(COPY ${CMAKE_SOURCE_DIR}/systems DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/data)
file(COPY ${CMAKE_SOURCE_DIR}/scripts DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/data)

# Copy each source file and collect the compile flags specified by add_definitions()
foreach(OBJECT ${libJSBSim_SOURCE_FILES})
string(SUBSTRING ${OBJECT} 0 17 HEADER)
Expand Down
4 changes: 4 additions & 0 deletions python/MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ recursive-include . *.h*
include *.pyx
include *.pxd
include src/simgear/xml/xmltok_*.c
recursive-include data/aircraft/ *.xml
recursive-include data/engine/ *.xml
recursive-include data/systems/ *.xml
recursive-include data/scripts/ *.xml
23 changes: 23 additions & 0 deletions python/setup.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,28 @@ else:
setup_kwargs = {'cmdclass' : {'build_ext': BuildC_CxxExtension,},
'setup_requires': ["setuptools>=24.2", "cython>=0.25"]}

# Prepare the list of XML data files (aircraft, engines, ...)

# Iterate over the XML files in a directory
def XML_files(dir_name):
dir_fullname = os.path.join('data', dir_name)
for f in os.scandir(dir_fullname):
if f.is_file() and os.path.splitext(f.name)[-1] == '.xml':
yield os.path.join(dir_fullname, f.name)

data_files = [
('share/${PROJECT_NAME}/engine', list(XML_files('engine'))),
('share/${PROJECT_NAME}/systems', list(XML_files('systems'))),
('share/${PROJECT_NAME}/scripts', list(XML_files('scripts'))),
]

# Iterate over the aircraft folders
for d in os.scandir('data/aircraft'):
if d.is_dir():
dir_name = 'aircraft/' + d.name
data_files.append(('share/${PROJECT_NAME}/'+dir_name,
list(XML_files(dir_name))))

# Build & installation process for the JSBSim Python module
setup(
name="${PROJECT_NAME}",
Expand Down Expand Up @@ -209,4 +231,5 @@ setup(
install_requires=['numpy'],
ext_modules=[Extension('jsbsim', language='c++', **ext_kwargs)],
python_requires=">=3.6",
data_files=data_files,
**setup_kwargs)

0 comments on commit bcb9c6c

Please sign in to comment.