Skip to content
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

Python 3 compatiblity tweaks #9

Merged
merged 1 commit into from Nov 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
51 changes: 27 additions & 24 deletions catkin_virtualenv/cmake/catkin_generate_virtualenv.cmake
Expand Up @@ -33,40 +33,24 @@ function(catkin_generate_virtualenv)
set(${PROJECT_NAME}_VENV_DEVEL_DIR ${venv_devel_dir} PARENT_SCOPE)
set(${PROJECT_NAME}_VENV_INSTALL_DIR ${venv_install_dir} PARENT_SCOPE)

if(${ARG_PYTHON3})
set(build_venv_extra "--python3")
set(PYTHON_VERSION_MAJOR 3)
endif()

if(NOSETESTS)
if(${ARG_PYTHON3})
find_program(nosetests NAMES
"nosetests${PYTHON_VERSION_MAJOR}"
"nosetests-${PYTHON_VERSION_MAJOR}"
"nosetests")
else()
set(nosetests ${NOSETESTS})
endif()

set(nosetests "${venv_devel_dir}/bin/python${PYTHON_VERSION_MAJOR} ${nosetests}")

# (pbovbel): NOSETESTS originally set by catkin here:
# <https://github.com/ros/catkin/blob/kinetic-devel/cmake/test/nosetests.cmake#L86>
message(STATUS "Using virtualenv to run Python nosetests: ${nosetests}")
set(NOSETESTS ${nosetests} PARENT_SCOPE)
endif()

# Collect all exported pip requirements files, from this package and all dependencies
execute_process(
COMMAND ${CATKIN_ENV} ${PYTHON_EXECUTABLE} ${catkin_virtualenv_CMAKE_DIR}/glob_requirements.py --package-name ${PROJECT_NAME}
OUTPUT_VARIABLE requirements_list
OUTPUT_STRIP_TRAILING_WHITESPACE
)

# Extra python 3 compatibility flags
if(${ARG_PYTHON3})
set(build_venv_extra "--python3")
set(PYTHON_VERSION_MAJOR 3)
list(APPEND requirements_list ${catkin_virtualenv_CMAKE_DIR}/python3_requirements.txt)
endif()

set(generated_requirements ${CMAKE_BINARY_DIR}/generated_requirements.txt)

# Trigger a re-configure if any requirements file changes
foreach(requirements_txt ${requirements_list})
# Trigger a re-configure if any requirements file changes
stamp(${requirements_txt})
message(STATUS "Including ${requirements_txt} in bundled virtualenv")
endforeach()
Expand All @@ -90,6 +74,7 @@ function(catkin_generate_virtualenv)
DEPENDS ${generated_requirements}
)

# Per-package virtualenv target
add_custom_target(${PROJECT_NAME}_generate_virtualenv ALL
DEPENDS ${CMAKE_BINARY_DIR}/${venv_dir}
DEPENDS ${venv_devel_dir}
Expand All @@ -103,4 +88,22 @@ function(catkin_generate_virtualenv)
install(FILES ${generated_requirements}
DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION})

if(NOSETESTS)
if(${ARG_PYTHON3})
find_program(nosetests NAMES
"nosetests${PYTHON_VERSION_MAJOR}"
"nosetests-${PYTHON_VERSION_MAJOR}"
"nosetests")
else()
set(nosetests ${NOSETESTS})
endif()

set(nosetests "${venv_devel_dir}/bin/python${PYTHON_VERSION_MAJOR} ${nosetests}")

# (pbovbel): NOSETESTS originally set by catkin here:
# <https://github.com/ros/catkin/blob/kinetic-devel/cmake/test/nosetests.cmake#L86>
message(STATUS "Using virtualenv to run Python nosetests: ${nosetests}")
set(NOSETESTS ${nosetests} PARENT_SCOPE)
endif()

endfunction()
3 changes: 3 additions & 0 deletions catkin_virtualenv/cmake/combine_requirements.py
Expand Up @@ -41,6 +41,9 @@ def combine_requirements(requirements_list, output_file):
combined_requirements[requirement.name] = combined_requirements[requirement.name] + requirement
except KeyError:
combined_requirements[requirement.name] = requirement
except requirements.ReqMergeException as e:
print("In files {}: {}".format(requirements_list, e), file=sys.stderr)
raise

for requirement in combined_requirements.values():
output_file.write("{}\n".format(requirement))
Expand Down
2 changes: 2 additions & 0 deletions catkin_virtualenv/cmake/python3_requirements.txt
@@ -0,0 +1,2 @@
rospkg==1.1.4
catkin-pkg==0.3.9
2 changes: 0 additions & 2 deletions test_catkin_virtualenv_py3/requirements.txt
@@ -1,3 +1 @@
wrapt==1.10.10
rospkg==1.1.4
catkin-pkg==0.3.9