Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes to support PREFIX containing spaces #449

Merged
merged 83 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
1702af8
Fixes to support PREFIX containing spaces
nsoranzo May 7, 2021
1ec2e54
Merge remote-tracking branch 'upstream/main' into patch-1
jaimergp Aug 15, 2022
1dbe1a5
bring back the getopt compatibility
jaimergp Aug 15, 2022
56bc9f6
remove getopt parsing, always use getopts
jaimergp Aug 15, 2022
d1ad911
Double-quote variables in new code
nsoranzo Aug 17, 2022
a8514f7
quote some more stuff
jaimergp Aug 17, 2022
3aadafe
(re-)enable space checks in all platforms, but default to False
jaimergp Aug 17, 2022
0871a2a
add news
jaimergp Aug 17, 2022
7e20a04
add tests
jaimergp Aug 17, 2022
f9565f7
use spaces in examples
jaimergp Aug 17, 2022
d800679
fix examples
jaimergp Aug 17, 2022
5a69eb5
workaround entry points limitations
jaimergp Aug 17, 2022
c0d6e07
fix postinstall test
jaimergp Aug 17, 2022
6030803
Fix typo
nsoranzo Aug 17, 2022
244afc7
fix prefix checks on mac
jaimergp Aug 17, 2022
9277ce3
some more quotes
jaimergp Aug 17, 2022
5e80a55
workaround one more entry point issue
jaimergp Aug 17, 2022
c7d3789
update example
jaimergp Aug 17, 2022
ff1705c
Merge branch 'main' into patch-1
jaimergp Aug 17, 2022
4351d92
Update constructor/osx/post_extract.sh
jaimergp Aug 17, 2022
0c30d4d
notify exit status
jaimergp Aug 17, 2022
0d584c3
Merge branch 'patch-1' of github.com:nsoranzo/constructor into patch-1
jaimergp Aug 17, 2022
5702f46
exit script failures if env var is set
jaimergp Aug 17, 2022
9b6e459
pass path properly...
jaimergp Aug 17, 2022
ab5449a
update .bat tests
jaimergp Aug 22, 2022
d95b712
flip default value
jaimergp Aug 24, 2022
64f7273
wrong default changed
jaimergp Aug 24, 2022
2da7847
add 'check_path_spaces: False' to examples
jaimergp Aug 24, 2022
bf20f13
improve spaces checking in pkg
jaimergp Aug 24, 2022
bd241c7
check for spaces in silent mode too?
jaimergp Aug 24, 2022
923c83d
enable errors on MinicondaX for Windows (temp)
jaimergp Aug 24, 2022
fd4cd93
make sure all dialog boxes for error have DetailPrint statements so w…
jaimergp Aug 24, 2022
d121979
OnDirectoryLeave not called on silent mode?
jaimergp Aug 24, 2022
00016c9
better docs about Windows silent installs
jaimergp Aug 24, 2022
252852a
add /SD options to all messageboxes with buttons
jaimergp Aug 24, 2022
4a2afc6
add debugging to each function
jaimergp Aug 24, 2022
06aae10
allow long paths in all examples
jaimergp Aug 24, 2022
8dbfabe
tempdir issues getting in the way?
jaimergp Aug 24, 2022
433d3db
add timings and handle io errors in run_examples
jaimergp Aug 24, 2022
20727ea
prettier debugging
jaimergp Aug 24, 2022
f2e06bf
document the nuances in run_examples
jaimergp Aug 24, 2022
ede8e86
handle IO error lines
jaimergp Aug 24, 2022
6464409
run examples on noconda
jaimergp Aug 24, 2022
b5554bf
add a little tip
jaimergp Aug 24, 2022
a6136c9
this should pass
jaimergp Aug 24, 2022
611d2c4
handle edge cases for empty log files too
jaimergp Aug 24, 2022
49fed9a
Merge remote-tracking branch 'upstream/main' into patch-1
jaimergp Aug 29, 2022
767f7e8
Merge branch 'main' into patch-1
jezdez Aug 30, 2022
86e1360
update news
jaimergp Aug 30, 2022
8d40666
Merge remote-tracking branch 'upstream/main' into patch-1
jaimergp Sep 6, 2022
332e101
do not check path on this example either
jaimergp Sep 6, 2022
168dc1b
avoid issues with spaces in shebangs during initialization
jaimergp Sep 6, 2022
687af3e
Merge branch 'main' into patch-1
jaimergp Sep 12, 2022
727f309
update docs
jaimergp Sep 12, 2022
2041d86
do not rely on direct entry points
jaimergp Sep 12, 2022
db9acec
Merge remote-tracking branch 'upstream/main' into patch-1
jaimergp Sep 12, 2022
63dcaf4
fix pytest
jaimergp Sep 12, 2022
3b97067
quote these too
jaimergp Sep 12, 2022
794dc9f
do not check path on examples
jaimergp Sep 12, 2022
75d6b32
None is a valid value
jaimergp Sep 13, 2022
dcc0a45
More quotes and use POSIX sh syntax
nsoranzo Sep 16, 2022
2f091f6
Merge branch 'main' into patch-1
jaimergp Oct 5, 2022
ca06b90
Merge branch 'main' into patch-1
jaimergp Jan 2, 2023
604b88b
Fix
dbast Jan 2, 2023
42c76b8
Update constructor/header.sh
dbast Jan 2, 2023
6861dd4
Merge remote-tracking branch 'upstream/main' into patch-1
dbast Jan 3, 2023
3923546
Run examples in un-buffered mode to see output
dbast Jan 2, 2023
7a88a84
Set 5 minute timeout for example execution
dbast Jan 3, 2023
aa5719f
Convert uninstall return code into error
dbast Jan 5, 2023
524f052
Test without spaces on windows
dbast Jan 5, 2023
ac2e7c6
Update scripts/run_examples.py
dbast Jan 5, 2023
4bc1b0c
Revert "Test without spaces on windows"
dbast Jan 5, 2023
59342a0
Revert "Update scripts/run_examples.py"
dbast Jan 6, 2023
04e89c6
Revert "Revert "Test without spaces on windows""
dbast Jan 6, 2023
f907a4e
Test some windows installers with spaces, but then without uninstalle…
dbast Jan 6, 2023
b37072d
Try quotes around env_dir for nsis uninstall calls
dbast Jan 6, 2023
4a82db8
Revert "Try quotes around env_dir for nsis uninstall calls"
dbast Jan 7, 2023
0814e5c
forbid spaces if conda is present in base on linux and macos
jaimergp Jan 9, 2023
f0b4627
refine which examples support spaces
jaimergp Jan 9, 2023
4d392eb
sync docs
jaimergp Jan 9, 2023
9945cae
fix osx test
jaimergp Jan 10, 2023
2da4026
Increase timeout
dbast Jan 10, 2023
c57b9ff
Update .github/workflows/main.yml
dbast Jan 10, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ jobs:
source $CONDA/etc/profile.d/conda.sh
conda activate constructor
mkdir -p examples_artifacts/
python scripts/run_examples.py --keep-artifacts=examples_artifacts/
python -u scripts/run_examples.py --keep-artifacts=examples_artifacts/
- name: Upload the example installers as artifacts
if: github.event_name == 'pull_request' && matrix.pyver == '3.9'
uses: actions/upload-artifact@v3
Expand Down
7 changes: 5 additions & 2 deletions CONSTRUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -557,8 +557,11 @@ Read notes about the particularities of Windows silent mode `/S` in the

