diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index ab98a0bc..ad9c3ca2 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -8,9 +8,6 @@ jobs: fail-fast: false matrix: versions: - - dist: ubuntu-20.04 - python: "3.8" - catkin: indigo-devel - dist: ubuntu-20.04 python: "3.8" catkin: noetic-devel @@ -39,7 +36,7 @@ jobs: python -m pip install --upgrade pip pip install . # Fix some sphinx versions until python 3.7 support is dropped - pip install --upgrade empy 'sphinx_rtd_theme<1.2.0' 'sphinxcontrib-spelling<8.0.0' pytest nose coverage flake8 mock isort + pip install --upgrade empy sphinx_rtd_theme sphinxcontrib-spelling pytest nose coverage flake8 mock isort - name: Set up catkin run: | git clone https://github.com/ros/catkin.git -b ${{ matrix.versions.catkin }} /tmp/catkin_source diff --git a/catkin_tools/execution/io.py b/catkin_tools/execution/io.py index b5a8b40e..7b88bbf9 100644 --- a/catkin_tools/execution/io.py +++ b/catkin_tools/execution/io.py @@ -26,19 +26,6 @@ MAX_LOGFILE_HISTORY = 10 -if type(u'') == str: - def _encode(string): - """Encode a Python 3 str into bytes. - :type data: str - """ - return string.encode('utf-8') -else: - def _encode(string): - """Encode a Python 2 str into bytes. - :type data: str - """ - return string.decode('utf-8').encode('utf-8') - class IOBufferContainer(object): @@ -133,7 +120,7 @@ def _encode(data): """Encode a Python str into bytes. :type data: str """ - return _encode(data) + return data.encode('utf8') @staticmethod def _decode(data): diff --git a/catkin_tools/jobs/cmake/python.cmake b/catkin_tools/jobs/cmake/python.cmake index c72b8599..4020aacf 100644 --- a/catkin_tools/jobs/cmake/python.cmake +++ b/catkin_tools/jobs/cmake/python.cmake @@ -1,11 +1,29 @@ # the CMake variable PYTHON_INSTALL_DIR has the same value as the Python function catkin.builder.get_python_install_dir() -set(PYTHON_VERSION "$ENV{ROS_PYTHON_VERSION}" CACHE STRING "Specify specific Python version to use ('major.minor' or 'major')") -find_package(PythonInterp ${PYTHON_VERSION} REQUIRED) +set(PYTHON_VERSION "$ENV{ROS_PYTHON_VERSION}" CACHE STRING "Specify specific Python version to use (2 or 3)") +if("${PYTHON_VERSION}" STREQUAL "") + message(STATUS "ROS_PYTHON_VERSION not set, using default") +endif() + +find_package(Python${PYTHON_VERSION} COMPONENTS Interpreter) + +if("${PYTHON_VERSION}" STREQUAL "3") + set(_MAJOR ${Python3_VERSION_MAJOR}) + set(_MINOR ${Python3_VERSION_MINOR}) + set(_EXECUTABLE ${Python3_EXECUTABLE}) +elseif("${PYTHON_VERSION}" STREQUAL "2") + set(_MAJOR ${Python2_VERSION_MAJOR}) + set(_MINOR ${Python2_VERSION_MINOR}) + set(_EXECUTABLE ${Python2_EXECUTABLE}) +else() + set(_MAJOR ${Python_VERSION_MAJOR}) + set(_MINOR ${Python_VERSION_MINOR}) + set(_EXECUTABLE ${Python_EXECUTABLE}) +endif() -message(STATUS "Using PYTHON_EXECUTABLE: ${PYTHON_EXECUTABLE}") +message(STATUS "Using PYTHON_EXECUTABLE: ${_EXECUTABLE}") -set(_PYTHON_PATH_VERSION_SUFFIX "${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}") +set(_PYTHON_PATH_VERSION_SUFFIX "${_MAJOR}.${_MINOR}") set(enable_setuptools_deb_layout OFF) if(EXISTS "/etc/debian_version") @@ -18,8 +36,8 @@ if(SETUPTOOLS_DEB_LAYOUT) set(PYTHON_PACKAGES_DIR dist-packages) set(SETUPTOOLS_ARG_EXTRA "--install-layout=deb") # use major version only when installing 3.x with debian layout - if("${PYTHON_VERSION_MAJOR}" STREQUAL "3") - set(_PYTHON_PATH_VERSION_SUFFIX "${PYTHON_VERSION_MAJOR}") + if("${_MAJOR}" STREQUAL "3") + set(_PYTHON_PATH_VERSION_SUFFIX "${_MAJOR}") endif() else() message(STATUS "Using default Python package layout") diff --git a/tests/system/verbs/catkin_build/test_pythonpath.py b/tests/system/verbs/catkin_build/test_pythonpath.py index 8f05e2bb..80cc3247 100644 --- a/tests/system/verbs/catkin_build/test_pythonpath.py +++ b/tests/system/verbs/catkin_build/test_pythonpath.py @@ -37,7 +37,7 @@ def test_python2_devel(): ws_pythonpath = [p for p in pythonpaths if p.startswith(wf.workspace)][0] assert ws_pythonpath # it might be dist-packages (debian) or site-packages - assert re.match('^' + wf.workspace + '/devel/lib/python2\.\d/(site|dist)-packages$', ws_pythonpath) + assert re.match('^' + wf.workspace + r'/devel/lib/python2\.\d/(site|dist)-packages$', ws_pythonpath) def test_python3_devel(): @@ -55,7 +55,7 @@ def test_python3_devel(): assert ws_pythonpath # it might be python3/dist-packages (debian) or python3.x/site-packages assert (ws_pythonpath == wf.workspace + '/devel/lib/python3/dist-packages' or - re.match('^' + wf.workspace + '/devel/lib/python3\.\d/site-packages$', ws_pythonpath)) + re.match('^' + wf.workspace + r'/devel/lib/python3\.\d/site-packages$', ws_pythonpath)) def test_python2_install(): @@ -74,7 +74,7 @@ def test_python2_install(): ws_pythonpath = [p for p in pythonpaths if p.startswith(wf.workspace)][0] assert ws_pythonpath # it might be dist-packages (debian) or site-packages - assert re.match('^' + wf.workspace + '/install/lib/python2\.\d/(site|dist)-packages$', ws_pythonpath) + assert re.match('^' + wf.workspace + r'/install/lib/python2\.\d/(site|dist)-packages$', ws_pythonpath) def test_python3_install(): @@ -92,4 +92,4 @@ def test_python3_install(): assert ws_pythonpath # it might be python3/dist-packages (debian) or python3.x/site-packages assert (ws_pythonpath == wf.workspace + '/install/lib/python3/dist-packages' or - re.match('^' + wf.workspace + '/install/lib/python3\.\d/site-packages$', ws_pythonpath)) + re.match('^' + wf.workspace + r'/install/lib/python3\.\d/site-packages$', ws_pythonpath))