Skip to content

Commit

Permalink
test menu_packages from extra_envs
Browse files Browse the repository at this point in the history
  • Loading branch information
jaimergp committed Dec 20, 2023
1 parent 137b5e6 commit 93d43dc
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 18 deletions.
2 changes: 0 additions & 2 deletions CONSTRUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,6 @@ name) to a dictionary of options:
Notes:
- `ignore_duplicate_files` will always be considered `True` if `extra_envs` is in use.
- `conda` needs to be present in the `base` environment (via `specs`)
- support for `menu_packages` is planned, but not possible right now. For now, all packages
in an `extra_envs` config will be allowed to create their shortcuts.
- If a global `exclude` option is used, it will have an effect on the environments created
by `extra_envs` too. For example, if the global environment excludes `tk`, none of the
extra environments will have it either. Unlike the global option, an error will not be
Expand Down
6 changes: 1 addition & 5 deletions constructor/construct.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,6 @@
Notes:
- `ignore_duplicate_files` will always be considered `True` if `extra_envs` is in use.
- `conda` needs to be present in the `base` environment (via `specs`)
- support for `menu_packages` is planned, but not possible right now. For now, all packages
in an `extra_envs` config will be allowed to create their shortcuts.
- If a global `exclude` option is used, it will have an effect on the environments created
by `extra_envs` too. For example, if the global environment excludes `tk`, none of the
extra environments will have it either. Unlike the global option, an error will not be
Expand Down Expand Up @@ -608,9 +606,7 @@
"channels_remap": (list, tuple),
"user_requested_specs": (list, tuple),
"exclude": (list, tuple),
# TODO: we can't support menu_packages for extra envs yet
# will implement when the PR for new menuinst lands
# "menu_packages": (list, tuple),
"menu_packages": (list, tuple),
}

logger = logging.getLogger(__name__)
Expand Down
9 changes: 6 additions & 3 deletions constructor/osxpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ def modify_xml(xml_path, info):
choices_outline.extend(list(child))
choices_outline.remove(child)

menu_packages = info.get('menu_packages', True)
for path_choice in root.findall('choice'):
ident = path_choice.get('id')
if ident == 'default':
Expand All @@ -218,7 +217,7 @@ def modify_xml(xml_path, info):
path_choice.set('visible', 'false')
path_choice.set('title', 'Apply {}'.format(info['name']))
path_choice.set('enabled', 'false')
elif ident.endswith('shortcuts') and menu_packages:
elif ident.endswith('shortcuts') and info["_enable_shortcuts"]:
# Show this option if menu_packages was set to a non-empty value
# or if the option was not set at all. We don't show the option
# menu_packages was set to an empty list!
Expand All @@ -227,7 +226,11 @@ def modify_xml(xml_path, info):
path_choice.set('enabled', 'true')
descr = "Create shortcuts for compatible packages"
menu_packages = info.get("menu_packages")
if isinstance(menu_packages, (list, tuple)):
if menu_packages is None:
menu_packages = []
for extra_env in info.get("_extra_envs_info", {}).values():
menu_packages += extra_env.get("menu_packages", [])
if menu_packages:
descr += f" ({', '.join(menu_packages)})"
path_choice.set('description', descr)
elif ident.endswith('user_pre_install') and info.get('pre_install_desc'):
Expand Down
2 changes: 0 additions & 2 deletions docs/source/construct-yaml.md
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,6 @@ name) to a dictionary of options:
Notes:
- `ignore_duplicate_files` will always be considered `True` if `extra_envs` is in use.
- `conda` needs to be present in the `base` environment (via `specs`)
- support for `menu_packages` is planned, but not possible right now. For now, all packages
in an `extra_envs` config will be allowed to create their shortcuts.
- If a global `exclude` option is used, it will have an effect on the environments created
by `extra_envs` too. For example, if the global environment excludes `tk`, none of the
extra environments will have it either. Unlike the global option, an error will not be
Expand Down
11 changes: 11 additions & 0 deletions examples/shortcuts/construct.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,16 @@ specs:
- console_shortcut # [win]
- package_1

menu_packages:
- package_1

extra_envs:
another_env:
specs:
- package_1
- console_shortcut # [win]
menu_packages:
- console_shortcut # [win]

initialize_by_default: false
register_python: False
19 changes: 13 additions & 6 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,16 +405,23 @@ def test_example_shortcuts(tmp_path, request):
# check that the shortcuts are created
if sys.platform == "win32":
for key in ("ProgramData", "AppData"):
pkg_1 = Path(os.environ[key]) / "Microsoft/Windows/Start Menu/Programs/Package 1"
if pkg_1.exists():
assert (pkg_1 / "A.lnk").exists()
assert (pkg_1 / "B.lnk").exists()
start_menu = Path(os.environ[key]) / "Microsoft/Windows/Start Menu/Programs"
package_1 = start_menu / "Package 1"
miniconda = start_menu / "Miniconda3"
if package_1.is_dir() and miniconda.is_dir():
assert (package_1 / "A.lnk").is_file()
assert (package_1 / "B.lnk").is_file()
# The shortcut created from the 'base' env
# should not exist because we filtered it out in the YAML
# We do expect one shortcut from 'another_env'
assert not (miniconda / "Anaconda Prompt.lnk").is_file()
assert (miniconda / "Anaconda Prompt (another_env).lnk").is_file()
break
else:
raise AssertionError("No shortcuts found!")
_run_uninstaller_exe(install_dir)
assert not (pkg_1 / "A.lnk").exists()
assert not (pkg_1 / "B.lnk").exists()
assert not (package_1 / "A.lnk").is_file()
assert not (package_1 / "B.lnk").is_file()
elif sys.platform == "darwin":
applications = Path("~/Applications").expanduser()
print("Shortcuts found:", sorted(applications.glob("**/*.app")))
Expand Down

0 comments on commit 93d43dc

Please sign in to comment.