Skip to content

Commit

Permalink
Merge branch 'main' into support-ruamel-yaml-18
Browse files Browse the repository at this point in the history
  • Loading branch information
jaimergp authored Jan 7, 2024
2 parents 11485f2 + 764ba8a commit a55ffb3
Show file tree
Hide file tree
Showing 29 changed files with 525 additions and 140 deletions.
10 changes: 1 addition & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,8 @@ jobs:
conda-standalone: conda-standalone
- os: windows
python-version: "3.11"
# conda-standalone: micromamba
conda-standalone: conda-standalone-nightly
# Micromamba doesn't support Windows yet (menuinst features missing)
# - os: windows
# python-version: 3.11
# conda-standalone: micromamba

env:
PYTHONUNBUFFERED: "1"
Expand Down Expand Up @@ -133,7 +130,6 @@ jobs:
- name: Run examples
env:
CONSTRUCTOR_EXAMPLES_KEEP_ARTIFACTS: "${{ runner.temp }}/examples_artifacts"
# signtool only exists on Windows, but doesn't cause errors on unix when absent
CONSTRUCTOR_SIGNTOOL_PATH: "C:/Program Files (x86)/Windows Kits/10/bin/10.0.17763.0/x86/signtool.exe"
run: |
rm -rf coverage.json
Expand All @@ -144,10 +140,6 @@ jobs:
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: integration
- name: Test with conda-libmamba-solver
run: |
conda install -yq conda-libmamba-solver
CONDA_SOLVER=libmamba CONDA_VERBOSITY=1 pytest -vv tests/test_examples.py -k noconda
- name: Check docs are up-to-date
if: matrix.check-docs
run: |
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ repos:
args: ["--py37-plus", "--keep-percent-format"]
exclude: ^(constructor/nsis/.*py)
- repo: https://github.com/PyCQA/isort
rev: 5.13.0
rev: 5.13.2
hooks:
- id: isort
- repo: https://github.com/PyCQA/flake8
Expand Down
25 changes: 17 additions & 8 deletions CONSTRUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,11 @@ by an exact URL; e.g.,
`https://repo.anaconda.com/pkgs/main/osx-64/openssl-1.0.2o-h26aff7b_0.tar.bz2`.
This key can also take a `str` pointing to a requirements file with the same syntax.

The specs will be solved with the solver configured for your `base` conda installation,
if any. Starting with conda 22.11, this behavior can be overriden with the
`CONDA_SOLVER` environment variable.
Note: `constructor` relies on `conda`'s Python API to solve the passed
specifications. You can still set the `CONDA_SOLVER` environment variable
to override system-wide settings for `constructor`. If you are using
`constructor` from a non-`base` environment, make sure the
configured solver plugin is also installed in that environment.

### `user_requested_specs`

Expand Down Expand Up @@ -126,9 +128,16 @@ _required:_ no<br/>
_type:_ list<br/>

A list of packages with menu items to be installed. The packages must have
necessary metadata in `Menu/<package name>.json`). Menu items are currently
only supported on Windows. By default, all menu items will be installed;
supplying this list allows a subset to be selected instead.
necessary metadata in `Menu/<package name>.json`). By default, all menu items
found in the installation will be created; supplying this list allows a
subset to be selected instead. If an empty list is supplied, no shortcuts will
be created.

If all environments (`extra_envs` included) set `menu_packages` to an empty list,
no UI options about shortcuts will be offered to the user.

Note: This option is not fully implemented when `micromamba` is used as
the `--conda-exe` binary. The only accepted value is an empty list (`[]`).

### `ignore_duplicate_files`

Expand Down Expand Up @@ -218,12 +227,12 @@ name) to a dictionary of options:
an empty list.
- `user_requested_specs` (list of str): same as the global option, but for this env;
if not provided, global value is _not_ used
- `menu_packages` (list of str): same as the global option, for this env;
if not provided, the global value is _not_ used.

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
33 changes: 20 additions & 13 deletions constructor/construct.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@
`https://repo.anaconda.com/pkgs/main/osx-64/openssl-1.0.2o-h26aff7b_0.tar.bz2`.
This key can also take a `str` pointing to a requirements file with the same syntax.
The specs will be solved with the solver configured for your `base` conda installation,
if any. Starting with conda 22.11, this behavior can be overriden with the
`CONDA_SOLVER` environment variable.
Note: `constructor` relies on `conda`'s Python API to solve the passed
specifications. You can still set the `CONDA_SOLVER` environment variable
to override system-wide settings for `constructor`. If you are using
`constructor` from a non-`base` environment, make sure the
configured solver plugin is also installed in that environment.
'''),

('user_requested_specs', False, (list, str), '''
Expand All @@ -82,11 +84,18 @@
is contained as a result of resolving the specs for `python 2.7`.
'''),

('menu_packages', False, list, '''
('menu_packages', False, list, '''
A list of packages with menu items to be installed. The packages must have
necessary metadata in `Menu/<package name>.json`). Menu items are currently
only supported on Windows. By default, all menu items will be installed;
supplying this list allows a subset to be selected instead.
necessary metadata in `Menu/<package name>.json`). By default, all menu items
found in the installation will be created; supplying this list allows a
subset to be selected instead. If an empty list is supplied, no shortcuts will
be created.
If all environments (`extra_envs` included) set `menu_packages` to an empty list,
no UI options about shortcuts will be offered to the user.
Note: This option is not fully implemented when `micromamba` is used as
the `--conda-exe` binary. The only accepted value is an empty list (`[]`).
'''),

