Skip to content

Commit

Permalink
Merge pull request conda#8550 from mingwandroid/master-4.6.13-stuff
Browse files Browse the repository at this point in the history
Try exiting with 0 on success from conda.bat
  • Loading branch information
msarahan authored Apr 14, 2019
2 parents 36ddbb8 + 79c9258 commit 4f152ee
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 34 deletions.
21 changes: 15 additions & 6 deletions conda.recipe/bld.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
echo %PKG_VERSION% > conda\.version
%PYTHON% setup.py install --single-version-externally-managed --record record.txt
if %errorlevel% neq 0 exit /b %errorlevel%

%PYTHON% -m conda init --install
if %errorlevel% neq 0 exit /b %errorlevel%
copy "%RECIPE_DIR%\build.sh" .
FOR /F "delims=" %%i IN ('cygpath.exe -u "%LIBRARY_PREFIX%"') DO set "LIBRARY_PREFIX=%%i"
SET PREFIXW=%PREFIX%
FOR /F "delims=" %%i IN ('cygpath.exe -u "%PREFIX%"') DO set "PREFIX=%%i"
FOR /F "delims=" %%i IN ('cygpath.exe -u "%PYTHON%"') DO set "PYTHON=%%i"
FOR /F "delims=" %%i IN ('cygpath.exe -u "%RECIPE_DIR%"') DO set "RECIPE_DIR=%%i"
FOR /F "delims=" %%i IN ('cygpath.exe -u "%SP_DIR%"') DO set "SP_DIR=%%i"
FOR /F "delims=" %%i IN ('cygpath.exe -u "%SRC_DIR%"') DO set "SRC_DIR=%%i"
FOR /F "delims=" %%i IN ('cygpath.exe -u "%STDLIB_DIR%"') DO set "STDLIB_DIR=%%i"
set MSYSTEM=MINGW%ARCH%
set MSYS2_PATH_TYPE=inherit
set CHERE_INVOKING=1
bash -lc ./build.sh
if %errorlevel% neq 0 exit /b %errorlevel%
exit /b 0
9 changes: 8 additions & 1 deletion conda.recipe/build.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
#!/bin/bash

echo $PKG_VERSION > conda/.version
$PYTHON setup.py install --single-version-externally-managed --record record.txt
rm -rf "$SP_DIR/conda/shell/*.exe"
if [[ $(uname -o) != Msys ]]; then
rm -rf "$SP_DIR/conda/shell/*.exe"
fi
$PYTHON -m conda init --install
if [[ $(uname -o) == Msys ]]; then
sed -i "s|CONDA_EXE=.*|CONDA_EXE=\'${PREFIXW//\\/\\\\}\\\\Scripts\\\\conda.exe\'|g" $PREFIX/etc/profile.d/conda.sh
fi
84 changes: 59 additions & 25 deletions conda.recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,19 @@ build:
# so we have to exempt them from the list of initial files
# for conda-build to realize they should be included.
always_include_files:
- bin/conda [unix]
- bin/activate [unix]
- bin/deactivate [unix]
- Scripts/activate.bat [win]
- Scripts/activate [win]
- Scripts/deactivate [win]
- bin/conda # [unix]
- bin/activate # [unix]
- bin/deactivate # [unix]
- Scripts/activate.bat # [win]
- Scripts/activate # [win]
- Scripts/deactivate # [win]

requirements:
build:
- m2-filesystem # [win]
- m2-bash # [win]
- m2-base # [win]

