Skip to content

Commit 4bf0143

Browse files
committed
Allow user to specify custom download cache directory
Contributes to #10.
1 parent 2540445 commit 4bf0143

2 files changed

Lines changed: 48 additions & 10 deletions

File tree

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,26 @@ Python plugin for linuxdeploy. Sets up miniconda inside an AppDir, and installs
1616
There are many variables available to alter the behavior of the plugin. The current list can be obtained by calling the plugin with `--help`.
1717

1818

19+
## Customize caching behavior
20+
21+
By default, linuxdeploy-plugin-conda redownloads the miniconda installer on every execution. This is not an issue for most people, as the installers are only 50-80 MiB in size. However, it is usually not necessary to redownload the file every time, especially while developing scripts based on the conda plugin.
22+
23+
Therefore, you can set a custom directory via the environment variable `$CONDA_DOWNLOAD_DIR`, into which downloaded files are stored then. The plugin makes use of some `wget` parameters to ensure that the file is only downloaded when it is incomplete (`-c`) or there is a newer version available (`-N`).
24+
25+
Example:
26+
27+
```bash
28+
> export CONDA_DOWNLOAD_DIR=/my/own/directory
29+
> ./linuxdeploy-x86_64.AppImage --plugin conda [...]
30+
[...]
31+
Using user-specified download directory: /my/own/directory
32+
[...]
33+
```
34+
35+
Relative paths work as well.
36+
37+
38+
1939
## Example
2040

2141
This generates a working FreeCAD AppImage from Conda ingredients, including Qt and PyQt:

linuxdeploy-plugin-conda.sh

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,29 @@ if [ "$CONDA_PACKAGES" == "" ]; then
6060
echo "WARNING: \$CONDA_PACKAGES not set, no packages will be installed!"
6161
fi
6262

63+
# the user can specify a directory into which the conda installer is downloaded
64+
# if they don't specify one, we use a temporary directory
65+
# if one is specified, the installer will not be re-downloaded unless it has changed
66+
if [ "$CONDA_DOWNLOAD_DIR" != "" ]; then
67+
# resolve path relative to cwd
68+
if [[ "$CONDA_DOWNLOAD_DIR" != /* ]]; then
69+
CONDA_DOWNLOAD_DIR="$(readlink -f "$CONDA_DOWNLOAD_DIR")"
70+
fi
6371

64-
# create temporary directory into which downloaded files are put
65-
TMPDIR=$(mktemp -d)
72+
echo "Using user-specified download directory: $CONDA_DOWNLOAD_DIR"
73+
mkdir -p "$CONDA_DOWNLOAD_DIR"
74+
else
75+
# create temporary directory into which downloaded files are put
76+
CONDA_DOWNLOAD_DIR="$(mktemp -d)"
6677

67-
_cleanup() {
68-
rm -rf "$TMPDIR"
69-
}
78+
_cleanup() {
79+
if [ -d "$CONDA_DOWNLOAD_DIR"]; then
80+
rm -rf "$CONDA_DOWNLOAD_DIR"
81+
fi
82+
}
7083

71-
trap _cleanup EXIT
84+
trap _cleanup EXIT
85+
fi
7286

7387
if [ -d "$APPDIR"/usr/conda ]; then
7488
echo "Error: directory exists: $APPDIR/usr/conda"
@@ -80,22 +94,25 @@ ARCH=${ARCH:-x86_64}
8094
# install Miniconda, a self contained Python distribution, into AppDir
8195
case "$ARCH" in
8296
"x86_64")
83-
miniconda_url=https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
97+
miniconda_installer_filename=Miniconda3-latest-Linux-x86_64.sh
8498
;;
8599
"i386"|"i686")
86-
miniconda_url=https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86.sh
100+
miniconda_installer_filename=Miniconda3-latest-Linux-x86.sh
87101
;;
88102
*)
89103
echo "Error: Unknown Miniconda arch: $ARCH"
90104
exit 1
91105
;;
92106
esac
93107

94-
(cd "$TMPDIR" && wget "$miniconda_url")
108+
pushd "$CONDA_DOWNLOAD_DIR"
109+
miniconda_url=https://repo.continuum.io/miniconda/"$miniconda_installer_filename"
110+
wget -N -c "$miniconda_url"
111+
popd
95112

96113
# install into usr/conda/ instead of usr/ to make sure that the libraries shipped with conda don't overwrite or
97114
# interfere with libraries bundled by other plugins or linuxdeploy itself
98-
bash "$TMPDIR"/Miniconda3-latest-Linux-*.sh -b -p "$APPDIR"/usr/conda -f
115+
bash "$CONDA_DOWNLOAD_DIR"/"$miniconda_installer_filename" -b -p "$APPDIR"/usr/conda -f
99116

100117
# activate environment
101118
. "$APPDIR"/usr/conda/bin/activate
@@ -162,3 +179,4 @@ if [ "$CONDA_SKIP_CLEANUP" == "" ]; then
162179
rm -rf lib/python?.?/site-packages/{setuptools,pip}
163180
popd
164181
fi
182+

0 commit comments

Comments
 (0)