diff --git a/README.md b/README.md index fcc4d62..135be6f 100644 --- a/README.md +++ b/README.md @@ -7,12 +7,14 @@ Python virtual environment wrapper package, based on [catkin_virtualenv](https:/ This package provides a mechanism to: +- choose that the target package should be run in a virtual Python environment of the desired version - export python library requirements in `requirements.txt` format via `package.xml`. - bundle a virtualenv within a ament package, inheriting requirements from any dependencies. - wrap python scripts and tests in a ament package with a virtualenv loader. -At build time, CMake macros provided by this package will create a virtualenv, and create -wrapper scripts for any Python scripts in the package. Both will be included in any associated bloom artifacts. +At build time, Python commands and CMake macros provided by this package will create a virtualenv, and create +wrapper scripts for Python scripts installed by the in the target package. +Both will be included in the release. This library is GPL licensed due to the inclusion of dh_virtualenv. @@ -35,47 +37,70 @@ Add an export to `package.xml`: ``` -Make sure to install the requirements file in `CMakeLists.txt`: -```cmake -install(FILES requirements.txt - DESTINATION ${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}) +If your package uses `ament_python` as build tool, add the following to your `setup.py` file: + +```python +import setuptools.command.install +import ament_virtualenv.install + +class InstallCommand(setuptools.command.install.install): + def run(self): + super().run() + ament_virtualenv.install.install_venv( + install_base=self.install_base, + package_name=package_name, + python_version='2' + ) + # instead of self.install_base we may also use: + # self.config_vars['platbase'] or self.config_vars['base'] + # Exchange the python_version with '3' if your package uses Python3. + return + +setup( + cmdclass={ + 'install': InstallCommand + }, ``` -If an ament package exports dependencies in a `requirements.txt` file, any dependent ament package that bundles a virtualenv (see below) will inherit those dependencies. -## Bundling virtualenv -It's possible to bundle all of an ament package's python requirements, as well as those of its ament dependencies, into a virtualenv. +If your package uses `ament_cmake` as build tool, add the following to your `CMakeLists.txt`: -This operation does not do any dependency resolution - similar to how `pip` operates, the topmost dependency declaration -'wins' (https://github.com/pypa/pip/issues/988). +```cmake +find_package(ament_cmake_virtualenv REQUIRED) +ament_generate_virtualenv(PYTHON_VERSION 2) +# Exchange the python_version with '3' if your package uses Python3. -Add an build dependency on ament_virtualenv to `package.xml`, as well as on any library packages you may want. Traditionally +# Tell ament to install your Python module: +ament_python_install_module(path/to/my/module.py) +# ... or a whole folder containing a Python package: +ament_python_install_package(path/to/your/package) -```xml -ament_virtualenv +# Tell ament also to copy the requirements.txt file +install(FILES requirements.txt + DESTINATION ${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}) - -some_python_library ``` -In CMakeLists.txt: -```cmake -# Make sure to find-package `ament_cmake_virtualenv` -find_package(ament_cmake REQUIRED) -find_package(ament_cmake_virtualenv REQUIRED) +Finally, add an build dependency on ament_virtualenv to your `package.xml`. -# Generate the virtualenv: -ament_generate_virtualenv() +If you're using `ament_python` as build tool: +```xml +ament_virtualenv +``` -# Must be called after target definitons -ament_package() +If you're using `ament_cmake` as build tool: +```xml +ament_cmake_virtualenv ``` +If an ament package exports dependencies in a `requirements.txt` file, any dependent ament package that bundles a virtualenv (see below) will inherit those dependencies. +Note that the requirements installation does not do any dependency resolution - similar to how `pip` operates, the topmost dependency declaration +'wins' (https://github.com/pypa/pip/issues/988). + ### Additional CMake Options @@ -84,7 +109,7 @@ The following options are supported by `ament_generate_virtualenv()`: ```cmake ament_generate_virtualenv( # Select an alternative version of the python interpreter - it must be installed on the system. Minor version is optional. - PYTHON_VERSION 3.7 # Default 2 + PYTHON_VERSION 3.7 # Default 3 # Choose not to use underlying system packages. This excludes any python packages installed by apt or system-pip from the environment. USE_SYSTEM_PACKAGES FALSE # Default TRUE diff --git a/ament_cmake_virtualenv/CHANGELOG.rst b/ament_cmake_virtualenv/CHANGELOG.rst index 6962882..42ef0a4 100644 --- a/ament_cmake_virtualenv/CHANGELOG.rst +++ b/ament_cmake_virtualenv/CHANGELOG.rst @@ -2,6 +2,10 @@ Changelog for package ament_cmake_virtualenv ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +0.0.3 (2019-12-04) +------------------ +* various bug-fixes + 0.0.2 (2019-11-21) ------------------ * various bug-fixes diff --git a/ament_cmake_virtualenv/package.xml b/ament_cmake_virtualenv/package.xml index 9062f59..1a49cc5 100644 --- a/ament_cmake_virtualenv/package.xml +++ b/ament_cmake_virtualenv/package.xml @@ -22,7 +22,7 @@ along with this program. If not, see . --> ament_cmake_virtualenv - 0.0.2 + 0.0.3 Bundle python requirements in a ament package via virtualenv. Max Krichenbauer diff --git a/ament_virtualenv/CHANGELOG.rst b/ament_virtualenv/CHANGELOG.rst index 0b76608..9036e4c 100644 --- a/ament_virtualenv/CHANGELOG.rst +++ b/ament_virtualenv/CHANGELOG.rst @@ -2,6 +2,10 @@ Changelog for package ament_virtualenv ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +0.0.3 (2019-12-04) +------------------ +* various bug-fixes + 0.0.2 (2019-11-21) ------------------ * various bug-fixes diff --git a/ament_virtualenv/package.xml b/ament_virtualenv/package.xml index 47348b8..9b56332 100644 --- a/ament_virtualenv/package.xml +++ b/ament_virtualenv/package.xml @@ -22,7 +22,7 @@ along with this program. If not, see . --> ament_virtualenv - 0.0.2 + 0.0.3 Bundle python requirements in a ament package via virtualenv. Max Krichenbauer diff --git a/test_ament_cmake_virtualenv/CHANGELOG.rst b/test_ament_cmake_virtualenv/CHANGELOG.rst new file mode 100644 index 0000000..624e706 --- /dev/null +++ b/test_ament_cmake_virtualenv/CHANGELOG.rst @@ -0,0 +1,7 @@ +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +Changelog for package test_ament_cmake_virtualenv +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +0.0.3 (2019-12-04) +------------------ +* added this package to the release diff --git a/test_ament_cmake_virtualenv/package.xml b/test_ament_cmake_virtualenv/package.xml index 31b0880..216bc4a 100644 --- a/test_ament_cmake_virtualenv/package.xml +++ b/test_ament_cmake_virtualenv/package.xml @@ -22,7 +22,7 @@ along with this program. If not, see . --> test_ament_cmake_virtualenv - 0.0.2 + 0.0.3 Package to test ament_cmake_virtualenv Max Krichenbauer GPL diff --git a/test_ament_virtualenv/CHANGELOG.rst b/test_ament_virtualenv/CHANGELOG.rst index 310b054..4b3e1d6 100644 --- a/test_ament_virtualenv/CHANGELOG.rst +++ b/test_ament_virtualenv/CHANGELOG.rst @@ -2,6 +2,10 @@ Changelog for package test_ament_virtualenv ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +0.0.3 (2019-12-04) +------------------ +* various bug-fixes + 0.0.2 (2019-11-21) ------------------ * various bug-fixes diff --git a/test_ament_virtualenv/package.xml b/test_ament_virtualenv/package.xml index 32beea0..9ade88a 100644 --- a/test_ament_virtualenv/package.xml +++ b/test_ament_virtualenv/package.xml @@ -22,7 +22,7 @@ along with this program. If not, see . --> test_ament_virtualenv - 0.0.2 + 0.0.3 Package to test ament_virtualenv. Max Krichenbauer