diff --git a/anaconda_anon_usage/install.py b/anaconda_anon_usage/install.py index 66688e2..cac3421 100644 --- a/anaconda_anon_usage/install.py +++ b/anaconda_anon_usage/install.py @@ -12,7 +12,6 @@ import sys import sysconfig from os.path import basename, dirname, exists, join, relpath -from traceback import format_exc from . import __version__ @@ -36,6 +35,8 @@ def configure_parser(): "pre-unlink script. It is not useful in normal operation; to disable " "the telemetry, use conda config --set anaconda_anon_usage false.", ) + # For testing only: exit with -1 if not enabled + g.add_argument("--expect", action="store_true", help=argparse.SUPPRESS) g.add_argument( "--status", action="store_true", @@ -54,29 +55,6 @@ def configure_parser(): verbose = True -def error(what, fatal=False, warn=False): - global success - print("ERROR:", what) - tb = format_exc() - if not tb.startswith("NoneType"): - print("-----") - print(tb.rstrip()) - print("-----") - if fatal: - print("cannot proceed; exiting.") - sys.exit(-1) - if not warn: - success = False - - -def tryop(op, *args, **kwargs): - try: - op(*args, **kwargs) - return True - except Exception: - return False - - PATCH_NAME = b"anaconda_anon_usage" PATCH_TEXT = b""" # %s %s @@ -147,6 +125,9 @@ def _patch(args, pfile, patch_text, patch_name): text, status = _read(pfile, patch_text, patch_name) if verbose: print(f"| status: {status}") + if args.expect and status != "ENABLED": + print("exiting due to unexpected status") + sys.exit(-1) if status == "NOT PRESENT": return elif status == "NEEDS UPDATE": diff --git a/conda.recipe/bld.bat b/conda.recipe/bld.bat index 3bc42a3..8c930ce 100644 --- a/conda.recipe/bld.bat +++ b/conda.recipe/bld.bat @@ -1,14 +1,14 @@ -echo on setlocal EnableDelayedExpansion %PREFIX%\python.exe -m pip install --no-deps --ignore-installed -vv . if "%NEED_SCRIPTS%" neq "yes" del %SP_DIR%\anaconda_anon_usage\install.py -if "%NEED_SCRIPTS%" equ "yes" del %SP_DIR%\anaconda_anon_usage\plugin.py if "%NEED_SCRIPTS%" neq "yes" exit +del %SP_DIR%\anaconda_anon_usage\plugin.py if not exist %PREFIX%\etc\conda\activate.d mkdir %PREFIX%\etc\conda\activate.d -if not exist %PREFIX%\python-scripts mkdir %PREFIX%\python-scripts -copy scripts\activate.sh %PREFIX%\etc\conda\activate.d\%PKG_NAME%_activate.sh -copy scripts\activate.bat %PREFIX%\etc\conda\activate.d\%PKG_NAME%_activate.bat -copy scripts\post-link.sh %PREFIX%\python-scripts\.%PKG_NAME%-post-link.sh -copy scripts\post-link.bat %PREFIX%\python-scripts\.%PKG_NAME%-post-link.bat -copy scripts\pre-unlink.sh %PREFIX%\python-scripts\.%PKG_NAME%-pre-unlink.sh -copy scripts\pre-unlink.bat %PREFIX%\python-scripts\.%PKG_NAME%-pre-unlink.bat +copy scripts\activate.sh %PREFIX%\etc\conda\activate.d\%PKG_NAME%_activate.sh +copy scripts\activate.bat %PREFIX%\etc\conda\activate.d\%PKG_NAME%_activate.bat +if not exist %PREFIX%\Scripts mkdir %PREFIX%\Scripts +copy scripts\post-link.bat %PREFIX%\Scripts\.%PKG_NAME%-post-link.bat +copy scripts\pre-unlink.bat %PREFIX%\Scripts\.%PKG_NAME%-pre-unlink.bat +if not exist %PREFIX%\bin mkdir %PREFIX%\bin +copy scripts\post-link.sh %PREFIX%\bin\.%PKG_NAME%-post-link.sh +copy scripts\pre-unlink.sh %PREFIX%\bin\.%PKG_NAME%-pre-unlink.sh diff --git a/conda.recipe/build.sh b/conda.recipe/build.sh index 69ad2d7..7434054 100644 --- a/conda.recipe/build.sh +++ b/conda.recipe/build.sh @@ -1,15 +1,17 @@ +#!/bin/bash "${PREFIX}/bin/python" -m pip install --no-deps --ignore-installed -vv . if [ "$NEED_SCRIPTS" != yes ]; then rm ${SP_DIR}/anaconda_anon_usage/install.py exit 0 -else - rm ${SP_DIR}/anaconda_anon_usage/plugin.py fi -mkdir -p "${PREFIX}/etc/conda/activate.d" -mkdir -p "${PREFIX}/python-scripts" -cp "scripts/activate.sh" "${PREFIX}/etc/conda/activate.d/${PKG_NAME}_activate.sh" -cp "scripts/activate.bat" "${PREFIX}/etc/conda/activate.d/${PKG_NAME}_activate.bat" -cp "scripts/post-link.sh" "${PREFIX}/python-scripts/.${PKG_NAME}-post-link.sh" -cp "scripts/pre-unlink.sh" "${PREFIX}/python-scripts/.${PKG_NAME}-pre-unlink.sh" -cp "scripts/post-link.bat" "${PREFIX}/python-scripts/.${PKG_NAME}-post-link.bat" -cp "scripts/pre-unlink.bat" "${PREFIX}/python-scripts/.${PKG_NAME}-pre-unlink.bat" +rm ${SP_DIR}/anaconda_anon_usage/plugin.py +if [ "$SUBDIR" = "noarch" ]; then sdir=python-scripts; else sdir=bin; fi +mkdir -p "${PREFIX}/etc/conda/activate.d" "${PREFIX}/${sdir}" +cp "scripts/activate.sh" "${PREFIX}/etc/conda/activate.d/${PKG_NAME}_activate.sh" +cp "scripts/post-link.sh" "${PREFIX}/${sdir}/.${PKG_NAME}-post-link.sh" +cp "scripts/pre-unlink.sh" "${PREFIX}/${sdir}/.${PKG_NAME}-pre-unlink.sh" +if [ "$SUBDIR" = "noarch" ]; then + cp "scripts/activate.bat" "${PREFIX}/etc/conda/activate.d/${PKG_NAME}_activate.bat" + cp "scripts/post-link.bat" "${PREFIX}/${sdir}/.${PKG_NAME}-post-link.bat" + cp "scripts/pre-unlink.bat" "${PREFIX}/${sdir}/.${PKG_NAME}-pre-unlink.bat" +fi diff --git a/conda.recipe/meta.yaml b/conda.recipe/meta.yaml index f2ed386..a08a40e 100644 --- a/conda.recipe/meta.yaml +++ b/conda.recipe/meta.yaml @@ -1,4 +1,5 @@ {% set data = load_setup_py_data() %} +{% set number = 0 %} package: name: anaconda-anon-usage @@ -8,6 +9,11 @@ source: path: .. build: + # Use a build number difference to ensure that the plugin + # variant is slightly preferred by conda's solver. + number: {{ number + 100 }} # [variant=="plugin"] + number: {{ number }} # [variant=="patch"] + string: py_{{ PKG_BUILDNUM }} noarch: python # [not win] script_env: - NEED_SCRIPTS=no # [variant=="plugin"] diff --git a/scripts/activate.bat b/scripts/activate.bat index e9cfb16..a388098 100644 --- a/scripts/activate.bat +++ b/scripts/activate.bat @@ -1 +1 @@ -@python -m anaconda_anon_usage.install --enable --quiet +@"%CONDA_PREFIX%\python.exe" -m anaconda_anon_usage.install --enable --quiet diff --git a/scripts/activate.sh b/scripts/activate.sh index 719fb0e..a5af7d7 100644 --- a/scripts/activate.sh +++ b/scripts/activate.sh @@ -1 +1,3 @@ -python -m anaconda_anon_usage.install --enable --quiet +pbin="${CONDA_PREFIX}/python.exe" +[ -f "${pbin}" ] || pbin="${CONDA_PREFIX}/bin/python" +"${pbin}" -m anaconda_anon_usage.install --enable --quiet || : diff --git a/scripts/post-link.bat b/scripts/post-link.bat index 16c84a2..65450b0 100644 --- a/scripts/post-link.bat +++ b/scripts/post-link.bat @@ -1,3 +1,3 @@ @echo off -if "%CONDA_PREFIX%"=="" (set "pfx=%PREFIX%") else (set "pfx=%CONDA_PREFIX%") -python -m anaconda_anon_usage.install --enable --quiet >>"%pfx%\.messages.txt" 2>&1 && if errorlevel 1 exit 1 +if "%CONDA_PREFIX%"=="" (set pfx="%PREFIX%") else (set pfx="%CONDA_PREFIX%") +"%pfx%\python.exe" -m anaconda_anon_usage.install --enable --quiet >>"%pfx%\.messages.txt" 2>&1 diff --git a/scripts/post-link.sh b/scripts/post-link.sh index 8b94042..b447b9e 100644 --- a/scripts/post-link.sh +++ b/scripts/post-link.sh @@ -1,4 +1,6 @@ -pfx=${CONDA_PREFIX:-${PREFIX:-}} -pbin=${pfx}/python.exe -[ -f ${pbin} ] || pbin=${pfx}/bin/python -${pbin} -m anaconda_anon_usage.install --enable --quiet >>"${pfx}/.messages.txt" 2>&1 +#!/bin/sh + +pfx="${CONDA_PREFIX:-${PREFIX:-}}" +pbin="${pfx}/python.exe" +[ -f "${pbin}" ] || pbin="${pfx}/bin/python" +"${pbin}" -m anaconda_anon_usage.install --enable --quiet >>"${pfx}/.messages.txt" 2>&1 || : diff --git a/scripts/pre-unlink.bat b/scripts/pre-unlink.bat index 3aaf5a0..0e6872e 100644 --- a/scripts/pre-unlink.bat +++ b/scripts/pre-unlink.bat @@ -1,3 +1,3 @@ @echo off -if "%CONDA_PREFIX%"=="" (set "pfx=%PREFIX%") else (set "pfx=%CONDA_PREFIX%") -python -m anaconda_anon_usage.install --disable --quiet >>"%pfx%\.messages.txt" 2>&1 && if errorlevel 1 exit 1 +if "%CONDA_PREFIX%"=="" (set pfx="%PREFIX%") else (set "pfx=%CONDA_PREFIX%") +"%pfx%\python.exe" -m anaconda_anon_usage.install --disable --quiet >>"%pfx%\.messages.txt" 2>&1 diff --git a/scripts/pre-unlink.sh b/scripts/pre-unlink.sh index c1fcee9..104db3e 100644 --- a/scripts/pre-unlink.sh +++ b/scripts/pre-unlink.sh @@ -1,4 +1,6 @@ -pfx=${CONDA_PREFIX:-${PREFIX:-}} -pbin=${pfx}/python.exe -[ -f ${pbin} ] || pbin=${pfx}/bin/python -${pbin} -m anaconda_anon_usage.install --disable --quiet >>"${pfx}/.messages.txt" 2>&1 +#!/bin/sh + +pfx="${CONDA_PREFIX:-${PREFIX:-}}" +pbin="${pfx}/python.exe" +[ -f "${pbin}" ] || pbin="${pfx}/bin/python" +"${pbin}" -m anaconda_anon_usage.install --disable --quiet >>"${pfx}/.messages.txt" 2>&1 || :