Skip to content

Commit

Permalink
Merge branch 'uv' into 'master'
Browse files Browse the repository at this point in the history
[py] Use uv over pip.

See merge request ogs/ogs!5139
  • Loading branch information
endJunction committed Oct 23, 2024
2 parents ebd40a7 + 15086dc commit b919636
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 28 deletions.
2 changes: 1 addition & 1 deletion ProcessLib/PhaseField/Tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ AddTest(

if(OGS_USE_PETSC)
NotebookTest(NOTEBOOKFILE PhaseField/surfing_jupyter_notebook/surfing_pyvista.ipynb RUNTIME 25)
NotebookTest(NOTEBOOKFILE PhaseField/beam_jupyter_notebook/beam.ipynb RUNTIME 500 PROPERTIES PROCESSORS 3)
NotebookTest(NOTEBOOKFILE PhaseField/beam_jupyter_notebook/beam.ipynb RUNTIME 1200 PROPERTIES PROCESSORS 3)
NotebookTest(NOTEBOOKFILE PhaseField/tpb_jupyter_notebook/TPB.ipynb RUNTIME 110 PROPERTIES PROCESSORS 4)
NotebookTest(NOTEBOOKFILE PhaseField/kregime_jupyter_notebook/Kregime_Static_jupyter.ipynb RUNTIME 40)
NotebookTest(NOTEBOOKFILE PhaseField/PForthotropy_jupyter_notebook/sen_shear.ipynb RUNTIME 500 PROPERTIES PROCESSORS 4)
Expand Down
3 changes: 2 additions & 1 deletion ProcessLib/SmallDeformation/Tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ if (OGS_USE_MFRONT)
)
OgsTest(PROJECTFILE Mechanics/MohrCoulombAbboSloan/load_test_mc.prj)
if (OGS_USE_MPI)
OgsTest(WRAPPER mpirun -np 4 PROJECTFILE Mechanics/MohrCoulombAbboSloan/PetscMpi/slope_hexa.prj)
OgsTest(WRAPPER mpirun -np 4 PROJECTFILE Mechanics/MohrCoulombAbboSloan/PetscMpi/slope_hexa.prj
RUNTIME 1200)
endif()
OgsTest(PROJECTFILE Mechanics/MohrCoulombAbboSloanAnisotropic/triax_1e0_47.prj)
OgsTest(PROJECTFILE Mechanics/MohrCoulombAbboSloanAnisotropic/triax_ortho_1e0_47.prj)
Expand Down
3 changes: 0 additions & 3 deletions Tests/Data/requirements-gmsh-nox.txt

This file was deleted.

2 changes: 1 addition & 1 deletion scripts/ci/jobs/build-wheels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,6 @@ test notebooks via wheel:
- python3.10 -m venv --upgrade-deps .venv
- source .venv/bin/activate
- pip install -r requirements.txt
- pip install --force-reinstall -r requirements-gmsh-nox.txt
- pip install --force-reinstall --pre --index-url https://gmsh.info/python-packages-dev-nox "gmsh>=4.11"
- pip install -r requirements-dev.txt
- pip install ${CI_PROJECT_DIR}/wheelhouse/ogs-*-cp310-cp310-manylinux_2_28_x86_64.whl
2 changes: 1 addition & 1 deletion scripts/ci/jobs/jupyter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ test notebooks via wheel:
- python -m venv --upgrade-deps .venv
- source .venv/bin/activate
- pip install -r requirements.txt
- pip install --force-reinstall -r requirements-gmsh-nox.txt
- pip install --force-reinstall --pre --index-url https://gmsh.info/python-packages-dev-nox "gmsh>=4.11"
- pip install -r requirements-dev.txt
- pip install -r requirements-ogs.txt
script:
Expand Down
18 changes: 14 additions & 4 deletions scripts/cmake/PythonCreateVirtualEnv.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
# cmake-lint: disable=C0103
message(STATUS "┌─ PythonCreateVirtualEnv.cmake")
list(APPEND CMAKE_MESSAGE_INDENT "│ ")

# Prefer more recent Python version
set(Python_FIND_STRATEGY VERSION)
Expand All @@ -14,9 +12,21 @@ if(${Python_VERSION} VERSION_GREATER_EQUAL 3.9)
set(_upgrade_deps --upgrade-deps)
endif()

if(UV_TOOL_PATH)
set(_create_venv_command ${UV_TOOL_PATH} venv --python ${Python_EXECUTABLE})
set(_venv_tool "uv")
else()
set(_create_venv_command ${Python_EXECUTABLE} -m venv ${_upgrade_deps}
.venv
)
set(_venv_tool "pip")
endif()

message(STATUS "┌─ PythonCreateVirtualEnv.cmake (using ${_venv_tool})")
list(APPEND CMAKE_MESSAGE_INDENT "│ ")

execute_process(
COMMAND ${Python_EXECUTABLE} -m venv ${_upgrade_deps} .venv
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
COMMAND ${_create_venv_command} WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
)

list(POP_BACK CMAKE_MESSAGE_INDENT)
Expand Down
56 changes: 39 additions & 17 deletions scripts/cmake/PythonSetup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,39 @@

