From 7fbb868d68be425227559041e88b9a28df2e29e2 Mon Sep 17 00:00:00 2001 From: Mohamed Salah Date: Sat, 31 Jan 2026 17:05:24 +0200 Subject: [PATCH] Modernize build commands for setuptools 80+ compatibility Replace deprecated setup.py develop commands with modern pip equivalents: - Replace 'setup.py develop --uninstall' with 'pip uninstall -y monai' - Replace 'setup.py develop' with 'pip install -e .' - Remove setuptools upper bound for Python 3.12+ (previously <=79.0.1) - Add BUILD_MONAI=1 explicitly in compile_cpp to ensure C++/CUDA extensions build - Remove --user flag from editable installs for virtualenv compatibility In setuptools 80+, the 'setup.py develop --uninstall' command was removed as part of PEP 660 modernization. The build system now delegates to pip for all installation and uninstallation operations. When using 'pip install -e .', the BUILD_MONAI environment variable must be set explicitly to trigger C++/CUDA compilation, as it's not automatically inherited due to pip's build isolation. The --user flag is removed from editable installs because it breaks inside virtualenvs (the modern development standard). Without --user, pip installs into the active virtualenv when present, or prompts for sudo when needed. Changes made: - runtests.sh: Updated compile_cpp() and clean_py() to use pip commands, set BUILD_MONAI=1 explicitly, and removed --user flag - requirements-min.txt: Removed setuptools <=79.0.1 upper bound for Python 3.12+ - docs/source/installation.md: Updated editable installation examples - .github/workflows/pythonapp.yml: Updated CI workflow to use pip commands Fixes #8439 Signed-off-by: Mohamed Salah --- .github/workflows/pythonapp.yml | 4 ++-- docs/source/installation.md | 8 ++++---- requirements-min.txt | 2 +- runtests.sh | 10 +++++----- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/workflows/pythonapp.yml b/.github/workflows/pythonapp.yml index 5fdec1e11e..8bbf155beb 100644 --- a/.github/workflows/pythonapp.yml +++ b/.github/workflows/pythonapp.yml @@ -91,8 +91,8 @@ jobs: shell: bash - name: Run compiled (${{ runner.os }}) run: | - python setup.py develop --uninstall - BUILD_MONAI=1 python setup.py develop # compile the cpp extensions + python -m pip uninstall -y monai + BUILD_MONAI=1 python -m pip install -e . # compile the cpp extensions shell: bash - name: Run quick tests (CPU ${{ runner.os }}) run: | diff --git a/docs/source/installation.md b/docs/source/installation.md index b8befc10b4..646b34a23f 100644 --- a/docs/source/installation.md +++ b/docs/source/installation.md @@ -135,23 +135,23 @@ You can install it by running: ```bash cd MONAI/ -python setup.py develop +pip install -e . ``` or, to build with MONAI C++/CUDA extensions and install: ```bash cd MONAI/ -BUILD_MONAI=1 python setup.py develop +BUILD_MONAI=1 pip install -e . # for MacOS -BUILD_MONAI=1 CC=clang CXX=clang++ python setup.py develop +BUILD_MONAI=1 CC=clang CXX=clang++ pip install -e . ``` To uninstall the package please run: ```bash cd MONAI/ -python setup.py develop --uninstall +pip uninstall -y monai # to further clean up the MONAI/ folder (Bash script) ./runtests.sh --clean diff --git a/requirements-min.txt b/requirements-min.txt index afc1bf6e07..21cf9d5e5c 100644 --- a/requirements-min.txt +++ b/requirements-min.txt @@ -1,7 +1,7 @@ # Requirements for minimal tests -r requirements.txt setuptools>=50.3.0,<66.0.0,!=60.6.0 ; python_version < "3.12" -setuptools>=70.2.0,<=79.0.1; python_version >= "3.12" +setuptools>=70.2.0; python_version >= "3.12" coverage>=5.5 parameterized packaging diff --git a/runtests.sh b/runtests.sh index 18cb0ab73a..ccf6400a7a 100755 --- a/runtests.sh +++ b/runtests.sh @@ -73,7 +73,7 @@ function print_usage { echo "./runtests.sh -f # run coding style and static type checking." echo "./runtests.sh --quick --unittests # run minimal unit tests, for quick verification during code developments." echo "./runtests.sh --autofix # run automatic code formatting using \"isort\" and \"black\"." - echo "./runtests.sh --clean # clean up temporary files and run \"${PY_EXE} setup.py develop --uninstall\"." + echo "./runtests.sh --clean # clean up temporary files and uninstall MONAI development package." echo "./runtests.sh --formatfix -p /my/code # run automatic code formatting using \"isort\" and \"black\" in specified path." echo "" echo "Code style check options:" @@ -143,12 +143,12 @@ function compile_cpp { echo "Compiling and installing MONAI cpp extensions..." # depends on setup.py behaviour for building # currently setup.py uses environment variables: BUILD_MONAI and FORCE_CUDA - ${cmdPrefix}"${PY_EXE}" setup.py develop --user --uninstall + ${cmdPrefix}"${PY_EXE}" -m pip uninstall -y monai if [[ "$OSTYPE" == "darwin"* ]]; then # clang for mac os - CC=clang CXX=clang++ ${cmdPrefix}"${PY_EXE}" setup.py develop --user + BUILD_MONAI=1 CC=clang CXX=clang++ ${cmdPrefix}"${PY_EXE}" -m pip install -e . else - ${cmdPrefix}"${PY_EXE}" setup.py develop --user + BUILD_MONAI=1 ${cmdPrefix}"${PY_EXE}" -m pip install -e . fi } @@ -179,7 +179,7 @@ function clean_py { # uninstall the development package echo "Uninstalling MONAI development files..." - ${cmdPrefix}"${PY_EXE}" setup.py develop --user --uninstall + ${cmdPrefix}"${PY_EXE}" -m pip uninstall -y monai # remove temporary files (in the directory of this script) TO_CLEAN="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"