From 0e05755031083646b5d7b05545869342b039d453 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Mon, 12 Aug 2024 10:19:51 -0500 Subject: [PATCH] Add an option to create arch specific, python version independent pkgs --- conda_build/build.py | 12 ++++++++---- conda_build/metadata.py | 17 +++++++++++++++++ conda_build/render.py | 4 +++- conda_build/utils.py | 2 ++ conda_build/windows.py | 2 +- 5 files changed, 31 insertions(+), 6 deletions(-) diff --git a/conda_build/build.py b/conda_build/build.py index 5d062f7720..f7503ef23d 100644 --- a/conda_build/build.py +++ b/conda_build/build.py @@ -1443,13 +1443,14 @@ def create_info_files(m, replacements, files, prefix): def get_short_path(m, target_file): + if m.python_version_independent: + if target_file.find("site-packages") >= 0: + return target_file[target_file.find("site-packages") :] if m.noarch == "python": entry_point_script_names = get_entry_point_script_names( m.get_value("build/entry_points") ) - if target_file.find("site-packages") >= 0: - return target_file[target_file.find("site-packages") :] - elif target_file.startswith("bin") and ( + if target_file.startswith("bin") and ( target_file not in entry_point_script_names ): return target_file.replace("bin", "python-scripts") @@ -1667,6 +1668,9 @@ def post_process_files(m: MetaData, initial_prefix_files): noarch_python.populate_files( m, pkg_files, host_prefix, entry_point_script_names ) + elif m.python_version_independent: + # For non noarch: python ones, we don't need to handle entry points in a special way. + noarch_python.populate_files(m, pkg_files, host_prefix, []) current_prefix_files = utils.prefix_files(prefix=host_prefix) new_files = current_prefix_files - initial_prefix_files @@ -3073,7 +3077,7 @@ def _set_env_variables_for_build(m, env): # locally, and if we don't, it's a problem. env["PIP_NO_INDEX"] = True - if m.noarch == "python": + if m.python_version_independent: env["PYTHONDONTWRITEBYTECODE"] = True # The stuff in replacements is not parsable in a shell script (or we need to escape it) diff --git a/conda_build/metadata.py b/conda_build/metadata.py index c254329d28..e395e87249 100644 --- a/conda_build/metadata.py +++ b/conda_build/metadata.py @@ -605,6 +605,7 @@ def parse(data, config, path=None): "script": list, "noarch": str, "noarch_python": bool, + "python_version_independent": bool, "has_prefix_files": None, "binary_has_prefix_files": None, "ignore_prefix_files": None, @@ -1811,6 +1812,10 @@ def info_index(self): build_noarch = self.get_value("build/noarch") if build_noarch: d["noarch"] = build_noarch + elif self.python_version_independent: + # This is a hack to make conda/mamba/micromamba compile the pure python files + # and for micromamba to move the files in site-packages to the correct dir. + d["noarch"] = "python" if self.is_app(): d.update(self.app_meta()) return d @@ -2291,6 +2296,14 @@ def copy(self: Self) -> MetaData: ) return new + @property + def python_version_independent(self): + return ( + self.get_value("build/python_version_independent") + or self.get_value("build/noarch") == "python" + or self.noarch_python + ) + @property def noarch(self): return self.get_value("build/noarch") @@ -2442,6 +2455,10 @@ def get_output_metadata(self, output): output_metadata.final = False output_metadata.noarch = output.get("noarch", False) output_metadata.noarch_python = output.get("noarch_python", False) + output_metadata.python_version_independent = ( + output.get("python_version_independent") + or output_metadata.noarch == "python" + ) # primarily for tests - make sure that we keep the platform consistent (setting noarch # would reset it) if ( diff --git a/conda_build/render.py b/conda_build/render.py index 0c80df0005..0af3808d26 100644 --- a/conda_build/render.py +++ b/conda_build/render.py @@ -209,7 +209,7 @@ def get_pin_from_build(m, dep, build_dep_versions): if ( version and dep_name in m.config.variant.get("pin_run_as_build", {}) - and not (dep_name == "python" and (m.noarch or m.noarch_python)) + and not (dep_name == "python" and m.python_version_independent) and dep_name in build_dep_versions ): pin_cfg = m.config.variant["pin_run_as_build"][dep_name] @@ -408,6 +408,8 @@ def get_upstream_pins(m: MetaData, precs, env): precs = [prec for prec in precs if prec.name in explicit_specs] ignore_pkgs_list = utils.ensure_list(m.get_value("build/ignore_run_exports_from")) + if m.python_version_independent and not m.noarch: + ignore_pkgs_list.append("python") ignore_list = utils.ensure_list(m.get_value("build/ignore_run_exports")) additional_specs = {} for prec in precs: diff --git a/conda_build/utils.py b/conda_build/utils.py index 4b5fdcc8d2..82dff139d2 100644 --- a/conda_build/utils.py +++ b/conda_build/utils.py @@ -1058,6 +1058,7 @@ def iter_entry_points(items): def create_entry_point(path, module, func, config): + """Creates an entry point for legacy noarch_python builds""" import_name = func.split(".")[0] pyscript = PY_TMPL % {"module": module, "func": func, "import_name": import_name} if on_win: @@ -1081,6 +1082,7 @@ def create_entry_point(path, module, func, config): def create_entry_points(items, config): + """Creates entry points for legacy noarch_python builds""" if not items: return bin_dir = join(config.host_prefix, bin_dirname) diff --git a/conda_build/windows.py b/conda_build/windows.py index 8643431a5b..7ae9e560b4 100644 --- a/conda_build/windows.py +++ b/conda_build/windows.py @@ -246,7 +246,7 @@ def build_vcvarsall_cmd(cmd, arch=arch_selector): def write_build_scripts(m, env, bld_bat): env_script = join(m.config.work_dir, "build_env_setup.bat") - if m.noarch == "python": + if m.python_version_independent: env["PYTHONDONTWRITEBYTECODE"] = True import codecs