host:
- python
- enum34 # [py<34]
Expand Down Expand Up @@ -55,26 +60,41 @@ test:
- pexpect
- responses
- conda-build
- m2-filesystem # [win]
- m2-bash # [win]
- m2-base # [win]
imports:
- conda
- conda_env
commands:
{% if on_win %}
- echo
# - SET CONDA_SHLVL=
# - CALL %PREFIX%\condabin\conda_hook.bat
# - CALL conda.bat activate base
# - FOR /F "delims=" %%i IN ('python -c "import sys; print(sys.version_info[0])"') DO set "PYTHON_MAJOR_VERSION=%%i"
# - set TEST_PLATFORM=win
# - FOR /F "delims=" %%i IN ('python -c "import random as r; print(r.randint(0,4294967296))"') DO set "PYTHONHASHSEED=%%i"
# - set
# - conda info
# - conda create -y -p .\built-conda-test-env
# - CALL conda.bat activate .\built-conda-test-env
# - echo %CONDA_PREFIX%
# - IF NOT "%CONDA_PREFIX%"=="%CD%\built-conda-test-env" EXIT /B 1
# - CALL conda.bat deactivate
# - py.test tests -m "not integration and not installed" -vv
- SET CONDA_SHLVL=
# don't inherit these from the build env setup
- SET _CE_CONDA=
- SET _CE_M=
- SET _CONDA_EXE=
- SET
# CALL stuff is necessary because conda in condabin is a bat script
# running bat files within other bat files requires CALL or else
# the outer script (our test script) exits when the inner completes
- CALL %PREFIX%\condabin\conda_hook.bat
- CALL conda.bat activate base
- FOR /F "delims=" %%i IN ('python -c "import sys; print(sys.version_info[0])"') DO set "PYTHON_MAJOR_VERSION=%%i"
- SET TEST_PLATFORM=win
- FOR /F "delims=" %%i IN ('python -c "import random as r; print(r.randint(0,4294967296))"') DO set "PYTHONHASHSEED=%%i"
- where conda
- CALL conda info
- CALL conda create -y -p .\built-conda-test-env
- CALL conda.bat activate .\built-conda-test-env
- ECHO %CONDA_PREFIX%
- IF NOT "%CONDA_PREFIX%"=="%CD%\built-conda-test-env" EXIT /B 1
- CALL conda deactivate
- SET MSYSTEM=MINGW%ARCH%
- SET MSYS2_PATH_TYPE=inherit
- SET CHERE_INVOKING=1
- FOR /F "delims=" %%i IN ('cygpath.exe -u "%PREFIX%"') DO set "PREFIXP=%%i"
- bash -lc "source %PREFIXP%/Scripts/activate"
- py.test tests -m "not integration and not installed" -vv
{% else %}
- unset CONDA_SHLVL
- eval "$(python -m conda shell.bash hook)"
Expand All @@ -93,15 +113,29 @@ test:
{% endif %}

about:
home: https://conda.io/
license: BSD
home: https://conda.io
license: BSD 3-Clause
license_file: LICENSE.txt
summary: OS-agnostic, system-level binary package and environment manager.
description: |
description: >
Conda is an open source package management system and environment
management system for installing multiple versions of software packages
and their dependencies and switching easily between them. It works on
Linux, OS X and Windows, and was created for Python programs but can
package and distribute any software.
doc_url: http://conda.pydata.org/docs/
doc_url: https://conda.io/projects/conda/en/latest/
dev_url: https://github.com/conda/conda

extra:
recipe-maintainers:
- jakirkham
- jjhelmus
- kalefranz
- mcg1969
- mingwandroid
- msarahan
- mwcraig
- ocefpaf
- patricksnape
- pelson
- scopatz
2 changes: 1 addition & 1 deletion conda/shell/condabin/_conda_activate.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
@IF DEFINED _CE_CONDA (
FOR %%A IN ("%CONDA_EXE%") DO @SET _sysp=%%~dpA
) ELSE (
FOR %%A IN ("%~dp0") DO @SET _sysp=%%~dpA
FOR %%A IN ("%~dp0.") DO @SET _sysp=%%~dpA
)

@IF "%CONDA_PS1_BACKUP%"=="" GOTO FIXUP43
Expand Down
4 changes: 3 additions & 1 deletion conda/shell/condabin/conda.bat
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
@IF DEFINED _CE_CONDA (
FOR %%A IN ("%CONDA_EXE%") DO @SET _sysp=%%~dpA
) ELSE (
FOR %%A IN ("%~dp0") DO @SET _sysp=%%~dpA
FOR %%A IN ("%~dp0.") DO @SET _sysp=%%~dpA
@SET _CE_M=
@SET _CE_CONDA=
@SET "CONDA_EXE=%~dp0..\Scripts\conda.exe"
Expand All @@ -30,3 +30,5 @@
@IF [%1]==[upgrade] "%~dp0_conda_activate" reactivate
@IF [%1]==[remove] "%~dp0_conda_activate" reactivate
@IF [%1]==[uninstall] "%~dp0_conda_activate" reactivate

EXIT /B %errorlevel%
26 changes: 26 additions & 0 deletions docs/source/user-guide/troubleshooting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,32 @@ Troubleshooting
:local:
:depth: 1


Using Conda in Windows Batch script exits early
===============================================

In conda 4.6+, the way that you interact with conda goes through a batch script (``%PREFIX%\condabin\conda.bat``).
Unfortunately, this means it's a little complicated to use conda from other batch scripts. When using batch
scripts from within batch scripts, you must prefix your command with ``CALL``. If you do not do this, your batch
script that calls conda will exit immediately after the conda usage. In other words, if you write this in a .bat file:

.. code-block:: bash
conda create myenv python
conda activate myenv
echo test
Neither the activation, nor the echo will happen. You must write this in your batch script:

.. code-block:: bash
CALL conda create myenv python
CALL conda activate myenv
echo test
This is known behavior with cmd.exe, and we have not found any way to change it. https://stackoverflow.com/questions/4798879/how-do-i-run-a-batch-script-from-within-a-batch-script/4798965


Numpy MKL library load failed
=============================

Expand Down

0 comments on commit 4f152ee

Please sign in to comment.