Skip to content

reactivating the envhook for adding editable packages to pythonpath. #121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions cmake/env-hooks/42.site_packages.sh.develspace.in
Original file line number Diff line number Diff line change
Expand Up @@ -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.)
Expand Down
34 changes: 0 additions & 34 deletions test/catkin_pip_pytest/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
63 changes: 0 additions & 63 deletions test/catkin_pip_pytest/test_syspath_pyros.py

This file was deleted.