Skip to content

Commit 148b437

Browse files
committed
build: support uv.lock
1 parent 9b09bf1 commit 148b437

File tree

7 files changed

+118
-122
lines changed

7 files changed

+118
-122
lines changed

Jenkinsfile

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -466,11 +466,10 @@ pipeline {
466466
script: '''python3 -m venv bootstrap_uv
467467
bootstrap_uv/bin/pip install --disable-pip-version-check uv
468468
bootstrap_uv/bin/uv venv venv
469-
. ./venv/bin/activate
470-
bootstrap_uv/bin/uv pip install uv
469+
UV_PROJECT_ENVIRONMENT=./venv uv sync --frozen --group ci --no-install-project
470+
bootstrap_uv/bin/uv pip install --python=./venv/bin/python uv
471471
rm -rf bootstrap_uv
472-
uv pip install -r requirements-dev.txt
473-
'''
472+
'''
474473
)
475474
}
476475
}
@@ -776,20 +775,18 @@ pipeline {
776775
milestone 1
777776
script{
778777
withSonarQubeEnv(installationName:'sonarcloud', credentialsId: params.SONARCLOUD_TOKEN) {
779-
if (env.CHANGE_ID){
780-
sh(
781-
label: 'Running Sonar Scanner',
782-
script: """. ./venv/bin/activate
783-
uvx pysonar-scanner -Dsonar.projectVersion=\$VERSION -Dsonar.buildString=\"${env.BUILD_TAG}\" -Dsonar.pullrequest.key=${env.CHANGE_ID} -Dsonar.pullrequest.base=${env.CHANGE_TARGET} -Dsonar.cfamily.cache.enabled=false -Dsonar.cfamily.threads=\$(grep -c ^processor /proc/cpuinfo) -Dsonar.cfamily.build-wrapper-output=build/build_wrapper_output_directory
784-
"""
785-
)
786-
} else {
787-
sh(
788-
label: 'Running Sonar Scanner',
789-
script: """. ./venv/bin/activate
790-
uvx pysonar-scanner -Dsonar.projectVersion=\$VERSION -Dsonar.buildString=\"${env.BUILD_TAG}\" -Dsonar.branch.name=${env.BRANCH_NAME} -Dsonar.cfamily.cache.enabled=false -Dsonar.cfamily.threads=\$(grep -c ^processor /proc/cpuinfo) -Dsonar.cfamily.build-wrapper-output=build/build_wrapper_output_directory
791-
"""
792-
)
778+
withCredentials([string(credentialsId: params.SONARCLOUD_TOKEN, variable: 'token')]) {
779+
if (env.CHANGE_ID){
780+
sh(
781+
label: 'Running Sonar Scanner',
782+
script: "./venv/bin/uvx pysonar -t \$token -Dsonar.projectVersion=\$VERSION -Dsonar.buildString=\"${env.BUILD_TAG}\" -Dsonar.pullrequest.key=${env.CHANGE_ID} -Dsonar.pullrequest.base=${env.CHANGE_TARGET} -Dsonar.cfamily.cache.enabled=false -Dsonar.cfamily.threads=\$(grep -c ^processor /proc/cpuinfo) -Dsonar.cfamily.build-wrapper-output=build/build_wrapper_output_directory"
783+
)
784+
} else {
785+
sh(
786+
label: 'Running Sonar Scanner',
787+
script: "./venv/bin/uvx pysonar -t \$token -Dsonar.projectVersion=\$VERSION -Dsonar.buildString=\"${env.BUILD_TAG}\" -Dsonar.branch.name=${env.BRANCH_NAME} -Dsonar.cfamily.cache.enabled=false -Dsonar.cfamily.threads=\$(grep -c ^processor /proc/cpuinfo) -Dsonar.cfamily.build-wrapper-output=build/build_wrapper_output_directory"
788+
)
789+
}
793790
}
794791
}
795792
timeout(time: 1, unit: 'HOURS') {

pyproject.toml

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,32 @@ classifiers = [
3939
Documentation = "https://www.library.illinois.edu/dccdocs/imagevalidate"
4040
Download = "https://github.com/UIUCLibrary/imagevalidate"
4141

42+
[dependency-groups]
43+
docs = ["sphinx"]
44+
type_checking = [
45+
"mypy",
46+
"lxml",
47+
]
48+
lint = [
49+
{include-group = "type_checking"},
50+
"flake8",
51+
]
52+
tox = ["tox"]
53+
test = ["coverage[toml]", "gcovr", "pytest"]
54+
conan = ["conan>=2.0", "cmake<4.0"]
55+
dev = [
56+
{include-group = "conan"},
57+
{include-group = "docs"},
58+
{include-group = "lint"},
59+
{include-group = "test"},
60+
]
61+
release = ["twine"]
62+
ci = [
63+
{include-group = "release"},
64+
{include-group = "dev"},
65+
"pysonar",
66+
]
67+
package = ["delocate ; sys_platform == 'darwin'"]
4268
[tool.setuptools]
4369
packages = [
4470
"uiucprescon.imagevalidate",
@@ -131,4 +157,16 @@ CONAN_BUILD_INFO_DIR="/tmp/conan/build/"
131157
PYTHONFAULTHANDLER="True"
132158

133159
[tool.uv]
134-
cache-keys = [{ file = "pyproject.toml" }, { file = "requirements-dev.txt" }, { file = "setup.py" }, { dir = "/Users/hborcher/CLionProjects/henryborchers/uiucprescon_build" }]
160+
cache-keys = [{ file = "pyproject.toml" }, { file = "requirements-dev.txt" }, { file = "setup.py" }, { dir = "/Users/hborcher/CLionProjects/henryborchers/uiucprescon_build" }]
161+
162+
[tool.uv.sources]
163+
py3exiv2bind = {index = "uiuc_prescon_python"}
164+
165+
[[tool.uv.index]]
166+
url = "https://pypi.org/simple"
167+
default = true
168+
169+
[[tool.uv.index]]
170+
name = "uiuc_prescon_python"
171+
url = "https://nexus.library.illinois.edu/repository/uiuc_prescon_python/simple"
172+
explicit = true

scripts/build_linux_wheels.sh

Lines changed: 36 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,33 @@ DEFAULT_PYTHON_VERSION="3.10"
77
DOCKERFILE=$(realpath "$scriptDir/resources/package_for_linux/Dockerfile")
88
DEFAULT_DOCKER_IMAGE_NAME="uiucprescon_imagevalidate_builder"
99
OUTPUT_PATH="$PROJECT_ROOT/dist"
10-
DEFAULT_BUILD_CONSTRAINTS="requirements-dev.txt"
1110
REMOVE_DIRS_FIRST=( \
1211
'uiucprescon.imagevalidate.egg-info' \
1312
'build' \
13+
'cmake-build-debug' \
1414
)
1515

16-
REMOVE_FILES_FIRST=(
17-
'CMakeUserPresets.json'
16+
SKIP_DIRS_NAMED=(\
17+
'.venv' \
18+
'venv' \
19+
'.tox' \
20+
'.git' \
21+
'.idea' \
22+
'reports' \
23+
'.mypy_cache' \
24+
'__pycache__' \
25+
'wheelhouse' \
26+
'.pytest_cache' \
27+
'uiucprescon.imagevalidate.egg-info'\
28+
'build' \
29+
)
30+
31+
REMOVE_FILES_FIRST=( \
32+
'CMakeUserPresets.json' \
33+
'CMakePresets.json' \
34+
'conan_toolchain.cmake' \
35+
'CTestTestfile.cmake' \
36+
'conandeps_legacy.cmake'
1837
)
1938

2039
arch=$(uname -m)
@@ -35,8 +54,7 @@ esac
3554
generate_wheel(){
3655
platform=$1
3756
local docker_image_name_to_use=$2
38-
local constraints_file=$3
39-
local python_versions_to_use=("${@:4}")
57+
local python_versions_to_use=("${@:3}")
4058

4159
case $platform in
4260
linux/amd64)
@@ -59,23 +77,26 @@ generate_wheel(){
5977
--build-arg PIP_INDEX_URL \
6078
--build-arg UV_EXTRA_INDEX_URL \
6179
--build-arg UV_INDEX_URL \
62-
--build-arg UV_CONSTRAINT=$constraints_file \
6380
--build-arg manylinux_image=$manylinux_image \
6481
"$PROJECT_ROOT"
6582

6683
mkdir -p "$OUTPUT_PATH"
6784
echo "Building wheels for Python versions: ${python_versions_to_use[*]}"
6885
CONTAINER_WORKSPACE=/tmp/workspace
6986
COMMAND="echo 'Making a shadow copy to prevent modifying local files' && \
87+
prune_expr=() && \
88+
for name in "${SKIP_DIRS_NAMED[@]}"; do \
89+
prune_expr+=(-name \"\$name\" -type d -prune -o); \
90+
done && \
7091
mkdir -p ${CONTAINER_WORKSPACE} && \
71-
lndir -silent /project/ ${CONTAINER_WORKSPACE} && \
72-
for d in "${REMOVE_DIRS_FIRST[@]}"; do
73-
OFFENDING_PATH=${CONTAINER_WORKSPACE}/\$d
74-
if [ -d \"\$OFFENDING_PATH\" ]; then
75-
echo \"Removing copy from temporary working path to avoid issues: \$OFFENDING_PATH\";
76-
rm -rf \$OFFENDING_PATH;
77-
fi; \
92+
(cd /project/ && \
93+
find . \"\${prune_expr[@]}\" -type d -print | while read -r dir; do \
94+
mkdir -p \"${CONTAINER_WORKSPACE}/\$dir\"
7895
done && \
96+
find . \"\${prune_expr[@]}\" \( -type f -o -type l \) -print | while read -r file; do \
97+
echo \"\$file\"
98+
ln -sf "/project/\$file" \"${CONTAINER_WORKSPACE}/\$file\"
99+
done) && \
79100
for f in "${REMOVE_FILES_FIRST[@]}"; do
80101
OFFENDING_FILE=${CONTAINER_WORKSPACE}/\$f
81102
if [ -f \"\$OFFENDING_FILE\" ]; then
@@ -88,7 +109,7 @@ generate_wheel(){
88109
find ${CONTAINER_WORKSPACE} -type f -name '*.pyc' -exec rm -f {} + && \
89110
for i in "${python_versions_to_use[@]}"; do
90111
echo \"Creating wheel for Python version: \$i\";
91-
uv build --python=\$i --python-preference=system --build-constraints=/project/$constraints_file --wheel --out-dir=/tmp/dist ${CONTAINER_WORKSPACE};
112+
uv build --python=\$i --python-preference=system --wheel --out-dir=/tmp/dist ${CONTAINER_WORKSPACE};
92113
if [ \$? -ne 0 ]; then
93114
echo \"Failed to build wheel for Python \$i\";
94115
exit 1;
@@ -128,10 +149,6 @@ show_help() {
128149
echo " --docker-image-name "
129150
echo " : Name of the Docker image to use for building the wheel. "
130151
echo " Defaults to \"$DEFAULT_DOCKER_IMAGE_NAME\". "
131-
echo " --build-constraints-file "
132-
echo " : File to use for build constraints. This must be within the "
133-
echo " root of the repository. "
134-
echo " Defaults to \"$DEFAULT_BUILD_CONSTRAINTS\" "
135152
echo " --help, -h : Display this help message. "
136153
}
137154

@@ -147,23 +164,6 @@ check_args(){
147164
exit 1
148165
fi
149166

150-
if [[ "$build_constraints_file" = /* ]]; then
151-
echo "The build constraints file '$build_constraints_file' cannot be an absolute path."
152-
exit 1
153-
fi
154-
155-
if [[ ! -f "$build_constraints_file" ]]; then
156-
echo "No valid file found at $build_constraints_file"
157-
exit 1
158-
fi
159-
160-
# Check if the resolved path is within the source repository
161-
if [[ ! $(realpath "$build_constraints_file") == "$PROJECT_ROOT"* ]]; then
162-
echo "Error: The path '$build_constraints_file' is not within the source repository."
163-
exit 1
164-
fi
165-
166-
167167
}
168168
# === Main script starts here ===
169169

@@ -188,14 +188,6 @@ while [[ "$#" -gt 0 ]]; do
188188
PROJECT_ROOT="$2"
189189
shift 2
190190
;;
191-
--build-constraints-file=*)
192-
build_constraints_file="${1#*=}"
193-
shift
194-
;;
195-
--build-constraints-file)
196-
build_constraints_file="${2}"
197-
shift 2
198-
;;
199191
--docker-image-name=*)
200192
docker_image_name="${1#*=}"
201193
shift
@@ -255,10 +247,5 @@ if [[ ! -v docker_image_name ]]; then
255247
else
256248
echo "Using '$docker_image_name' for the name of the Docker Image generated to build."
257249
fi
258-
if [[ -z "$build_constraints_file" ]]; then
259-
build_constraints_file=$DEFAULT_BUILD_CONSTRAINTS
260-
else
261-
echo "Using '$build_constraints_file' for constraints file."
262-
fi
263250
check_args
264-
generate_wheel $PLATFORM $docker_image_name $build_constraints_file ${python_versions[@]}
251+
generate_wheel $PLATFORM $docker_image_name ${python_versions[@]}

scripts/build_mac_wheel.sh

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
INSTALLED_UV=$(command -v uv)
33
DEFAULT_PYTHON_VENV="./wheel_builder_venv"
44
DEFAULT_BASE_PYTHON="python3"
5-
REQUIREMENTS_FILE="requirements-dev.txt"
5+
scriptDir=$(dirname -- "$(readlink -f -- "$BASH_SOURCE")")
6+
PROJECT_ROOT=$(realpath "$scriptDir/..")
67
set -e
78

89
remove_venv(){
@@ -12,15 +13,6 @@ remove_venv(){
1213
fi
1314
}
1415

15-
generate_venv(){
16-
base_python=$1
17-
virtual_env=$2
18-
trap "remove_venv $virtual_env" ERR SIGINT SIGTERM
19-
$base_python -m venv $virtual_env
20-
$virtual_env/bin/pip install --disable-pip-version-check uv
21-
. $virtual_env/bin/activate
22-
}
23-
2416
generate_wheel_with_uv(){
2517
uv=$1
2618
project_root=$2
@@ -54,29 +46,28 @@ generate_wheel_with_uv(){
5446
out_temp_wheels_dir=$(mktemp -d /tmp/python_wheels.XXXXXX)
5547
output_path="./dist"
5648
trap "rm -rf $out_temp_wheels_dir" ERR SIGINT SIGTERM RETURN
57-
UV_INDEX_STRATEGY=unsafe-best-match _PYTHON_HOST_PLATFORM=$_PYTHON_HOST_PLATFORM MACOSX_DEPLOYMENT_TARGET=$MACOSX_DEPLOYMENT_TARGET ARCHFLAGS=$ARCHFLAGS $uv build --python=$pythonVersion --build-constraints $REQUIREMENTS_FILE --wheel --out-dir=$out_temp_wheels_dir $project_root
49+
UV_INDEX_STRATEGY=unsafe-best-match _PYTHON_HOST_PLATFORM=$_PYTHON_HOST_PLATFORM MACOSX_DEPLOYMENT_TARGET=$MACOSX_DEPLOYMENT_TARGET ARCHFLAGS=$ARCHFLAGS $uv build --python=$pythonVersion --wheel --out-dir=$out_temp_wheels_dir $project_root
5850
pattern="$out_temp_wheels_dir/*.whl"
5951
files=( $pattern )
6052
undelocate_wheel="${files[0]}"
6153

6254
echo ""
6355
echo "================================================================================"
6456
echo "${undelocate_wheel} is linked to the following:"
65-
$uv tool run --python=$pythonVersion --index-strategy=unsafe-first-match --constraint $REQUIREMENTS_FILE --from=delocate delocate-listdeps --depending "${undelocate_wheel}"
57+
$uv run --only-group=package --isolated --python=$pythonVersion delocate-listdeps --depending "${undelocate_wheel}"
6658
echo ""
6759
echo "================================================================================"
68-
$uv tool run --python=$pythonVersion --index-strategy=unsafe-first-match --constraint $REQUIREMENTS_FILE --from=delocate delocate-wheel -w $output_path --require-archs $REQUIRED_ARCH --verbose "$undelocate_wheel"
60+
$uv run --only-group=package --isolated --python=$pythonVersion delocate-wheel -w $output_path --require-archs $REQUIRED_ARCH --verbose "$undelocate_wheel"
6961
}
7062

7163
print_usage(){
72-
echo "Usage: $0 project_root python_version [--help]"
64+
echo "Usage: $0 python_version [--help]"
7365
}
7466

7567
show_help() {
7668
print_usage
7769
echo
7870
echo "Arguments:"
79-
echo " project_root The root directory of the project."
8071
echo " python_version The version of Python to generate a wheel for."
8172
echo
8273
echo "Options:"
@@ -90,18 +81,6 @@ install_temporary_uv(){
9081
$venvPath/bin/pip install --disable-pip-version-check uv
9182
}
9283

93-
check_args(){
94-
if [[ -f "$project_root" ]]; then
95-
echo "error: project_root should point to a directory not a file"
96-
print_usage
97-
exit
98-
fi
99-
if [[ ! -f "$project_root/pyproject.toml" ]]; then
100-
echo "error: $project_root contains no pyproject.toml"
101-
exit
102-
fi
103-
}
104-
10584
# Check if the help flag is provided
10685
for arg in "$@"; do
10786
if [[ "$arg" == "--help" || "$arg" == "-h" ]]; then
@@ -111,25 +90,21 @@ for arg in "$@"; do
11190
done
11291

11392
# Check if the project_root argument is provided
114-
if [ -z "$2" ]; then
93+
if [ -z "$1" ]; then
11594
echo "Error: Missing required arguments."
11695
print_usage
11796
exit 1
11897
fi
11998

12099
# Assign the project_root argument to a variable
121-
project_root=$1
122-
python_version=$2
100+
python_version=$1
123101

124102
# venv_path value is set to default
125103
venv_path=$DEFAULT_PYTHON_VENV
126104

127105
# base_python_path value is set to default
128106
base_python_path=$DEFAULT_BASE_PYTHON
129107

130-
# validate arguments
131-
check_args
132-
133108
if [[ ! -f "$INSTALLED_UV" ]]; then
134109
tmpdir=$(mktemp -d)
135110
install_temporary_uv $tmpdir
@@ -138,4 +113,4 @@ else
138113
uv=$INSTALLED_UV
139114
fi
140115

141-
generate_wheel_with_uv $uv $project_root $python_version
116+
generate_wheel_with_uv $uv $PROJECT_ROOT $python_version

scripts/build_windows.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ function Build-Wheel {
8181
$DockerImageName
8282
"-c",
8383
${createShallowCopy};`
84-
"uv build --build-constraints=${containerSourcePath}\requirements-dev.txt --python=${PythonVersion} --wheel --out-dir=${containerDistPath} --config-setting=conan_cache=C:/Users/ContainerAdministrator/.conan2"
84+
"uv build --python=${PythonVersion} --wheel --out-dir=${containerDistPath} --config-setting=conan_cache=C:/Users/ContainerAdministrator/.conan2"
8585
)
8686

8787
$local:dockerBuildProcess = Start-Process -FilePath $DockerExec -WorkingDirectory $(Get-Item $PSScriptRoot).Parent.FullName -ArgumentList $dockerArgsList -NoNewWindow -PassThru -Wait

0 commit comments

Comments
 (0)