From afe8ac7d2516ee707d84b98bc61bc79a41b1bf1b Mon Sep 17 00:00:00 2001 From: jaimergp Date: Thu, 20 Jun 2024 17:00:45 +0200 Subject: [PATCH 1/5] Draft support for the napari/pins channel --- build_installers.py | 52 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/build_installers.py b/build_installers.py index 75b2d67e..22767dbe 100644 --- a/build_installers.py +++ b/build_installers.py @@ -170,16 +170,18 @@ def _generate_background_images(installer_type, outpath="./", napari_repo=HERE): atexit.register(os.unlink, output) -def _get_condarc(): +def _get_base_condarc(): # we need defaults for tensorflow and others on windows only defaults = "- defaults" if WINDOWS else "" prompt = "[napari]({default_env}) " contents = dedent( f""" channels: #!final - - napari - conda-forge {defaults} + channel_alias: https://github.com/napari/pins/releases/download #!final + custom_channels: #!final + - conda-forge: https://conda.anaconda.org repodata_fns: #!final - repodata.json auto_update_conda: false #!final @@ -195,6 +197,20 @@ def _get_condarc(): return f.name +def _get_napari_env_condarc(napari_version): + version_components = 3 if napari_version.startswith("0.4.") else 2 + channel_v = ".".join(napari_version.split(".")[:version_components]) + contents = dedent( + f""" + channels: #!final + - napari-v{channel_v} + """ + ) + with NamedTemporaryFile(delete=False, mode="w+") as f: + f.write(contents) + return f.name + + def _get_conda_meta_state(): data = { "env_vars": { @@ -228,9 +244,19 @@ def _napari_env( pyside_version=PYSIDE_VER, extra_specs=None, ): + version_components = 3 if napari_version.startswith("0.4.") else 2 + channel_v = ".".join(napari_version.split(".")[:version_components]) return { "name": f"napari-{napari_version}", - # "channels": same as _base_env(), omit to inherit :) + "channels": [ + f"https://github.com/napari/pins/releases/download/napari-v{channel_v}", + ], + "channels_remap": [ + { + "src": f"https://github.com/napari/pins/releases/download/napari-v{channel_v}", + "dest": f"napari-v{napari_version}", + } + ], "specs": [ f"python={python_version}.*=*_cpython", f"napari={napari_version}", @@ -242,6 +268,7 @@ def _napari_env( "pip", ] + (extra_specs or []), + "menu_packages": ["napari-menu"], # "exclude": exclude, # TODO: not supported yet in constructor } @@ -251,9 +278,15 @@ def _definitions(version=_version(), extra_specs=None, napari_repo=HERE): base_env = _base_env() napari_env = _napari_env(napari_version=version, extra_specs=extra_specs) empty_file = NamedTemporaryFile(delete=False) - condarc = _get_condarc() + base_condarc = _get_base_condarc() + napari_condarc = _get_napari_env_condarc(version) + napari_condarc_path = os.path.join("envs", napari_env["name"], ".condarc") env_state = _get_conda_meta_state() env_state_path = os.path.join("envs", napari_env["name"], "conda-meta", "state") + atexit.register(os.unlink, empty_file.name) + atexit.register(os.unlink, base_condarc) + atexit.register(os.unlink, napari_condarc) + atexit.register(os.unlink, env_state) definitions = { "name": APP, "company": "Napari", @@ -267,16 +300,14 @@ def _definitions(version=_version(), extra_specs=None, napari_repo=HERE): "license_file": os.path.join(resources, "bundle_license.rtf"), "specs": base_env["specs"], "extra_envs": { - napari_env["name"]: { - "specs": napari_env["specs"], - "menu_packages": ["napari-menu"], - }, + napari_env["name"]: {k: v for k, v in napari_env.items() if k != "name"}, }, "register_envs": False, "extra_files": [ {os.path.join(resources, "bundle_readme.md"): "README.txt"}, {empty_file.name: ".napari_is_bundled_constructor"}, - {condarc: ".condarc"}, + {base_condarc: ".condarc"}, + {napari_condarc: napari_condarc_path}, {env_state: env_state_path}, ], "build_outputs": [ @@ -351,9 +382,6 @@ def _definitions(version=_version(), extra_specs=None, napari_repo=HERE): ) atexit.register(os.unlink, "construct.yaml") - atexit.register(os.unlink, empty_file.name) - atexit.register(os.unlink, condarc) - atexit.register(os.unlink, env_state) return definitions From 8a7957b363618434ad233de3c8d0230ea354e9d7 Mon Sep 17 00:00:00 2001 From: jaimergp Date: Thu, 20 Jun 2024 17:23:00 +0200 Subject: [PATCH 2/5] quote URLs? --- build_installers.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build_installers.py b/build_installers.py index 22767dbe..513a5b89 100644 --- a/build_installers.py +++ b/build_installers.py @@ -249,11 +249,11 @@ def _napari_env( return { "name": f"napari-{napari_version}", "channels": [ - f"https://github.com/napari/pins/releases/download/napari-v{channel_v}", + f"'https://github.com/napari/pins/releases/download/napari-v{channel_v}'", ], "channels_remap": [ { - "src": f"https://github.com/napari/pins/releases/download/napari-v{channel_v}", + "src": f"'https://github.com/napari/pins/releases/download/napari-v{channel_v}'", "dest": f"napari-v{napari_version}", } ], From baf10daf5fdde0ff10088e3d7c6c70f9392aec43 Mon Sep 17 00:00:00 2001 From: jaimergp Date: Thu, 20 Jun 2024 17:54:07 +0200 Subject: [PATCH 3/5] Put channels_remap in the global level as a workaround --- build_installers.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/build_installers.py b/build_installers.py index 513a5b89..bbe75d45 100644 --- a/build_installers.py +++ b/build_installers.py @@ -249,13 +249,7 @@ def _napari_env( return { "name": f"napari-{napari_version}", "channels": [ - f"'https://github.com/napari/pins/releases/download/napari-v{channel_v}'", - ], - "channels_remap": [ - { - "src": f"'https://github.com/napari/pins/releases/download/napari-v{channel_v}'", - "dest": f"napari-v{napari_version}", - } + f"https://github.com/napari/pins/releases/download/napari-v{channel_v}", ], "specs": [ f"python={python_version}.*=*_cpython", @@ -283,6 +277,8 @@ def _definitions(version=_version(), extra_specs=None, napari_repo=HERE): napari_condarc_path = os.path.join("envs", napari_env["name"], ".condarc") env_state = _get_conda_meta_state() env_state_path = os.path.join("envs", napari_env["name"], "conda-meta", "state") + version_components = 3 if version.startswith("0.4.") else 2 + channel_v = ".".join(version.split(".")[:version_components]) atexit.register(os.unlink, empty_file.name) atexit.register(os.unlink, base_condarc) atexit.register(os.unlink, napari_condarc) @@ -294,6 +290,12 @@ def _definitions(version=_version(), extra_specs=None, napari_repo=HERE): "version": version.replace("+", "_"), "channels": base_env["channels"], "conda_default_channels": ["conda-forge"], + "channels_remap": [ + { + "src": f"https://github.com/napari/pins/releases/download/napari-v{channel_v}", + "dest": f"napari-v{version}", + } + ], "installer_filename": OUTPUT_FILENAME, "initialize_conda": False, "initialize_by_default": False, @@ -381,7 +383,7 @@ def _definitions(version=_version(), extra_specs=None, napari_repo=HERE): napari_repo=napari_repo, ) - atexit.register(os.unlink, "construct.yaml") + # atexit.register(os.unlink, "construct.yaml") return definitions From 5a5bd21c7e9c4a23d74c0de7d670fe089b1a1c2b Mon Sep 17 00:00:00 2001 From: jaimergp Date: Thu, 20 Jun 2024 18:03:01 +0200 Subject: [PATCH 4/5] fix dest too --- build_installers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build_installers.py b/build_installers.py index bbe75d45..c03484aa 100644 --- a/build_installers.py +++ b/build_installers.py @@ -293,7 +293,7 @@ def _definitions(version=_version(), extra_specs=None, napari_repo=HERE): "channels_remap": [ { "src": f"https://github.com/napari/pins/releases/download/napari-v{channel_v}", - "dest": f"napari-v{version}", + "dest": f"napari-v{channel_v}", } ], "installer_filename": OUTPUT_FILENAME, From 4cd9479c7552ddd59b45a545fc5bac96309503ed Mon Sep 17 00:00:00 2001 From: jaimergp Date: Fri, 21 Jun 2024 09:24:01 +0200 Subject: [PATCH 5/5] I think we don't need remaps --- build_installers.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/build_installers.py b/build_installers.py index c03484aa..d353c491 100644 --- a/build_installers.py +++ b/build_installers.py @@ -250,6 +250,7 @@ def _napari_env( "name": f"napari-{napari_version}", "channels": [ f"https://github.com/napari/pins/releases/download/napari-v{channel_v}", + "conda-forge", # temporary ], "specs": [ f"python={python_version}.*=*_cpython", @@ -277,8 +278,6 @@ def _definitions(version=_version(), extra_specs=None, napari_repo=HERE): napari_condarc_path = os.path.join("envs", napari_env["name"], ".condarc") env_state = _get_conda_meta_state() env_state_path = os.path.join("envs", napari_env["name"], "conda-meta", "state") - version_components = 3 if version.startswith("0.4.") else 2 - channel_v = ".".join(version.split(".")[:version_components]) atexit.register(os.unlink, empty_file.name) atexit.register(os.unlink, base_condarc) atexit.register(os.unlink, napari_condarc) @@ -290,12 +289,6 @@ def _definitions(version=_version(), extra_specs=None, napari_repo=HERE): "version": version.replace("+", "_"), "channels": base_env["channels"], "conda_default_channels": ["conda-forge"], - "channels_remap": [ - { - "src": f"https://github.com/napari/pins/releases/download/napari-v{channel_v}", - "dest": f"napari-v{channel_v}", - } - ], "installer_filename": OUTPUT_FILENAME, "initialize_conda": False, "initialize_by_default": False,