From 868f11d49ec1e9f8e5282d69b94c6c8a95b09209 Mon Sep 17 00:00:00 2001 From: Silvio Date: Tue, 12 Apr 2022 17:42:08 +0200 Subject: [PATCH] Add support for generating conda packages for pure_python packages --- cmake/RobSupPurePythonYCMEPHelper.cmake | 4 ++ ...tologySuperbuildGenerateCondaRecipes.cmake | 7 +++ .../bld.bat | 0 .../build.sh | 0 .../meta.yaml | 0 conda/pure_python_recipe_template/meta.yaml | 35 +++++++++++++++ ...enerate_conda_recipes_from_metametadata.py | 44 +++++++++++++------ 7 files changed, 77 insertions(+), 13 deletions(-) rename conda/{recipe_template => cmake_recipe_template}/bld.bat (100%) rename conda/{recipe_template => cmake_recipe_template}/build.sh (100%) rename conda/{recipe_template => cmake_recipe_template}/meta.yaml (100%) create mode 100644 conda/pure_python_recipe_template/meta.yaml diff --git a/cmake/RobSupPurePythonYCMEPHelper.cmake b/cmake/RobSupPurePythonYCMEPHelper.cmake index 7bd7da102..93572b338 100644 --- a/cmake/RobSupPurePythonYCMEPHelper.cmake +++ b/cmake/RobSupPurePythonYCMEPHelper.cmake @@ -50,4 +50,8 @@ function(ROB_SUP_PURE_PYTHON_YCM_EP_HELPER _name) CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND ${Python3_EXECUTABLE} -m pip install --upgrade --no-deps --target=${YCM_EP_INSTALL_DIR}/${ROBSUB_PYTHON_INSTALL_DIR} -VV ) + + # Set this variable so that RobotologySuperbuildGenerateCondaRecipes.cmake pass this information to the + # Python scripts that generates the conda recipes + set(${_name}_CONDA_BUILD_TYPE "pure_python") endfunction() diff --git a/conda/cmake/RobotologySuperbuildGenerateCondaRecipes.cmake b/conda/cmake/RobotologySuperbuildGenerateCondaRecipes.cmake index 032505239..f51506e25 100644 --- a/conda/cmake/RobotologySuperbuildGenerateCondaRecipes.cmake +++ b/conda/cmake/RobotologySuperbuildGenerateCondaRecipes.cmake @@ -74,6 +74,11 @@ macro(generate_metametadata_file) set(${_cmake_pkg}_CONDA_VERSION ${${_cmake_pkg}_CONDA_TAG}) endif() + # If the build_type is not defined, it is assumed to be cmake + if(NOT DEFINED ${_cmake_pkg}_CONDA_BUILD_TYPE) + set(${_cmake_pkg}_CONDA_BUILD_TYPE "cmake") + endif() + # If a package is already available in conda-forge, we use # that one by defining appropriately the <_cmake_pkg>_CONDA_PACKAGE_NAME @@ -113,11 +118,13 @@ macro(generate_metametadata_file) string(APPEND metametadata_file_contents " github_repo: ${${_cmake_pkg}_CONDA_GIHUB_REPO}\n") string(APPEND metametadata_file_contents " github_tag: ${${_cmake_pkg}_CONDA_TAG}\n") string(APPEND metametadata_file_contents " conda_build_number: ${CONDA_BUILD_NUMBER}\n") + string(APPEND metametadata_file_contents " build_type: ${${_cmake_pkg}_CONDA_BUILD_TYPE}\n") if(_YH_${_cmake_pkg}_SOURCE_SUBDIR) string(APPEND metametadata_file_contents " source_subdir: ${_YH_${_cmake_pkg}_SOURCE_SUBDIR}\n") endif() + if(NOT "${${_cmake_pkg}_CONDA_CMAKE_ARGS}" STREQUAL "") string(APPEND metametadata_file_contents " cmake_args:\n") foreach(_cmake_arg IN LISTS ${_cmake_pkg}_CONDA_CMAKE_ARGS) diff --git a/conda/recipe_template/bld.bat b/conda/cmake_recipe_template/bld.bat similarity index 100% rename from conda/recipe_template/bld.bat rename to conda/cmake_recipe_template/bld.bat diff --git a/conda/recipe_template/build.sh b/conda/cmake_recipe_template/build.sh similarity index 100% rename from conda/recipe_template/build.sh rename to conda/cmake_recipe_template/build.sh diff --git a/conda/recipe_template/meta.yaml b/conda/cmake_recipe_template/meta.yaml similarity index 100% rename from conda/recipe_template/meta.yaml rename to conda/cmake_recipe_template/meta.yaml diff --git a/conda/pure_python_recipe_template/meta.yaml b/conda/pure_python_recipe_template/meta.yaml new file mode 100644 index 000000000..251ddc01f --- /dev/null +++ b/conda/pure_python_recipe_template/meta.yaml @@ -0,0 +1,35 @@ +{{ '{% set name =' }} "{{ name }}" {{ '%}' }} + +package: +{% raw %} name: {{ name }} {% endraw %} + version: "{{ version.replace("v","") }}" + +source: + git_url: https://github.com/{{ github_repo }}.git + git_rev: {{ github_tag }} + +build: + number: {{ conda_build_number }} + script: {{ PYTHON }} -m pip install . --no-deps -vv + +requirements: + build: + + host: + - python + - pip +{% for dep in dependencies %} - {{ dep }} +{% endfor %} + run: + - python +{% for dep in dependencies %} - {{ dep }} +{% endfor %} + +test: + commands: + - pip check + requires: + - pip + +about: + home: https://github.com/{{ github_repo }} diff --git a/conda/python/generate_conda_recipes_from_metametadata.py b/conda/python/generate_conda_recipes_from_metametadata.py index dc6c62a3f..4e3d705b5 100644 --- a/conda/python/generate_conda_recipes_from_metametadata.py +++ b/conda/python/generate_conda_recipes_from_metametadata.py @@ -126,17 +126,26 @@ def main(): parser.add_argument('--generate_distro_metapackages', action='store_true', help="if passed also generates the recipes for the robotology-distro and robotology-distro-all metapackages ") args = parser.parse_args() - # Get recipe templates - recipe_template_dir = os.path.realpath(os.path.dirname(os.path.abspath(__file__)) + "/../recipe_template"); - recipe_template_files = [f for f in os.listdir(recipe_template_dir) if os.path.isfile(os.path.join(recipe_template_dir, f))] + # Get cmake recipe template fles + cmake_recipe_template_dir = os.path.realpath(os.path.dirname(os.path.abspath(__file__)) + "/../cmake_recipe_template"); + cmake_recipe_template_files = [f for f in os.listdir(cmake_recipe_template_dir) if os.path.isfile(os.path.join(cmake_recipe_template_dir, f))] + cmake_recipe_template_file_loader = jinja2.FileSystemLoader(cmake_recipe_template_dir) + cmake_recipe_template_env = jinja2.Environment(loader=cmake_recipe_template_file_loader) + + # Get pure_python recipe template fles + pure_python_recipe_template_dir = os.path.realpath(os.path.dirname(os.path.abspath(__file__)) + "/../pure_python_recipe_template"); + pure_python_recipe_template_files = [f for f in os.listdir(pure_python_recipe_template_dir) if os.path.isfile(os.path.join(pure_python_recipe_template_dir, f))] + pure_python_recipe_template_file_loader = jinja2.FileSystemLoader(pure_python_recipe_template_dir) + pure_python_recipe_template_env = jinja2.Environment(loader=pure_python_recipe_template_file_loader) # Get multisheller scripts multisheller_scripts_dir = os.path.realpath(os.path.dirname(os.path.abspath(__file__)) + "/../multisheller"); multisheller_scripts = [f for f in os.listdir(multisheller_scripts_dir) if os.path.isfile(os.path.join(multisheller_scripts_dir, f))] - # Prepare Jinja templates - file_loader = jinja2.FileSystemLoader(recipe_template_dir) - env = jinja2.Environment(loader=file_loader) + + + + # Load metametadata metametadata = yaml.load(open(args.metametadata), Loader=yaml.FullLoader) @@ -165,13 +174,22 @@ def main(): else: pkg_info['copy_activation_scripts'] = False - # Generate recipe - for template_file in recipe_template_files: - template = env.get_template(template_file) - template_output = template.render(pkg_info) - with open(os.path.join(recipe_dir, template_file), 'w') as f: - f.write(template_output) - + # Generate recipe if the package is installed via cmake + if pkg_info['build_type'] == "cmake": + for template_file in cmake_recipe_template_files: + template = cmake_recipe_template_env.get_template(template_file) + template_output = template.render(pkg_info) + with open(os.path.join(recipe_dir, template_file), 'w') as f: + f.write(template_output) + + # Generate recipe if the package is installed via cmake + if pkg_info['build_type'] == "pure_python": + for template_file in pure_python_recipe_template_files: + template = pure_python_recipe_template_env.get_template(template_file) + template_output = template.render(pkg_info) + with open(os.path.join(recipe_dir, template_file), 'w') as f: + f.write(template_output) + # If requested also generate recipes for distro metapackages if args.generate_distro_metapackages: recipe_metapackages_template_dir = os.path.realpath(os.path.dirname(os.path.abspath(__file__)) + "/../metapackages_recipes_template");