Skip to content

Commit

Permalink
Add support for generating conda packages for pure_python packages
Browse files Browse the repository at this point in the history
  • Loading branch information
traversaro committed Apr 12, 2022
1 parent a83dd7c commit 868f11d
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 13 deletions.
4 changes: 4 additions & 0 deletions cmake/RobSupPurePythonYCMEPHelper.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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 <SOURCE_DIR>)

# 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()
7 changes: 7 additions & 0 deletions conda/cmake/RobotologySuperbuildGenerateCondaRecipes.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
35 changes: 35 additions & 0 deletions conda/pure_python_recipe_template/meta.yaml
Original file line number Diff line number Diff line change
@@ -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 }}
44 changes: 31 additions & 13 deletions conda/python/generate_conda_recipes_from_metametadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 868f11d

Please sign in to comment.