('ignore_duplicate_files', False, bool, '''
Expand Down Expand Up @@ -151,12 +160,12 @@
an empty list.
- `user_requested_specs` (list of str): same as the global option, but for this env;
if not provided, global value is _not_ used
- `menu_packages` (list of str): same as the global option, for this env;
if not provided, the global value is _not_ used.
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 @@ -598,9 +607,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 Expand Up @@ -765,7 +772,7 @@ def verify(info):
sys.exit(
f"Environment names (keys in 'extra_envs') cannot contain any of {disallowed}. "
f"You tried to use: {env_name}"
)
)
for key, value in env_data.items():
if key not in _EXTRA_ENVS_SCHEMA:
sys.exit(f"Key '{key}' not supported in 'extra_envs'.")
Expand Down
10 changes: 6 additions & 4 deletions constructor/fcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ def getsize(filename):


def warn_menu_packages_missing(precs, menu_packages):
if not menu_packages:
return
all_names = {prec.name for prec in precs}
for name in menu_packages:
if name not in all_names:
Expand Down Expand Up @@ -236,7 +238,7 @@ def _precs_from_environment(environment, input_dir):


def _solve_precs(name, version, download_dir, platform, channel_urls=(), channels_remap=(),
specs=(), exclude=(), menu_packages=(), environment=None, environment_file=None,
specs=(), exclude=(), menu_packages=None, environment=None, environment_file=None,
verbose=True, conda_exe="conda.exe", extra_env=False, input_dir=""):
# Add python to specs, since all installers need a python interpreter. In the future we'll
# probably want to add conda too.
Expand Down Expand Up @@ -376,7 +378,7 @@ def _fetch_precs(precs, download_dir, transmute_file_type=''):


def _main(name, version, download_dir, platform, channel_urls=(), channels_remap=(), specs=(),
exclude=(), menu_packages=(), ignore_duplicate_files=True, environment=None,
exclude=(), menu_packages=None, ignore_duplicate_files=True, environment=None,
environment_file=None, verbose=True, dry_run=False, conda_exe="conda.exe",
transmute_file_type='', extra_envs=None, check_path_spaces=True, input_dir=""):
precs = _solve_precs(
Expand Down Expand Up @@ -408,7 +410,7 @@ def _main(name, version, download_dir, platform, channel_urls=(), channels_remap
channels_remap=env_config.get("channels_remap", channels_remap),
specs=env_config.get("specs", ()),
exclude=env_config.get("exclude", exclude),
menu_packages=env_config.get("menu_packages", ()),
menu_packages=env_config.get("menu_packages"),
environment=env_config.get("environment"),
environment_file=env_config.get("environment_file"),
verbose=verbose,
Expand Down Expand Up @@ -462,7 +464,7 @@ def main(info, verbose=True, dry_run=False, conda_exe="conda.exe"):
channels_remap = info.get('channels_remap', ())
specs = info.get("specs", ())
exclude = info.get("exclude", ())
menu_packages = info.get("menu_packages", ())
menu_packages = info.get("menu_packages")
ignore_duplicate_files = info.get("ignore_duplicate_files", True)
environment = info.get("environment", None)
environment_file = info.get("environment_file", None)
Expand Down
68 changes: 60 additions & 8 deletions constructor/header.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ KEEP_PKGS=1
KEEP_PKGS=0
#endif
SKIP_SCRIPTS=0
#if enable_shortcuts == "true"
SKIP_SHORTCUTS=0
#endif
TEST=0
REINSTALL=0
USAGE="
Expand All @@ -70,6 +73,9 @@ Installs ${INSTALLER_NAME} ${INSTALLER_VER}
-p PREFIX install prefix, defaults to $PREFIX
#endif
-s skip running pre/post-link/install scripts
#if enable_shortcuts == 'true'
-m disable the creation of menu items / shortcuts
#endif
-u update an existing installation
#if has_conda
-t run package tests after installation (may install conda-build)
Expand All @@ -80,7 +86,11 @@ Installs ${INSTALLER_NAME} ${INSTALLER_VER}
# However getopt is not standardized and the version on Mac has different
# behaviour. getopts is good enough for what we need :)
# More info: https://unix.stackexchange.com/questions/62950/
#if enable_shortcuts == "true"
while getopts "bifhkp:smut" x; do
#else
while getopts "bifhkp:sut" x; do
#endif
case "$x" in
h)
printf "%s\\n" "$USAGE"
Expand All @@ -104,6 +114,11 @@ while getopts "bifhkp:sut" x; do
s)
SKIP_SCRIPTS=1
;;
#if enable_shortcuts == "true"
m)
SKIP_SHORTCUTS=1
;;
#endif
u)
FORCE=1
;;
Expand Down Expand Up @@ -391,14 +406,19 @@ cd "$PREFIX"
unset PYTHON_SYSCONFIGDATA_NAME _CONDA_PYTHON_SYSCONFIGDATA_NAME

# the first binary payload: the standalone conda executable
CONDA_EXEC="$PREFIX/conda.exe"
CONDA_EXEC="$PREFIX/_conda"
extract_range "${boundary0}" "${boundary1}" > "$CONDA_EXEC"
chmod +x "$CONDA_EXEC"

export TMP_BACKUP="${TMP:-}"
export TMP="$PREFIX/install_tmp"
mkdir -p "$TMP"

# Create $PREFIX/.nonadmin if the installation didn't require superuser permissions
if [ "$(id -u)" -ne 0 ]; then
touch "$PREFIX/.nonadmin"
fi

# the second binary payload: the tarball of packages
printf "Unpacking payload ...\n"
extract_range $boundary1 $boundary2 | \
Expand Down Expand Up @@ -445,14 +465,31 @@ test -d ~/.conda || mkdir -p ~/.conda >/dev/null 2>/dev/null || test -d ~/.conda

printf "\nInstalling base environment...\n\n"

#if enable_shortcuts == "true"
if [ "$SKIP_SHORTCUTS" = "1" ]; then
shortcuts="--no-shortcuts"
else
shortcuts="__SHORTCUTS__"
fi
#endif
#if enable_shortcuts == "false"
shortcuts="--no-shortcuts"
#endif
#if enable_shortcuts == "incompatible"
shortcuts=""
#endif

# shellcheck disable=SC2086
CONDA_ROOT_PREFIX="$PREFIX" \
CONDA_REGISTER_ENVS="__REGISTER_ENVS__" \
CONDA_SAFETY_CHECKS=disabled \
CONDA_EXTRA_SAFETY_CHECKS=no \
CONDA_CHANNELS="__CHANNELS__" \
CONDA_PKGS_DIRS="$PREFIX/pkgs" \
"$CONDA_EXEC" install --offline --file "$PREFIX/pkgs/env.txt" -yp "$PREFIX" || exit 1
"$CONDA_EXEC" install --offline --file "$PREFIX/pkgs/env.txt" -yp "$PREFIX" $shortcuts || exit 1
rm -f "$PREFIX/pkgs/env.txt"

#The templating doesn't support nested if statements
#if has_conda
mkdir -p "$PREFIX/envs"
for env_pkgs in "${PREFIX}"/pkgs/envs/*/; do
Expand All @@ -469,14 +506,31 @@ for env_pkgs in "${PREFIX}"/pkgs/envs/*/; do
else
env_channels="__CHANNELS__"
fi

# TODO: custom shortcuts per env?
#endif
#if has_conda and enable_shortcuts == "true"
if [ "$SKIP_SHORTCUTS" = "1" ]; then
env_shortcuts="--no-shortcuts"
else
# This file is guaranteed to exist, even if empty
env_shortcuts=$(cat "${env_pkgs}shortcuts.txt")
rm -f "${env_pkgs}shortcuts.txt"
fi
#endif
#if has_conda and enable_shortcuts == "false"
env_shortcuts="--no-shortcuts"
#endif
#if has_conda and enable_shortcuts == "incompatible"
env_shortcuts=""
#endif
#if has_conda
# shellcheck disable=SC2086
CONDA_ROOT_PREFIX="$PREFIX" \
CONDA_REGISTER_ENVS="__REGISTER_ENVS__" \
CONDA_SAFETY_CHECKS=disabled \
CONDA_EXTRA_SAFETY_CHECKS=no \
CONDA_CHANNELS="$env_channels" \
CONDA_PKGS_DIRS="$PREFIX/pkgs" \
"$CONDA_EXEC" install --offline --file "${env_pkgs}env.txt" -yp "$PREFIX/envs/$env_name" || exit 1
"$CONDA_EXEC" install --offline --file "${env_pkgs}env.txt" -yp "$PREFIX/envs/$env_name" $env_shortcuts || exit 1
rm -f "${env_pkgs}env.txt"
done
#endif
Expand All @@ -486,9 +540,6 @@ __INSTALL_COMMANDS__
POSTCONDA="$PREFIX/postconda.tar.bz2"
"$CONDA_EXEC" constructor --prefix "$PREFIX" --extract-tarball < "$POSTCONDA" || exit 1
rm -f "$POSTCONDA"

rm -f "$CONDA_EXEC"

rm -rf "$PREFIX/install_tmp"
export TMP="$TMP_BACKUP"

Expand Down Expand Up @@ -630,4 +681,5 @@ fi
#endif

exit 0
# shellcheck disable=SC2317
@@END_HEADER@@
Loading

0 comments on commit a55ffb3

Please sign in to comment.