From 29f4aada6cf416eddd8e44e252270da77b40f49b Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Sun, 20 Aug 2023 12:31:15 +0200 Subject: [PATCH] minimal runner conf and profiles Contributes to CURA-10855 --- conan.conf | 15 --- generators/GitHubActionsBuildEnv.py | 30 ----- generators/GitHubActionsRunEnv.py | 30 ----- generators/PyCharmRunEnv.py | 62 ---------- generators/VirtualPythonEnv.py | 174 ---------------------------- global.conf | 11 +- profiles/cura.jinja | 20 ---- profiles/cura_build.jinja | 15 --- remotes.txt | 2 - 9 files changed, 1 insertion(+), 358 deletions(-) delete mode 100644 generators/GitHubActionsBuildEnv.py delete mode 100644 generators/GitHubActionsRunEnv.py delete mode 100644 generators/PyCharmRunEnv.py delete mode 100644 generators/VirtualPythonEnv.py delete mode 100644 profiles/cura.jinja delete mode 100644 profiles/cura_build.jinja delete mode 100644 remotes.txt diff --git a/conan.conf b/conan.conf index 0ab8d76..bff5cf4 100644 --- a/conan.conf +++ b/conan.conf @@ -1,24 +1,9 @@ [log] -run_to_output = True # environment CONAN_LOG_RUN_TO_OUTPUT -run_to_file = False # environment CONAN_LOG_RUN_TO_FILE -level = warn # environment CONAN_LOGGING_LEVEL -print_run_commands = True # environment CONAN_PRINT_RUN_COMMANDS [general] -default_profile = default -compression_level = 9 # environment CONAN_COMPRESSION_LEVEL -sysrequires_sudo = True # environment CONAN_SYSREQUIRES_SUDO -request_timeout = 60 # environment CONAN_REQUEST_TIMEOUT (seconds) -default_package_id_mode = full_package_mode # environment CONAN_DEFAULT_PACKAGE_ID_MODE -revisions_enabled = True -scm_to_conandata = True -use_always_short_paths = True -config_install_interval = 12h [storage] -path = ./data [proxies] [hooks] -attribute_checker diff --git a/generators/GitHubActionsBuildEnv.py b/generators/GitHubActionsBuildEnv.py deleted file mode 100644 index d7b7305..0000000 --- a/generators/GitHubActionsBuildEnv.py +++ /dev/null @@ -1,30 +0,0 @@ -from pathlib import Path - -from jinja2 import Template - -from conan.tools.env import VirtualBuildEnv -from conans.model import Generator - - -class GitHubActionsBuildEnv(Generator): - - @property - def filename(self): - filepath = str(Path(self.conanfile.generators_folder).joinpath("activate_github_actions_buildenv")) - if self.conanfile.settings.get_safe("os") == "Windows": - if self.conanfile.conf.get("tools.env.virtualenv:powershell", check_type = bool): - filepath += ".ps1" - else: - filepath += ".bat" - else: - filepath += ".sh" - return filepath - - @property - def content(self): - template = Template("""{% for k, v in envvars.items() %}echo "{{ k }}={{ v }}" >> ${{ env_prefix }}GITHUB_ENV\n{% endfor %}""") - build_env = VirtualBuildEnv(self.conanfile) - env = build_env.environment() - envvars = env.vars(self.conanfile, scope = "build") - env_prefix = "Env:" if self.conanfile.settings.os == "Windows" else "" - return template.render(envvars = envvars, env_prefix = env_prefix) diff --git a/generators/GitHubActionsRunEnv.py b/generators/GitHubActionsRunEnv.py deleted file mode 100644 index b79a130..0000000 --- a/generators/GitHubActionsRunEnv.py +++ /dev/null @@ -1,30 +0,0 @@ -from pathlib import Path - -from jinja2 import Template - -from conan.tools.env import VirtualRunEnv -from conans.model import Generator - - -class GitHubActionsRunEnv(Generator): - - @property - def filename(self): - filepath = str(Path(self.conanfile.generators_folder).joinpath("activate_github_actions_runenv")) - if self.conanfile.settings.get_safe("os") == "Windows": - if self.conanfile.conf.get("tools.env.virtualenv:powershell", check_type = bool): - filepath += ".ps1" - else: - filepath += ".bat" - else: - filepath += ".sh" - return filepath - - @property - def content(self): - template = Template("""{% for k, v in envvars.items() %}echo "{{ k }}={{ v }}" >> ${{ env_prefix }}GITHUB_ENV\n{% endfor %}""") - build_env = VirtualRunEnv(self.conanfile) - env = build_env.environment() - envvars = env.vars(self.conanfile, scope = "run") - env_prefix = "Env:" if self.conanfile.settings.os == "Windows" else "" - return template.render(envvars = envvars, env_prefix = env_prefix) diff --git a/generators/PyCharmRunEnv.py b/generators/PyCharmRunEnv.py deleted file mode 100644 index 14f5570..0000000 --- a/generators/PyCharmRunEnv.py +++ /dev/null @@ -1,62 +0,0 @@ -from pathlib import Path -from typing import Dict - -from conans import tools -from conans.model import Generator -from jinja2 import Template -from conan.tools.env.virtualrunenv import VirtualRunEnv - -class PyCharmRunEnv(Generator): - @property - def _base_dir(self): - return Path("$PROJECT_DIR$", "venv") - - @property - def _py_interp(self): - if self.settings.os == "Windows": - py_interp = Path(*[f'"{p}"' if " " in p else p for p in self._base_dir.joinpath("Scripts", "python.exe").parts]) - return py_interp - return self._base_dir.joinpath("bin", "python") - - @property - def _site_packages(self): - if self.settings.os == "Windows": - return self._base_dir.joinpath("Lib", "site-packages") - py_version = tools.Version(self.conanfile.deps_cpp_info["cpython"].version) - return self._base_dir.joinpath("lib", f"python{py_version.major}.{py_version.minor}", "site-packages") - - @property - def filename(self): - pass - - @property - def content(self) -> Dict[str, str]: - # Mapping of file names -> files - run_configurations: Dict[str, str] = {} - - if not hasattr(self.conanfile, "_pycharm_targets"): - # There are no _pycharm_targets in the conanfile for the package using this generator. - return run_configurations - - # Collect environment variables for use in the template - env = VirtualRunEnv(self.conanfile).environment() - env.prepend_path("PYTHONPATH", str(self._site_packages)) - - if hasattr(self.conanfile, f"_{self.conanfile.name}_run_env"): - project_run_env = getattr(self.conanfile, f"_{self.conanfile.name}_run_env") - if project_run_env: - env.compose_env(project_run_env) # TODO: Add logic for dependencies - - # Create Pycharm run configuration from template for each target - for target in self.conanfile._pycharm_targets: - target["env_vars"] = env.vars(self.conanfile, scope="run") - target["sdk_path"] = str(self._py_interp) - if "parameters" not in target: - target["parameters"] = "" - - with open(target["jinja_path"], "r") as f: - template = Template(f.read()) - run_configuration = template.render(target) - run_configurations[str(Path(self.conanfile.source_folder).joinpath(".run", f"{target['name']}.run.xml"))] = run_configuration - - return run_configurations diff --git a/generators/VirtualPythonEnv.py b/generators/VirtualPythonEnv.py deleted file mode 100644 index c270162..0000000 --- a/generators/VirtualPythonEnv.py +++ /dev/null @@ -1,174 +0,0 @@ -import sys - -import os -from io import StringIO - -from pathlib import Path - -from jinja2 import Template - -from conan import ConanFile -from conan.tools.env import VirtualRunEnv -from conans.model import Generator -from conans.errors import ConanException - - -class VirtualPythonEnv(Generator): - - @property - def _script_ext(self): - if self.conanfile.settings.get_safe("os") == "Windows": - return ".ps1" - return ".sh" - - @property - def _venv_path(self): - if self.settings.os == "Windows": - return "Scripts" - return "bin" - - @property - def filename(self): - pass - - @property - def content(self): - conanfile: ConanFile = self.conanfile - python_interpreter = Path(self.conanfile.deps_user_info["cpython"].python) - - # When on Windows execute as Windows Path - if conanfile.settings.os == "Windows": - python_interpreter = Path(*[f'"{p}"' if " " in p else p for p in python_interpreter.parts]) - - # Create the virtual environment - print(f"Creating virtual environment in {conanfile.install_folder}") - print(f"Creating virtual environment in {conanfile.build_folder}") - if conanfile.in_local_cache: - venv_folder = conanfile.install_folder - else: - venv_folder = conanfile.build_folder if conanfile.build_folder else Path(os.getcwd(), "venv") - - conanfile.output.info(f"Creating virtual environment in {venv_folder}") - conanfile.run(f"""{python_interpreter} -m venv {venv_folder}""", run_environment = True, env = "conanrun") - - # Make sure there executable is named the same on all three OSes this allows it to be called with `python` - # simplifying GH Actions steps - if conanfile.settings.os != "Windows": - python_venv_interpreter = Path(venv_folder, self._venv_path, "python") - if not python_venv_interpreter.exists(): - python_venv_interpreter.hardlink_to( - Path(venv_folder, self._venv_path, Path(sys.executable).stem + Path(sys.executable).suffix)) - else: - python_venv_interpreter = Path(venv_folder, self._venv_path, Path(sys.executable).stem + Path(sys.executable).suffix) - - if not python_venv_interpreter.exists(): - raise ConanException(f"Virtual environment Python interpreter not found at: {python_venv_interpreter}") - if conanfile.settings.os == "Windows": - python_venv_interpreter = Path(*[f'"{p}"' if " " in p else p for p in python_venv_interpreter.parts]) - - buffer = StringIO() - outer = '"' if conanfile.settings.os == "Windows" else "'" - inner = "'" if conanfile.settings.os == "Windows" else '"' - conanfile.run(f"{python_venv_interpreter} -c {outer}import sysconfig; print(sysconfig.get_path({inner}purelib{inner})){outer}", - env = "conanrun", - output = buffer) - pythonpath = buffer.getvalue().splitlines()[-1] - - run_env = VirtualRunEnv(conanfile) - env = run_env.environment() - - if hasattr(self.conanfile, f"_{self.conanfile.name}_run_env"): - project_run_env = getattr(self.conanfile, f"_{self.conanfile.name}_run_env") - if project_run_env: - env.compose_env(project_run_env) # TODO: Add logic for dependencies - - env.define_path("VIRTUAL_ENV", venv_folder) - env.prepend_path("PATH", os.path.join(venv_folder, self._venv_path)) - env.prepend_path("LD_LIBRARY_PATH", os.path.join(venv_folder, self._venv_path)) - env.prepend_path("DYLD_LYBRARY_PATH", os.path.join(venv_folder, self._venv_path)) - env.prepend_path("PYTHONPATH", pythonpath) - env.unset("PYTHONHOME") - - # Install some base_packages - conanfile.run(f"""{python_venv_interpreter} -m pip install wheel setuptools""", run_environment = True, env = "conanrun") - - # Install pip_requirements from dependencies - for dep_name in reversed(conanfile.deps_user_info): - dep_user_info = conanfile.deps_user_info[dep_name] - if len(dep_user_info.vars) == 0: - continue - pip_req_paths = [conanfile.deps_cpp_info[dep_name].res_paths[i] for i, req_path in - enumerate(conanfile.deps_cpp_info[dep_name].resdirs) if req_path.endswith("pip_requirements")] - if len(pip_req_paths) != 1: - continue - pip_req_base_path = Path(pip_req_paths[0]) - if hasattr(dep_user_info, "pip_requirements"): - req_txt = pip_req_base_path.joinpath(dep_user_info.pip_requirements) - if req_txt.exists(): - conanfile.run(f"{python_venv_interpreter} -m pip install -r {req_txt} --upgrade", run_environment = True, - env = "conanrun") - conanfile.output.success(f"Dependency {dep_name} specifies pip_requirements in user_info installed!") - else: - conanfile.output.warn(f"Dependency {dep_name} specifies pip_requirements in user_info but {req_txt} can't be found!") - - if hasattr(dep_user_info, "pip_requirements_git"): - req_txt = pip_req_base_path.joinpath(dep_user_info.pip_requirements_git) - if req_txt.exists(): - conanfile.run(f"{python_venv_interpreter} -m pip install -r {req_txt} --upgrade", run_environment = True, - env = "conanrun") - conanfile.output.success(f"Dependency {dep_name} specifies pip_requirements_git in user_info installed!") - else: - conanfile.output.warn( - f"Dependency {dep_name} specifies pip_requirements_git in user_info but {req_txt} can't be found!") - - if hasattr(dep_user_info, "pip_requirements_build"): - req_txt = pip_req_base_path.joinpath(dep_user_info.pip_requirements_build) - if req_txt.exists(): - conanfile.run(f"{python_venv_interpreter} -m pip install -r {req_txt} --upgrade", run_environment = True, - env = "conanrun") - conanfile.output.success(f"Dependency {dep_name} specifies pip_requirements_build in user_info installed!") - else: - conanfile.output.warn( - f"Dependency {dep_name} specifies pip_requirements_build in user_info but {req_txt} can't be found!") - - if not conanfile.in_local_cache and hasattr(conanfile, "requirements_txts"): - # Install the Python requirements of the current conanfile requirements*.txt - pip_req_base_path = Path(conanfile.source_folder) - - for req_path in sorted(conanfile.requirements_txts, reverse = True): - req_txt = pip_req_base_path.joinpath(req_path) - if req_txt.exists(): - conanfile.run(f"{python_venv_interpreter} -m pip install -r {req_txt} --upgrade", run_environment = True, - env = "conanrun") - conanfile.output.success(f"Requirements file {req_txt} installed!") - else: - conanfile.output.warn(f"Requirements file {req_txt} can't be found!") - - # Add all dlls/dylibs/so found in site-packages to the PATH, DYLD_LIBRARY_PATH and LD_LIBRARY_PATH - dll_paths = list({ dll.parent for dll in Path(pythonpath).glob("**/*.dll") }) - for dll_path in dll_paths: - env.append_path("PATH", str(dll_path)) - - dylib_paths = list({ dylib.parent for dylib in Path(pythonpath).glob("**/*.dylib") }) - for dylib_path in dylib_paths: - env.append_path("DYLD_LIBRARY_PATH", str(dylib_path)) - - so_paths = list({ so.parent for so in Path(pythonpath).glob("**/*.dylib") }) - for so_path in so_paths: - env.append_path("LD_LIBRARY_PATH", str(so_path)) - - full_envvars = env.vars(conanfile, scope = "conanrun") - - # Generate the Python Virtual Environment Script - full_envvars.save_sh(Path(venv_folder, self._venv_path, "activate")) - full_envvars.save_bat(Path(venv_folder, self._venv_path, "activate.bat")) - full_envvars.save_ps1(Path(venv_folder, self._venv_path, "Activate.ps1")) - - # Generate the GitHub Action activation script - env_prefix = "Env:" if conanfile.settings.os == "Windows" else "" - activate_github_actions_buildenv = Template(r"""{% for var, value in envvars.items() %}echo "{{ var }}={{ value }}" >> ${{ env_prefix }}GITHUB_ENV -{% endfor %}""").render(envvars = full_envvars, env_prefix = env_prefix) - - return { - str(Path(venv_folder, self._venv_path, f"activate_github_actions_env{self._script_ext}")): activate_github_actions_buildenv - } diff --git a/global.conf b/global.conf index c945886..ef4dcdb 100644 --- a/global.conf +++ b/global.conf @@ -1,10 +1 @@ -core:default_profile = cura.jinja -core:default_build_profile = cura_build.jinja -tools.cmake.cmaketoolchain:generator = Ninja -tools.env.virtualenv:auto_use = True -tools.gnu:define_libcxx11_abi = True - -# FIXME: Needs to be commented out for OpenSSL to work but if we wan't to create ps1 scripts it needs to be set to True -# Otherwise .bat files are created. Maybe we should define this on a recipe basis: -# -#{% if platform.system() == 'Windows' %}tools.env.virtualenv:powershell=True{% endif %} +core:default_profile = runner.jinja diff --git a/profiles/cura.jinja b/profiles/cura.jinja deleted file mode 100644 index 9744cca..0000000 --- a/profiles/cura.jinja +++ /dev/null @@ -1,20 +0,0 @@ -include(default) - -[build_requires] - -[settings] -compiler.cppstd=17 -curaengine:compiler.cppstd=20 -curaengine*:compiler.cppstd=20 -curaengine_plugin_infill_generate:compiler.cppstd=20 -scripta:compiler.cppstd=20 -umspatial*:compiler.cppstd=20 - -{% if compiler == 'gcc' %}compiler.libcxx=libstdc++11 -{% elif compiler == 'apple-clang' %}compiler.libcxx=libc++ -{% elif compiler == 'Visual Studio' %}compiler.toolset=v143 -{% endif %} -[options] -[env] - -[conf] diff --git a/profiles/cura_build.jinja b/profiles/cura_build.jinja deleted file mode 100644 index c747fd0..0000000 --- a/profiles/cura_build.jinja +++ /dev/null @@ -1,15 +0,0 @@ -include(default) - -[build_requires] - -[settings] -compiler.cppstd=17 -{% if compiler == 'gcc' %}compiler.libcxx=libstdc++11 -{% elif compiler == 'apple-clang' %}compiler.libcxx=libc++ -{% elif compiler == 'Visual Studio' %}compiler.toolset=v143 -{% endif %} -[options] - -[env] - -[conf] diff --git a/remotes.txt b/remotes.txt deleted file mode 100644 index d8875d3..0000000 --- a/remotes.txt +++ /dev/null @@ -1,2 +0,0 @@ -cura https://ultimaker.jfrog.io/artifactory/api/conan/cura-internal True -conan-center https://center.conan.io True