_required:_ no<br/>
_type:_ boolean<br/>
Check if the path where the distribution is installed contains spaces and show a warning
if any spaces are found. Default is True. (Windows only).
Check if the path where the distribution is installed contains spaces. Default is True.
To allow installations with spaces, change to False. Note that:

- A recent conda-standalone (>=22.11.1) or equivalent is needed for full support.
- `conda` cannot be present in the `base` environment

Read notes about the particularities of Windows silent mode `/S` in the
`installer_type` documentation.
Expand Down
7 changes: 5 additions & 2 deletions constructor/construct.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,11 @@
'''),

('check_path_spaces', False, bool, '''
Check if the path where the distribution is installed contains spaces and show a warning
if any spaces are found. Default is True. (Windows only).
Check if the path where the distribution is installed contains spaces. Default is True.
To allow installations with spaces, change to False. Note that:

- A recent conda-standalone (>=22.11.1) or equivalent is needed for full support.
- `conda` cannot be present in the `base` environment

Read notes about the particularities of Windows silent mode `/S` in the
`installer_type` documentation.
Expand Down
22 changes: 16 additions & 6 deletions constructor/fcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,19 +367,28 @@ 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,
environment_file=None, verbose=True, dry_run=False, conda_exe="conda.exe",
transmute_file_type='', extra_envs=None):
transmute_file_type='', extra_envs=None, check_path_spaces=True):
precs = _solve_precs(
name, version, download_dir, platform, channel_urls=channel_urls,
channels_remap=channels_remap, specs=specs, exclude=exclude,
menu_packages=menu_packages, environment=environment,
environment_file=environment_file, verbose=verbose, conda_exe=conda_exe
)
extra_envs = extra_envs or {}
conda_in_base: PackageCacheRecord = next((prec for prec in precs if prec.name == "conda"), None)
if conda_in_base:
if not check_path_spaces and platform.startswith(("linux-", "osx-")):
raise RuntimeError(
"'check_path_spaces=False' cannot be used on Linux and macOS installers "
"if 'conda' is present in the 'base' environment."
)
elif extra_envs:
raise RuntimeError(
"conda needs to be present in 'base' environment for 'extra_envs' to work"
)

