Skip to content

Commit

Permalink
Add base requirements file for python3 catkin; include extra data abo…
Browse files Browse the repository at this point in the history
…ut requirement merge failure
  • Loading branch information
paulbovbel committed Nov 30, 2017
1 parent c074275 commit 0c86b5c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 25 deletions.
49 changes: 26 additions & 23 deletions catkin_virtualenv/cmake/catkin_generate_virtualenv.cmake
Expand Up @@ -33,36 +33,20 @@ 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)

foreach(requirements_txt ${requirements_list})
Expand Down Expand Up @@ -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

0 comments on commit 0c86b5c

Please sign in to comment.