Skip to content

Commit

Permalink
Have itl2py Take Care of CMake Config File Dir
Browse files Browse the repository at this point in the history
So users won't have to pass that to `pip install`.
  • Loading branch information
iguessthislldo committed Oct 18, 2021
1 parent b6b20e6 commit 380b285
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 7 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/pyopendds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
pull_request:
branches:
- master
workflow_dispatch:
workflow_dispatch:
schedule:
- cron: "0 3 * * 5"

Expand Down Expand Up @@ -61,7 +61,7 @@ jobs:
make
itl2py -o basic_output basic_idl basic.itl
cd basic_output
basic_idl_DIR=$(realpath ..) python -m pip --verbose install .
python -m pip --verbose install .
- name: Run Basic Test
run: |
Expand All @@ -77,7 +77,7 @@ jobs:
make
itl2py -o basic_output basic_idl basic.itl
cd basic_output
basic_idl_DIR=$(realpath ..) python -m pip --verbose install .
python -m pip --verbose install .
- name: Run Basic C++11 Test
run: |
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ limitations.
- Python >= 3.7
- This uses the C API of CPython, so PyPy or any other Python implementation
is not supported.
- OpenDDS
- Right now this is being developed using the master branch of OpenDDS.
- OpenDDS >= 3.16
- CMake >= 3.12
- A C++14 Compiler

Expand All @@ -40,7 +39,7 @@ make
# Build and Install Basic Test Python Type Support
itl2py -o basic_output basic_idl basic.itl
cd basic_output
basic_idl_DIR=$(realpath ..) pip install .
pip install .

# Run Basic Test
cd ../..
Expand Down
2 changes: 1 addition & 1 deletion docs/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ below in this directory.
# Build and Install Basic Test Python Type Support
itl2py -o basic_output basic_idl basic.itl
cd basic_output
basic_idl_DIR=$(realpath ..) pip install .
pip install .
# Run Basic Test
cd ../..
Expand Down
20 changes: 20 additions & 0 deletions pyopendds/dev/itl2py/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ def main():
help='''\
Name of the native Python extension package to create. By default this is \'_\'
and the name of the Python package.''')
argparser.add_argument('--idl-library-build-dir',
metavar='IDL_LIBRARY_BUILD_DIR', type=Path,
help='''\
Location of the CMake config file to use. By default this will be the location
of all the input ITL files if they are in the same location. If they are not or
the exepcted config file is not there, then this option becomes required.'''),
argparser.add_argument('--default-encoding',
type=str, default='utf_8',
help='Default encoding of strings. By default this is UTF-8.')
Expand All @@ -47,6 +53,20 @@ def main():
args.package_name = 'py' + args.itl_files[0].stem
if args.native_package_name is None:
args.native_package_name = '_' + args.package_name
if args.idl_library_build_dir is None:
args.idl_library_build_dir = args.itl_files[0].resolve().parent
for path in args.itl_files[1:]:
if path.resolve().parent != args.idl_library_build_dir:
sys.exit('''\
--idl-library-build-dir is required when ITL files are in different directories''')
else:
args.idl_library_build_dir = args.idl_library_build_dir.resolve()
config_filename = '{}Config.cmake'.format(args.idl_library_cmake_name)
config_path = args.idl_library_build_dir / config_filename
if not config_path.is_file():
sys.exit('''\
Native IDL library CMake config file {} does not exist, please pass the
directory for it (where cmake was ran) using --idl-library-build-dir'''.format(config_path))

# Generate The Python Package
generate(vars(args))
Expand Down
1 change: 1 addition & 0 deletions pyopendds/dev/itl2py/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def generate(context: dict) -> None:
'''Generate a Python IDL binding package given a dict of arguments. The
arguments are the following:
- idl_library_cmake_name
- idl_library_build_dir
- itl_files
- output
- package_name
Expand Down
1 change: 1 addition & 0 deletions pyopendds/dev/itl2py/templates/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ find_package(Python3 ${PYOPENDDS_PYTHON_VERSION} EXACT
REQUIRED
)
find_package(OpenDDS REQUIRED)
set({{ idl_library_cmake_name }}_DIR {{ idl_library_build_dir }})
find_package({{ idl_library_cmake_name }} REQUIRED)

Python3_add_library({{ native_package_name }} MODULE {{ native_package_name }}.cpp)
Expand Down

0 comments on commit 380b285

Please sign in to comment.