diff --git a/cmake/env-hooks/42.site_packages.sh.develspace.in b/cmake/env-hooks/42.site_packages.sh.develspace.in index bab0c16..5d08d62 100755 --- a/cmake/env-hooks/42.site_packages.sh.develspace.in +++ b/cmake/env-hooks/42.site_packages.sh.develspace.in @@ -51,17 +51,18 @@ fi # NOT DOING THIS any longer : it half-works but somehow doesnt change behavior when using catkin cmake scripts : usual python way, editable links are after python path # TO FIX IT : use pyros_setup -# # Prepending here our easy-install.pth content into PYTHONPATH, for overlayed workspace to get it before the workspace path -# # Somehow Python pth/.egg behavior doesnt work well with workspace overlays, based on PYTHONPATH. -# # However be aware of : https://github.com/pypa/pip/issues/3160 -# # And : https://github.com/pypa/pip/issues/4261 -# if [ -f "@CATKIN_DEVEL_PREFIX@/@CATKIN_PIP_PYTHON_INSTALL_DIR@/easy-install.pth" ]; then -# # Ref : http://stackoverflow.com/questions/4165135/how-to-use-while-read-bash-to-read-the-last-line-in-a-file-if-there-s-no-new -# while IFS='' read -r DEVEL_PKG_PATH || [ -n "$DEVEL_PKG_PATH" ]; do -# #echo "Inserting $DEVEL_PKG_PATH before "@CATKIN_DEVEL_PREFIX@/@CATKIN_PIP_PYTHON_INSTALL_DIR@" into PYTHONPATH" -# PYTHONPATH=$("@CATKIN_PIP_SCRIPTS_PATH@/path_prepend.sh" "$DEVEL_PKG_PATH" "${PYTHONPATH}" "@CATKIN_DEVEL_PREFIX@/@CATKIN_PIP_PYTHON_INSTALL_DIR@") || ${PYTHONPATH} # to be safe if path_prepend fails -# done <"@CATKIN_DEVEL_PREFIX@/@CATKIN_PIP_PYTHON_INSTALL_DIR@/easy-install.pth" -# fi +# REVISION : we should not rely on pyros-setup. FIX THIS HERE ! +# Prepending here our easy-install.pth content into PYTHONPATH, for overlayed workspace to get it before the workspace path +# Somehow Python pth/.egg behavior doesnt work well with workspace overlays, based on PYTHONPATH. +# However be aware of : https://github.com/pypa/pip/issues/3160 +# And : https://github.com/pypa/pip/issues/4261 +if [ -f "@CATKIN_DEVEL_PREFIX@/@CATKIN_PIP_PYTHON_INSTALL_DIR@/easy-install.pth" ]; then + # Ref : http://stackoverflow.com/questions/4165135/how-to-use-while-read-bash-to-read-the-last-line-in-a-file-if-there-s-no-new + while IFS='' read -r DEVEL_PKG_PATH || [ -n "$DEVEL_PKG_PATH" ]; do + #echo "Inserting $DEVEL_PKG_PATH before "@CATKIN_DEVEL_PREFIX@/@CATKIN_PIP_PYTHON_INSTALL_DIR@" into PYTHONPATH" + PYTHONPATH=$("@CATKIN_PIP_SCRIPTS_PATH@/path_prepend.sh" "$DEVEL_PKG_PATH" "${PYTHONPATH}" "@CATKIN_DEVEL_PREFIX@/@CATKIN_PIP_PYTHON_INSTALL_DIR@") || ${PYTHONPATH} # to be safe if path_prepend fails + done <"@CATKIN_DEVEL_PREFIX@/@CATKIN_PIP_PYTHON_INSTALL_DIR@/easy-install.pth" +fi # Exporting is required to make sure we get the new value in children processes (catkin_make, test runs, etc.) diff --git a/test/catkin_pip_pytest/conftest.py b/test/catkin_pip_pytest/conftest.py index feed551..43b53e1 100644 --- a/test/catkin_pip_pytest/conftest.py +++ b/test/catkin_pip_pytest/conftest.py @@ -2,9 +2,6 @@ import sys import pytest -# Imports CANNOT be in fixtues (pytest would cleanup modules, preventing re-import...) -import pyros_setup - def pytest_addoption(parser): parser.addoption("--build-dir", action="store", default="build", help="the build directory") @@ -68,34 +65,3 @@ def install_space(): assert os.path.exists(os.path.abspath(os.path.join('install', 'setup.sh'))), "install/setup.bash not found in {0}".format(os.getcwd()) ws = os.path.abspath('install') return ws - -@pytest.fixture -def pyros(): - # IMPORTANT : Without pyros_setup configuration activated, - # the develop packages are set in sys.path AFTER the site-packages and dist-packages - # This is because of incompatibilities between ROS and python ways of handling PYTHONPATH. - # It is usually not a problem, unless : - # - you are working in a devel space with catkin_pip and expect to use a editable package from there - # - you have the same package installed somewhere else in the PYTHONPATH - # And in that case it might end up being *before* the source dir in sys.path - # - # => Without pyros_setup, the installed version will be preferred - # This is the python (and tools) way of working, since PYTHONPATH purpose is to override file-based setup, - # like editable packages. - # - # => With pyros_setup, the devel version will be preferred - # This is the ROS way of working, since PYTHONPATH order determine the order of folder when looking for a package. - # - # Both will work fine in most cases, but one might want to keep this corner case in mind... - - print("sys.path before pyros_setup {pyros_setup.__file__} :\n{sys.path}".format(**globals())) - - # We need to pass the proper workspace here - pyros_setup.configurable_import().configure({ - 'WORKSPACES': [ - devel_space() - ], # This should be the same as pytest devel_space fixture - 'DISTRO': pyros_setup.DETECTED_DISTRO, - }).activate() - - # We cannot move pyros_setup outside the fixture (pytest would clean it up and break module imports) diff --git a/test/catkin_pip_pytest/test_syspath_pyros.py b/test/catkin_pip_pytest/test_syspath_pyros.py deleted file mode 100644 index ac486e0..0000000 --- a/test/catkin_pip_pytest/test_syspath_pyros.py +++ /dev/null @@ -1,63 +0,0 @@ -from __future__ import absolute_import -from __future__ import print_function - -import pytest -import sys - -""" -This module is a test for catkin_pip, with pyros_setup. -It is expected to run DIRECTLY with pytest, from the build directory -Ex : If you ran ./travis_checks.bash that is /home/alexv/Projects/ros_pyros_ws/src/catkin_pip/testbuild - -It is here to make testing/debugging sys.path issues from IDE easier : -- run ./travis_checks -- setup a test target (careful with the working directory) -- run it (and you can debug inside...) - -Note however that this test module is run with catkin_pip tests as well -to make sure pyros_setup fixes our catkin import problems. -""" - -from . import test_syspath - -# -# Tests importing pyros_setup via fixture and automatically setting configuration -# All these should PASS in any case. -# - - -@pytest.mark.xfail(reason="this has no meaning without catkin_pip, since pyros_setup does not rely and has no knowledge of catkin_pip") -def test_catkin_pip_env_dir_in_sys_path(catkin_pip_env_dir): - return test_syspath.test_catkin_pip_env_dir_in_sys_path(catkin_pip_env_dir) - - -def test_devel_site_in_sys_path(pyros, devel_space): - return test_syspath.test_devel_site_in_sys_path(devel_space) - - -# this fails since dist-packages does not exists -@pytest.mark.xfail(reason="dist-packages does not exist in our example since all packages use catkin_pip") -def test_devel_dist_in_sys_path(pyros, devel_space): - return test_syspath.test_devel_dist_in_sys_path(devel_space) - - -# this fails since dist-packages does not exists -@pytest.mark.xfail(strict=True, reason="dist-packages does not exist in our example since all packages use catkin_pip") -def test_devel_site_before_devel_dist_in_sys_path(pyros, devel_space): - return test_syspath.test_devel_site_before_devel_dist_in_sys_path(devel_space) - - -@pytest.mark.xfail(reason="this has no meaning without catkin_pip, since pyros_setup does not rely and has no knowledge of catkin_pip") -def test_devel_site_before_catkin_pip_site_in_sys_path(pyros, catkin_pip_env_dir, devel_space): - return test_syspath.test_devel_site_before_catkin_pip_site_in_sys_path(catkin_pip_env_dir, devel_space) - - -@pytest.mark.xfail(reason="this has no meaning without catkin_pip, since pyros_setup does not rely and has no knowledge of catkin_pip") -def test_devel_dist_before_catkin_pip_site_in_sys_path(pyros, catkin_pip_env_dir, devel_space): - return test_syspath.test_devel_dist_before_catkin_pip_site_in_sys_path(catkin_pip_env_dir, devel_space) - - -# Using Pyros_setup is the only way to get this to work as expected. -# That is getting devel packages in sys.path before ROS workspaces from PYTHONPATH. -def test_sys_path_editable(pyros, git_working_tree, devel_space): - return test_syspath.test_sys_path_editable(git_working_tree, devel_space)