if(OGS_USE_PIP)
set(LOCAL_VIRTUALENV_DIR ${PROJECT_BINARY_DIR}/.venv CACHE INTERNAL "")
set(_venv_bin_dir "bin")
if(MSVC)
set(_venv_bin_dir "Scripts")
endif()
set(LOCAL_VIRTUALENV_BIN_DIR ${LOCAL_VIRTUALENV_DIR}/${_venv_bin_dir}
CACHE INTERNAL ""
)
set(Python_ROOT_DIR ${LOCAL_VIRTUALENV_DIR})
set(CMAKE_REQUIRE_FIND_PACKAGE_Python TRUE)
find_program(UV_TOOL_PATH uv)
if(UV_TOOL_PATH)
set(_pip_install_command ${UV_TOOL_PATH} pip install --prefix
${LOCAL_VIRTUALENV_DIR} CACHE INTERNAL ""
)
set(_pip_uninstall_command ${UV_TOOL_PATH} pip uninstall --prefix
${LOCAL_VIRTUALENV_DIR} CACHE INTERNAL ""
)
set(_venv_tool "uv")
else()
set(_pip_install_command ${LOCAL_VIRTUALENV_BIN_DIR}/pip install
CACHE INTERNAL ""
)
set(_pip_uninstall_command ${LOCAL_VIRTUALENV_BIN_DIR}/pip uninstall
--yes CACHE INTERNAL ""
)
set(_venv_tool "pip")
endif()
if(NOT EXISTS ${LOCAL_VIRTUALENV_DIR})
execute_process(
COMMAND
${CMAKE_COMMAND} -DPROJECT_BINARY_DIR=${PROJECT_BINARY_DIR}
-Dpython_version=${ogs.minimum_version.python} -P
-Dpython_version=${ogs.minimum_version.python}
-DUV_TOOL_PATH=${UV_TOOL_PATH} -P
${PROJECT_SOURCE_DIR}/scripts/cmake/PythonCreateVirtualEnv.cmake
WORKING_DIRECTORY ${PROJECT_BINARY_DIR} COMMAND_ECHO STDOUT
ECHO_OUTPUT_VARIABLE ECHO_ERROR_VARIABLE
Expand All @@ -23,16 +49,9 @@ if(OGS_USE_PIP)
endif()
unset(_OGS_PYTHON_PACKAGES_SHA1 CACHE)
endif()
set(_venv_bin_dir "bin")
if(MSVC)
set(_venv_bin_dir "Scripts")
endif()
set(LOCAL_VIRTUALENV_BIN_DIR ${LOCAL_VIRTUALENV_DIR}/${_venv_bin_dir}
CACHE INTERNAL ""
)
# Fixes macOS install issues
execute_process(
COMMAND ${LOCAL_VIRTUALENV_BIN_DIR}/pip install wheel
COMMAND ${_pip_install_command} wheel
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
)
# Create jupytext config
Expand Down Expand Up @@ -124,16 +143,15 @@ function(setup_venv)
)
message(
STATUS
"Installing Python packages into local virtual environment..."
"Installing Python packages into local virtual environment using ${_venv_tool} ..."
)
if(APPLE)
# CC=/Library/Developer/CommandLineTools/usr/bin/cc and this somehow
# breaks wheel builds ...
set(_apple_env ${CMAKE_COMMAND} -E env CC=clang CXX=clang)
endif()
execute_process(
COMMAND ${_apple_env} ${LOCAL_VIRTUALENV_BIN_DIR}/pip install -r
requirements.txt
COMMAND ${_apple_env} ${_pip_install_command} -r requirements.txt
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
RESULT_VARIABLE _return_code
OUTPUT_VARIABLE _out
Expand All @@ -152,11 +170,15 @@ function(setup_venv)
)
endif()
if(DEFINED ENV{CI} AND UNIX AND NOT APPLE)
set(_pip_gmsh_flags --force-reinstall --pre)
if(UV_TOOL_PATH)
set(_pip_gmsh_flags --reinstall --prerelease=allow)
endif()
execute_process(
COMMAND
${_apple_env} ${LOCAL_VIRTUALENV_BIN_DIR}/pip install
--force-reinstall -r
${PROJECT_SOURCE_DIR}/Tests/Data/requirements-gmsh-nox.txt
${_apple_env} ${_pip_install_command} ${_pip_gmsh_flags}
--index-url https://gmsh.info/python-packages-dev-nox
"gmsh>=4.11"
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
RESULT_VARIABLE _return_code
OUTPUT_VARIABLE _out
Expand All @@ -177,8 +199,8 @@ function(setup_venv)
endif()
# Uninstall ogs wheel
execute_process(
COMMAND ${_apple_env} ${LOCAL_VIRTUALENV_BIN_DIR}/pip uninstall
--yes ogs WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
COMMAND ${_apple_env} ${_pip_uninstall_command} ogs
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
)
endif()
endfunction()
Expand Down
7 changes: 7 additions & 0 deletions scripts/cmake/test/NotebookTest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ function(NotebookTest)

if(NOT DEFINED NotebookTest_RUNTIME)
set(NotebookTest_RUNTIME 1)
elseif(NotebookTest_RUNTIME GREATER 750)
# Set a timeout on jobs larger than the default ctest timeout of 1500
# (s). The allowed runtime is twice as long as the given RUNTIME
# parameter.
math(EXPR timeout "${NotebookTest_RUNTIME} * 2")
set(timeout TIMEOUT ${timeout})
endif()

if(DEFINED OGS_CTEST_MAX_RUNTIME)
Expand Down Expand Up @@ -131,6 +137,7 @@ function(NotebookTest)
${NotebookTest_DISABLED}
LABELS
"${labels}"
${timeout}
ENVIRONMENT
"CI=1;PYDEVD_DISABLE_FILE_VALIDATION=1"
)
Expand Down

0 comments on commit b919636

Please sign in to comment.