extra_envs_precs = {}
for env_name, env_config in (extra_envs or {}).items():
if not any(prec.name == "conda" for prec in precs):
raise RuntimeError("conda needs to be present in `base` environment for extra_envs to work")

for env_name, env_config in extra_envs.items():
if verbose:
print("Solving extra environment:", env_name)
extra_envs_precs[env_name] = _solve_precs(
Expand Down Expand Up @@ -445,6 +454,7 @@ def main(info, verbose=True, dry_run=False, conda_exe="conda.exe"):
environment_file = info.get("environment_file", None)
transmute_file_type = info.get("transmute_file_type", "")
extra_envs = info.get("extra_envs", {})
check_path_spaces = info.get("check_path_spaces", True)

if not channel_urls and not channels_remap:
sys.exit("Error: at least one entry in 'channels' or 'channels_remap' is required")
Expand All @@ -467,7 +477,7 @@ def main(info, verbose=True, dry_run=False, conda_exe="conda.exe"):
has_conda, extra_envs_info) = _main(
name, version, download_dir, platform, channel_urls, channels_remap, specs,
exclude, menu_packages, ignore_duplicate_files, environment, environment_file,
verbose, dry_run, conda_exe, transmute_file_type, extra_envs
verbose, dry_run, conda_exe, transmute_file_type, extra_envs, check_path_spaces
)

info["_all_pkg_records"] = pkg_records # full PackageRecord objects
Expand Down
176 changes: 64 additions & 112 deletions constructor/header.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export INSTALLER_TYPE="SH"
THIS_DIR=$(DIRNAME=$(dirname "$0"); cd "$DIRNAME"; pwd)
THIS_FILE=$(basename "$0")
THIS_PATH="$THIS_DIR/$THIS_FILE"
PREFIX=__DEFAULT_PREFIX__
PREFIX="__DEFAULT_PREFIX__"
#if batch_mode
BATCH=1
#else
Expand Down Expand Up @@ -58,114 +58,60 @@ Installs __NAME__ __VERSION__
#if not keep_pkgs
-k do not clear the package cache after installation
#endif
#if check_path_spaces
-p PREFIX install prefix, defaults to $PREFIX, must not contain spaces.
#else
-p PREFIX install prefix, defaults to $PREFIX
#endif
-s skip running pre/post-link/install scripts
-u update an existing installation
#if has_conda
-t run package tests after installation (may install conda-build)
#endif
"

if which getopt > /dev/null 2>&1; then
OPTS=$(getopt bifhkp:sut "$*" 2>/dev/null)
if [ ! $? ]; then
printf "%s\\n" "$USAGE"
exit 2
fi

eval set -- "$OPTS"

while true; do
case "$1" in
-h)
printf "%s\\n" "$USAGE"
exit 2
;;
-b)
BATCH=1
shift
;;
-i)
BATCH=0
shift
;;
-f)
FORCE=1
shift
;;
-k)
KEEP_PKGS=1
shift
;;
-p)
PREFIX="$2"
shift
shift
;;
-s)
SKIP_SCRIPTS=1
shift
;;
-u)
FORCE=1
shift
;;
#if has_conda
-t)
TEST=1
shift
;;
#endif
--)
shift
break
;;
*)
printf "ERROR: did not recognize option '%s', please try -h\\n" "$1"
exit 1
;;
esac
done
else
while getopts "bifhkp:sut" x; do
case "$x" in
h)
printf "%s\\n" "$USAGE"
exit 2
# We used to have a getopt version here, falling back to getopts if needed
# 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/
while getopts "bifhkp:sut" x; do
case "$x" in
h)
printf "%s\\n" "$USAGE"
exit 2
;;
b)
BATCH=1
;;
i)
BATCH=0
;;
f)
FORCE=1
;;
k)
KEEP_PKGS=1
;;
p)
PREFIX="$OPTARG"
;;
s)
SKIP_SCRIPTS=1
;;
u)
FORCE=1
;;
b)
BATCH=1
;;
i)
BATCH=0
;;
f)
FORCE=1
;;
k)
KEEP_PKGS=1
;;
p)
PREFIX="$OPTARG"
;;
s)
SKIP_SCRIPTS=1
;;
u)
FORCE=1
;;
#if has_conda
t)
TEST=1
;;
t)
TEST=1
;;
#endif
?)
printf "ERROR: did not recognize option '%s', please try -h\\n" "$x"
exit 1
;;
esac
done
fi
?)
printf "ERROR: did not recognize option '%s', please try -h\\n" "$x"
exit 1
;;
esac
done

