diff --git a/CMakeLists.txt b/CMakeLists.txt index 24b970e6..07102c21 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.25) project( daisy - VERSION 7.1.3 + VERSION 7.1.4 DESCRIPTION "Mechanistic simulation of agricultural fields" HOMEPAGE_URL https://daisy.ku.dk/ LANGUAGES CXX C @@ -71,7 +71,7 @@ SET(LINKER_OPTIONS "$<$:${LINKER_OPTIONS_PORTABLE}>" ) -if (${OS} STREQUAL "macos") +if (${OS} STREQUAL "macos" OR ${OS} STREQUAL "mingw") set(DAISY_BIN_NAME daisy-bin) else() set(DAISY_BIN_NAME daisy) diff --git a/cmake/MinGW.cmake b/cmake/MinGW.cmake index 6297b26e..aab61ade 100644 --- a/cmake/MinGW.cmake +++ b/cmake/MinGW.cmake @@ -60,3 +60,11 @@ file(COPY ${UV_INSTALLED_PYTHON_ROOT_DIR}/ ) # and install it install(DIRECTORY ${_python_dir}/ TYPE BIN COMPONENT runtime) + +# Install the wrapper script that calls daisy with python +install(PROGRAMS # Ensure executable permission + ${CMAKE_CURRENT_SOURCE_DIR}/scripts/run_daisy_windows.cmd + TYPE BIN + RENAME daisy.cmd + COMPONENT runtime +) diff --git a/doc/README.md b/doc/README.md index 65dd98c6..5929daba 100644 --- a/doc/README.md +++ b/doc/README.md @@ -4,7 +4,6 @@ - [Getting started on MacOS](getting-started-macos.md) - [Getting started on Windows](getting-started-windows.md) -- [Setup python](setup-python.md) - [Setup Visual Studio Code on Windows](setup-vscode.md) - [Setup Textpad](setup-textpad.md) diff --git a/doc/getting-started-windows.md b/doc/getting-started-windows.md index 2314e52a..637c81bc 100644 --- a/doc/getting-started-windows.md +++ b/doc/getting-started-windows.md @@ -8,27 +8,58 @@ The zip file just needs to be unzipped to whatever location you prefer. In the following we will refer to ``. This is the folder where you install Daisy, which is most likely `C:\Program Files\daisy ` if you use the installer. +## Test that it works +Open a shell (either `cmd.exe` or `Powershell` should be fine) and execute the following, remember to replace `` with the path from above +``` +cd \bin +.\daisy.cmd --info +``` +that should display something similar to +``` +.\daisy.cmd --info +1:Daisy crop/soil simulation version 7.1.4. (Mar 16 2026) +Python 3.13.11 +Sample dir: +``` +where `` will be a directory containing sample files illustrating the use of Daisy. + +## Managing Daisy's python environment +Daisy comes with a python environment that allows you to extend Daisy with functions implemented in python. If you need to run Daisy's python interpreter, for example to debug scripts, you can start it using +``` +.\daisy.cmd --python +``` + +You can install additional packages into the environment by calling daisy with `--pip`. To install `numpy` +``` +.\daisy.cmd --pip install numpy +``` + +Anything after `--pip` is passed to `pip`, so to upgrade `numpy` +``` +.\daisy.cmd --pip install --upgrade numpy +``` + +To uninstall `numpy` +``` +.\daisy.cmd --pip uninstall numpy +``` + +If you want to inspect the python environment it is stored under `\bin\Lib`. + +### Repair pip +If `pip` does not work, you can repair it with +``` +.\daisy.cmd --repair-pip +``` + +and +``` +.\daisy.cmd --pip install --upgrade pip +``` +to upgrade it. + ## Setting up an environment for running Daisy You can run Daisy from the commandline, but we recommend that you use an editor like [VSCode](https://code.visualstudio.com). See [instructions for setting up VSCode](setup-vscode.md). - -## Running your first Daisy program -Several sample programs are included in the Daisy distribution. These are located in the directory `sample` under `` - -1. Create a new directory named `daisy` on your Desktop -2. Copy the file `test.dai` from the `sample` directory to the newly created `daisy` directory -3. Open the `test.dai` file from the `daisy` directory in your editor -4. Run the `test.dai` file. This should produce the following files in the `daisy` directory - - `checkpoint-1987-8-7+6.dai`. - the state of the simulation. Can be used to hot start the simulation. - - `daisy.log` - Log of the simulation that was just run - - `field_nitrogen.dlf` - - `field_water.dlf` - - `harvest.dlf` - - `sbarley.dlf` - - `soil_nitrogen.dlf` - - `soil_water.dlf` - -The `.dlf` files are the output of the simulation. These are tab separated files with a custom header that can be read into spreadsheet applications or with you favorite programming language. We recommend using [RStudio](https://posit.co/downloads) with the [daisyrVis](https://github.com/daisy-model/daisyrVis) package or Python with the [daisypy-vis](https://github.com/daisy-model/daisypy-vis) package. +Once you have set up an editor you can try [running your first daisy program](running-your-first-daisy-program.md). diff --git a/scripts/run_daisy_windows.cmd b/scripts/run_daisy_windows.cmd new file mode 100644 index 00000000..e73f5c40 --- /dev/null +++ b/scripts/run_daisy_windows.cmd @@ -0,0 +1,138 @@ +@echo off +rem Daisy Windows launcher (single-file CMD) +rem - --info : print Daisy+Python info +rem - --pip ... : run pip inside the bundled Python (adds --no-warn-script-location on install) +rem - --python.. : run the bundled Python +rem - --repair-pip : try to fix pip by removing any old pip and installing again +rem - default : run daisy-bin.exe with all remaining args + +setlocal + +rem ----- resolve directories ----- +set "SCRIPT_DIR=%~dp0" +for %%I in ("%SCRIPT_DIR%") do set "ABS_DIR=%%~fI" +for %%I in ("%SCRIPT_DIR%\..\sample") do set "SAMPLE_DIR=%%~fI" + +set "DAISY=%ABS_DIR%\daisy-bin.exe" +set "PYTHONHOME=%ABS_DIR%" +set "PYTHON=%PYTHONHOME%\python.exe" + +rem ----- DAISYHOME: honor env if already set ----- +if defined DAISYHOME ( + set "DAISYHOME=%DAISYHOME%" +) else ( + for %%I in ("%ABS_DIR%\..") do set "DAISYHOME=%%~fI" +) + +rem ======================= +rem ARGUMENT PARSING +rem ======================= +set "MODE=%~1" +shift + +rem First argument after MODE (used by --pip) +set "FIRST=" +if not "%~1"=="" set "FIRST=%~1" + +rem Collect remaining args (quoted per token) +set "ARGS=" +:__argloop +if "%~1"=="" goto __after_args +set "ARGS=%ARGS% "%~1"" +shift +goto __argloop +:__after_args + +rem ======================= +rem DISPATCH +rem ======================= +if "%MODE%"=="--info" goto do_info +if "%MODE%"=="--pip" goto do_pip +if "%MODE%"=="--python" goto do_python +if "%MODE%"=="--repair-pip" goto do_repairpip +goto do_default + +rem ======================= +rem HANDLERS +rem ======================= + +rem ========================== +rem info mode +rem ========================== +:do_info +set "PYTHONHOME=%PYTHONHOME%" +rem Show only the first line of 'daisy -v' +"%DAISY%" -v 2>&1 | findstr /n ".*" | findstr /b "1:" +if exist ".\daisy.log" del ".\daisy.log" >nul 2>&1 +"%PYTHON%" --version +echo Sample dir: %SAMPLE_DIR% +exit /b %ERRORLEVEL% + +rem ========================== +rem pip mode +rem ========================== +:do_pip +set "PYTHONHOME=%PYTHONHOME%" +set "PYTHONPATH=" +set "PYTHONNOUSERSITE=1" + +if /i "%FIRST%"=="install" ( + "%PYTHON%" -I -m pip %ARGS% --no-warn-script-location +) else ( + if not "%ARGS%"=="" ( + "%PYTHON%" -I -m pip %ARGS% + ) else ( + "%PYTHON%" -I -m pip + ) +) +exit /b %ERRORLEVEL% + + +rem ========================== +rem python mode +rem ========================== +:do_python +"%PYTHON%" %ARGS% +exit /b %ERRORLEVEL% + +:do_default +set "PYTHONHOME=%PYTHONHOME%" +set "DAISYHOME=%DAISYHOME%" + +rem Reconstruct the original argv for Daisy: +if "%MODE%"=="" ( + "%DAISY%" %ARGS% +) else ( + "%DAISY%" "%MODE%" %ARGS% +) +exit /b %ERRORLEVEL% + + +rem ========================== +rem pip repair mode +rem ========================== +:do_repairpip +set "PYTHONHOME=%PYTHONHOME%" +set "PYTHONPATH=" +set "PYTHONNOUSERSITE=1" + +echo [daisy] Repairing embedded pip... + +rem Remove pip/ directory +if exist "%PYTHONHOME%\Lib\site-packages\pip" ( + echo Removing pip package directory... + rmdir /s /q "%PYTHONHOME%\Lib\site-packages\pip" +) + +rem Remove pip-*.dist-info directories +for /d %%D in ("%PYTHONHOME%\Lib\site-packages\pip-*.dist-info") do ( + echo Removing %%~fD ... + rmdir /s /q "%%~fD" +) + +rem Rebuild pip cleanly +echo Reinstalling pip via ensurepip... +"%PYTHON%" -I -m ensurepip --upgrade + +echo Pip repair completed. +exit /b 0