diff --git a/drivers/usb/tests/TESTS/usb_device/README.md b/drivers/usb/tests/TESTS/usb_device/README.md index 6af69a00c10..74c7b7d58c5 100644 --- a/drivers/usb/tests/TESTS/usb_device/README.md +++ b/drivers/usb/tests/TESTS/usb_device/README.md @@ -1,12 +1,8 @@ # Testing the Mbed OS USB device ## Setup -Before running tests, please make sure to install all the -required Python modules. - -``` -pip install -r mbed-os/tools/requirements-ci-build.txt -``` +> [!NOTE] +> all required Python modules are instaled into the Python virtual enviroment (venv) automatically with first build of Greentea. Additional, platform-specific setup is described below. See also [Known issues](#known-issues). diff --git a/tools/cmake/mbed_python_interpreter.cmake b/tools/cmake/mbed_python_interpreter.cmake index 1d563c3ac28..6c5e2a5dd33 100644 --- a/tools/cmake/mbed_python_interpreter.cmake +++ b/tools/cmake/mbed_python_interpreter.cmake @@ -19,6 +19,9 @@ if(MBED_CREATE_PYTHON_VENV) set(VENV_STAMP_FILE ${MBED_VENV_LOCATION}/mbed-venv.stamp) set(MBED_PYPROJECT_TOML_LOCATION "${MBED_CE_TOOLS_BASE_DIR}/pyproject.toml") + # a separate stamp file to track whether greentea dependencies have been installed + set(GT_STAMP_FILE ${MBED_VENV_LOCATION}/mbed-gt.stamp) + # Make it so modifying pyproject.toml will trigger a reconfigure set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${MBED_PYPROJECT_TOML_LOCATION}) @@ -66,6 +69,11 @@ if(MBED_CREATE_PYTHON_VENV) set(NEED_TO_INSTALL_PACKAGES TRUE) endif() + # If greentea tests are being built, we need to ensure greentea dependencies are installed + if(MBED_BUILD_GREENTEA_TESTS AND NOT EXISTS "${GT_STAMP_FILE}") + set(NEED_TO_INSTALL_PACKAGES TRUE) + endif() + if(NEED_TO_CREATE_VENV) # Create venv. # Using approach from here: https://discourse.cmake.org/t/possible-to-create-a-python-virtual-env-from-cmake-and-then-find-it-with-findpython3/1132/2 @@ -92,13 +100,29 @@ if(MBED_CREATE_PYTHON_VENV) COMMAND ${Python3_EXECUTABLE} -m pip install --upgrade pip COMMAND_ERROR_IS_FATAL ANY ) - execute_process( - COMMAND ${Python3_EXECUTABLE} -m pip install -e ${MBED_CE_TOOLS_BASE_DIR} - COMMAND_ERROR_IS_FATAL ANY - ) + + # + if(MBED_BUILD_GREENTEA_TESTS) + # Enable the extra dependencies for the GT + execute_process( + COMMAND ${Python3_EXECUTABLE} -m pip install -e "${MBED_CE_TOOLS_BASE_DIR}[greentea]" + COMMAND_ERROR_IS_FATAL ANY + ) + else() + # The dependencies for regular build + execute_process( + COMMAND ${Python3_EXECUTABLE} -m pip install -e "${MBED_CE_TOOLS_BASE_DIR}" + COMMAND_ERROR_IS_FATAL ANY + ) + endif() message(STATUS "Mbed: venv created successfully") file(TOUCH ${VENV_STAMP_FILE}) + if(MBED_BUILD_GREENTEA_TESTS) + # If greentea tests are being built, we need create a greentea stamp file + file(TOUCH ${GT_STAMP_FILE}) + endif() + endif() # When using the venv, scripts will always be installed to the directory where Python itself is installed @@ -175,4 +199,4 @@ function(mbed_check_or_install_python_package FOUND_VAR PACKAGE_IMPORT_NAME PACK message(WARNING "Mbed: ${PACKAGE_IMPORT_NAME} cannot be installed because the Mbed virtualenv is not being used. Please install ${PACKAGE_INSTALL_CONSTRAINT} into Mbed's Python interpeter manually.") endif() endif() -endfunction(mbed_check_or_install_python_package) \ No newline at end of file +endfunction(mbed_check_or_install_python_package) diff --git a/tools/pyproject.toml b/tools/pyproject.toml index 0087c13fcb0..8635a110000 100644 --- a/tools/pyproject.toml +++ b/tools/pyproject.toml @@ -71,6 +71,13 @@ unit-tests = [ "beautifulsoup4", "lxml" ] +greentea = [ + ## Additional requirements to install into the Mbed environment when running Greentea tests + # For USB Device host tests + "hidapi>=0.7.99", + "pyusb>=1.2.0", + "wmi>=1.5; platform_system == 'Windows'", +] [tool.hatch.build.targets.wheel] packages = [ @@ -88,4 +95,4 @@ mbedhtrun = "mbed_host_tests.mbedhtrun:main" mbedls = "mbed_lstools.main:mbedls_main" mbed-tools = "mbed_tools.cli.main:cli" memap = "memap.memap:main" -ambiq_svl = "ambiq_svl.svl:cli" \ No newline at end of file +ambiq_svl = "ambiq_svl.svl:cli" diff --git a/tools/requirements-greentea.txt b/tools/requirements-greentea.txt deleted file mode 100644 index b4ae78d2285..00000000000 --- a/tools/requirements-greentea.txt +++ /dev/null @@ -1,6 +0,0 @@ -## Additional requirements to install into the Mbed environment when running Greentea tests - -# For USB Device host tests -hidapi>=0.7.99 -pyusb>=1.2.0 -wmi>=1.5; platform_system == "Windows" \ No newline at end of file