# For testing, keep the package cache around longer
CLEAR_AFTER_TEST=0
Expand Down Expand Up @@ -343,6 +289,7 @@ EOF
printf "[%s] >>> " "$PREFIX"
read -r user_prefix
if [ "$user_prefix" != "" ]; then
#if check_path_spaces is True
case "$user_prefix" in
*\ * )
printf "ERROR: Cannot install into directories with spaces\\n" >&2
Expand All @@ -352,15 +299,20 @@ EOF
eval PREFIX="$user_prefix"
;;
esac
#else
PREFIX="$user_prefix"
#endif
fi
fi # !BATCH

#if check_path_spaces is True
case "$PREFIX" in
*\ * )
printf "ERROR: Cannot install into directories with spaces\\n" >&2
exit 1
;;
esac
#endif

if [ "$FORCE" = "0" ] && [ -e "$PREFIX" ]; then
printf "ERROR: File or directory already exists: '%s'\\n" "$PREFIX" >&2
Expand All @@ -370,7 +322,6 @@ elif [ "$FORCE" = "1" ] && [ -e "$PREFIX" ]; then
REINSTALL=1
fi


if ! mkdir -p "$PREFIX"; then
printf "ERROR: Could not create directory: '%s'\\n" "$PREFIX" >&2
exit 1
Expand Down Expand Up @@ -438,8 +389,8 @@ extract_range $boundary0 $boundary1 > "$CONDA_EXEC"
chmod +x "$CONDA_EXEC"

export TMP_BACKUP="$TMP"
export TMP=$PREFIX/install_tmp
mkdir -p $TMP
export TMP="$PREFIX/install_tmp"
nsoranzo marked this conversation as resolved.
Show resolved Hide resolved
mkdir -p "$TMP"

# the second binary payload: the tarball of packages
printf "Unpacking payload ...\n"
Expand Down Expand Up @@ -473,7 +424,6 @@ else
fi
#endif

PYTHON="$PREFIX/bin/python"
MSGS="$PREFIX/.messages.txt"
touch "$MSGS"
export FORCE
Expand All @@ -494,9 +444,9 @@ CONDA_PKGS_DIRS="$PREFIX/pkgs" \
rm -f "$PREFIX/pkgs/env.txt"

#if has_conda
mkdir -p $PREFIX/envs
for env_pkgs in ${PREFIX}/pkgs/envs/*/; do
env_name=$(basename ${env_pkgs})
mkdir -p "$PREFIX/envs"
for env_pkgs in "${PREFIX}"/pkgs/envs/*/; do
env_name=$(basename "${env_pkgs}")
if [ "$env_name" = "*" ]; then
continue
fi
Expand Down Expand Up @@ -526,9 +476,9 @@ POSTCONDA="$PREFIX/postconda.tar.bz2"
"$CONDA_EXEC" constructor --prefix "$PREFIX" --extract-tarball < "$POSTCONDA" || exit 1
rm -f "$POSTCONDA"

rm -f $PREFIX/conda.exe
rm -f "$CONDA_EXEC"

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


Expand Down Expand Up @@ -560,7 +510,7 @@ if [ "$KEEP_PKGS" = "0" ]; then
else
# Attempt to delete the empty temporary directories in the package cache
# These are artifacts of the constructor --extract-conda-pkgs
find $PREFIX/pkgs -type d -empty -exec rmdir {} \; 2>/dev/null || :
find "$PREFIX/pkgs" -type d -empty -exec rmdir {} \; 2>/dev/null || :
fi

cat <<EOF
Expand Down Expand Up @@ -609,13 +559,15 @@ if [ "$BATCH" = "0" ]; then
printf "\\n"
else
case $SHELL in
*zsh) $PREFIX/bin/conda init zsh ;;
*) $PREFIX/bin/conda init ;;
# We call the module directly to avoid issues with spaces in shebang
*zsh) "$PREFIX/bin/python" -m conda init zsh ;;
*) "$PREFIX/bin/python" -m conda init ;;
esac
if [ -f "$PREFIX/bin/mamba" ]; then
case $SHELL in
*zsh) $PREFIX/bin/mamba init zsh ;;
*) $PREFIX/bin/mamba init ;;
# We call the module directly to avoid issues with spaces in shebang
*zsh) "$PREFIX/bin/python" -m mamba.mamba init zsh ;;
*) "$PREFIX/bin/python" -m mamba.mamba init ;;
esac
fi
fi
Expand Down
Loading