Skip to content

Commit

Permalink
Make using Python easier
Browse files Browse the repository at this point in the history
- Move Pipfile to the root of the project, so docs and CMake builds
  can access it

- Fix python/CMakeLists.txt

- Document
  • Loading branch information
jasujm committed Dec 2, 2019
1 parent fe55535 commit ff2506b
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ install(FILES ${ENHANCEDENUM_CONFIG}

install(DIRECTORY ${ENHANCEDENUM_INCLUDE_DIR}/ DESTINATION include)

set(ENHANCEDENUM_BUILD_TESTS OFF CACHE BOOL "Build tests")
if(ENHANCEDENUM_BUILD_TESTS)
enable_testing()
endif()
Expand All @@ -64,7 +65,6 @@ if(ENHANCEDENUM_BUILD_DOCS)
add_subdirectory(docs)
endif()

set(ENHANCEDENUM_BUILD_TESTS OFF CACHE BOOL "Build tests")
if(ENHANCEDENUM_BUILD_TESTS)
add_subdirectory(cxx/tests)
endif()
Expand Down
File renamed without changes.
File renamed without changes.
39 changes: 30 additions & 9 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ The Enhanced Enum library specific CMake variables are:
$ python setup.py build
$ python setup.py install
...but does some extra bootstrapping to build out-of-source. The
package is thus installed in the current site-packages. You can also
do normal in-source build for greater control.
...but does some extra bootstrapping to build out-of-source.

- ``ENHANCEDENUM_BUILD_TESTS``: Build tests for the C++ and/or Python
packages
Expand All @@ -44,12 +42,35 @@ imported target ``EnhancedEnum::EnhancedEnum``:
find_package(EnhancedEnum)
target_link_libraries(my-target EnhancedEnum::EnhancedEnum)
Docs, EnumECG and unit tests *all* require Python when being built. A
build environment can be bootstrapped using the ``Pipfile`` under
the ``python/`` directory:
Python environment
------------------

Docs, EnumECG and unit tests *all* require Python when being built. To
use the CMake targets, a suggested approach is to create a build
directory under the sources where the project ``Pipfile `` is
available.
.. code-block:: console
$ mkdir /path/to/repository/build
$ cd /path/to/repository/build
$ pipenv install --dev
$ pipenv run cmake \
> -D ENHANCEDENUM_BUILD_DOCS:BOOL=ON \
> -D ENHANCEDENUM_BUILD_TESTS:BOOL=ON \
> ..
$ make && make test
However, ``make install`` target may not make much sense with this
workflow, as it will only install :mod:`enumecg` to the current
virtualenv. If want to install development version of the EnumECG
library via CMake, you should use an external virtualenv:

.. code-block:: console
$ cd /path/to/repository/python
$ pipenv install --dev
$ pipenv shell
(venv) $ cd /path/to/build/dir
(venv) $ cmake -D ENHANCEDENUM_BUILD_PYTHON:BOOL=ON /path/to/repository
(venv) $ make && make install
It is of course possible to build and install EnumECG by invoking a
more typical in-source build.
2 changes: 2 additions & 0 deletions python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ include(FindPython)
find_package(Python)

if(Python_FOUND)
get_target_property(PYTHON_EXECUTABLE Python::Interpreter LOCATION)
set(PYTHON_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/build/lib")
file(MAKE_DIRECTORY ${PYTHON_BUILD_DIR})

set(ENUMECG_SETUP "${CMAKE_CURRENT_SOURCE_DIR}/setup.py")
set(ENUMECG_OUTPUT "${PYTHON_BUILD_DIR}/timestamp")
Expand Down

0 comments on commit ff2506b

Please sign in to comment.